Liquidity Sweeps + Stop Depth [Rider Algo]

RiderAlgo · study · 448 行 · 点赞 42 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RiderAlgo
 
//@version=6
indicator("Liquidity Sweeps + Stop Depth [Rider Algo]", shorttitle="Liquidity Sweeps + Stop Depth [Rider Algo]", overlay=true, max_lines_count=200, max_labels_count=500)
 
// Developed by Rider Algo
//
// How often does this market break a level just to take the stops, and how far does it go?
// 1. Pools: two or more swing highs (or lows) at about the same price. Stop orders often rest just beyond them.
// 2. Every break of a pool is sorted, on closed candles only:
//    - Real break: the candle closes beyond the level.
//    - Sweep: the candle wicks beyond and closes back inside. Then N candles decide:
//      TRAP   = price never closes beyond the tip of the wick (it went for the stops and came back);
//      FAILED = price closes beyond the wick (the break was real after all).
// 3. Stop depth: how far past the level confirmed traps reached on this chart (9 of 10 of them).
// 4. Table: how many breaks were traps, equal highs and equal lows apart, and how far traps went.
// A statistics tool, not a buy or sell signal. Written from scratch (clean-room): no code from other liquidity or
// SMC scripts.
 
//──────────────────────────────────────────────
// QUICK GUIDE
//──────────────────────────────────────────────
groupGuide = "Quick Guide"
 
quickGuide = input.string("Hover the (i) on the right", "How to use", group=groupGuide, display=display.none, tooltip="1. Dotted lines mark equal highs and equal lows: places where stop orders often rest.\n2. When a candle wicks beyond one of them and closes back inside, a gray dot marks it. Then the indicator waits the candles set in Settings (10 by default):\n   colored triangle = TRAP: price never closed beyond the tip of the wick. It went for the stops and came back.\n   gray cross = FAILED: price closed beyond the wick. The break was real after all.\n3. The thin line beyond each pool shows how far 9 of 10 past traps reached on this chart. A stop right at the level is where traps take it.\n4. The table: how many breaks of equal highs and of equal lows were traps on this asset and timeframe, and how far traps went.\n\nThis is a statistics tool, not a buy or sell signal. A marker is final once its candles pass. Past behavior does not guarantee future behavior.")
 
//──────────────────────────────────────────────
// 1 · LIQUIDITY POOLS
//──────────────────────────────────────────────
groupPool = "1 · Liquidity Pools"
 
pivLen   = input.int(3, "Swing size (candles each side)", minval=2, maxval=20, group=groupPool, tooltip="A swing high is a candle with this many lower highs on each side (a swing low, the same with lows). Bigger = fewer, more important swings. A swing is only known this many candles later.")
eqTol    = input.float(0.25, "Equal = within (ATR)", minval=0.05, step=0.05, group=groupPool, tooltip="Two swings count as 'equal' if their prices are this close. ATR = the average size of one candle on this chart. Bigger = more pools.")
poolLife = input.int(150, "Pool life (candles)", minval=20, group=groupPool, tooltip="The two swings of a pool must be at most this many candles apart, and a pool that is not touched for this long is removed.")
maxPools = input.int(3, "Pools shown per side", minval=1, maxval=5, group=groupPool, tooltip="Only the pools nearest to price are drawn, to keep the chart clean.")
colHigh  = input.color(color.new(#f23645, 0), "Colors: Equal highs", group=groupPool, inline="poolc")
colLow   = input.color(color.new(#089981, 0), "Equal lows", group=groupPool, inline="poolc")
 
//──────────────────────────────────────────────
// 2 · TRAPS
//──────────────────────────────────────────────
groupTrap = "2 · Traps"
 
confBars  = input.int(10, "Candles to confirm a trap", minval=1, maxval=50, group=groupTrap, tooltip="After a sweep, price has this many candles to close beyond the tip of the wick. If it does not, the sweep is a TRAP; if it does, it is FAILED. More candles = stricter, fewer traps.")
showMarks = input.bool(true, "Mark past sweeps", group=groupTrap, tooltip="Gray dot = sweep still being judged. Colored triangle = trap. Gray cross = failed. Confirmed traps also get a line from the pool to the sweep.")
showDepth = input.bool(true, "Show the stop depth line", group=groupTrap, tooltip="A thin line beyond each drawn pool: 9 of 10 confirmed traps on this chart reached less far than this. Needs the number of traps set in 3 · Statistics.")
colFail   = input.color(color.new(#787b86, 0), "Colors: Failed / judging", group=groupTrap)
 
//──────────────────────────────────────────────
// 3 · STATISTICS (TABLE)
//──────────────────────────────────────────────
groupStat = "3 · Statistics"
 
showTable = input.bool(true, "Show table", group=groupStat, tooltip="What each side is doing now, how many of its past breaks were traps, and how far traps went.")
minN      = input.int(8, "Cases needed", minval=1, group=groupStat, tooltip="Below this number of judged breaks the trap count says 'too few'; below this number of traps the depth says 'too few'.")
manyPct   = input.int(30, "MANY traps from (%)", minval=1, maxval=100, group=groupStat, inline="cut")
fewPct    = input.int(15, "FEW traps below (%)", minval=0, maxval=100, group=groupStat, inline="cut", tooltip="Share of judged breaks that were traps. At or above MANY: orange, breaks here often go for the stops and come back. Below FEW: blue, breaks here are usually real. In between: SOME.")
tblPosIn  = input.string("Bottom Right", "Position", options=["Top Left", "Top Right", "Bottom Left", "Bottom Right"], group=groupStat, inline="tbl")
tblSizeIn = input.string("Small", "Size", options=["Tiny", "Small", "Normal"], group=groupStat, inline="tbl")
 
tblSize = tblSizeIn == "Tiny" ? size.tiny : tblSizeIn == "Normal" ? size.normal : size.small
tblPos = switch tblPosIn
    "Top Left"     => position.top_left
    "Top Right"    => position.top_right
    "Bottom Left"  => position.bottom_left
    "Bottom Right" => position.bottom_right
 
MAXPOOLS  = 30
MAXSWINGS = 50
MAXMARKS  = 300
MAXLINES  = 80
MAXDEPTHS = 500
DEPTHQ    = 0.9
 
//──────────────────────────────────────────────
// TYPES AND STATE
//──────────────────────────────────────────────
type Pool
    float level
    int   startBar
    int   lastBar
    int   touches
 
// A sweep waiting for its verdict. dir: 1 = equal highs, -1 = equal lows. ext = tip of the wick.
type Sweep
    int   dir
    int   bar
    float level
    int   poolStart
    float ext
    float atrAt
    label mark
 
var array<Pool>  highPools = array.new<Pool>()
var array<Pool>  lowPools  = array.new<Pool>()
var array<float> swHigh    = array.new<float>()
var array<int>   swHighBar = array.new<int>()
var array<float> swLow     = array.new<float>()
var array<int>   swLowBar  = array.new<int>()
var array<Sweep> pending   = array.new<Sweep>()
var array<label> marks     = array.new<label>()
var array<line>  trapLines = array.new<line>()
 
// Index d: 0 = equal highs, 1 = equal lows
var array<int>   nReal   = array.new<int>(2, 0)
var array<int>   nFail   = array.new<int>(2, 0)
var array<int>   nTrap   = array.new<int>(2, 0)
var array<float> depHigh = array.new<float>()
var array<float> depLow  = array.new<float>()
 
// Called on every candle (never inside a condition)
float atr = ta.atr(14)
float ph  = ta.pivothigh(high, pivLen, pivLen)
float pl  = ta.pivotlow(low, pivLen, pivLen)
 
bool sweptHiNow = false
bool sweptLoNow = false
bool trapHiNow  = false
bool trapLoNow  = false
 
f_px(float v) =>
    str.tostring(v, format.mintick)
 
//──────────────────────────────────────────────
// ENGINE (closed candles only)
//──────────────────────────────────────────────
if barstate.isconfirmed and not na(atr)
    float tol = eqTol * atr
 
    // 1 · Judge the open sweeps, from the candle after the sweep. A close beyond the wick = FAILED; none in
    //     confBars candles = TRAP.
    if pending.size() > 0
        for i = pending.size() - 1 to 0
            Sweep s = pending.get(i)
            if bar_index > s.bar
                bool   hi    = s.dir == 1
                int    d     = hi ? 0 : 1
                bool   broke = hi ? close > s.ext : close < s.ext
                string name  = hi ? "equal highs" : "equal lows"
                float  depth = s.atrAt > 0 ? math.abs(s.ext - s.level) / s.atrAt : na
                if broke
                    nFail.set(d, nFail.get(d) + 1)
                    if not na(s.mark)
                        s.mark.set_style(label.style_xcross)
                        s.mark.set_color(color.new(colFail, 20))
                        s.mark.set_tooltip("FAILED sweep of " + name + " at " + f_px(s.level) + ": the candle closed back " + (hi ? "below" : "above") + ", but " + str.tostring(bar_index - s.bar) + " candles later price closed " + (hi ? "above" : "below") + " the tip of the wick (" + f_px(s.ext) + "). The break was real after all.")
                    pending.remove(i)
                else if bar_index - s.bar >= confBars
                    nTrap.set(d, nTrap.get(d) + 1)
                    if not na(depth)
                        array<float> dep = hi ? depHigh : depLow
                        dep.push(depth)
                        if dep.size() > MAXDEPTHS
                            dep.shift()
                    if hi
                        trapHiNow := true
                    else
                        trapLoNow := true
                    if not na(s.mark)
                        s.mark.set_style(hi ? label.style_triangledown : label.style_triangleup)
                        s.mark.set_color(hi ? colHigh : colLow)
                        s.mark.set_tooltip("TRAP at " + name + " " + f_px(s.level) + ": the wick went " + f_px(math.abs(s.ext - s.level)) + (na(depth) ? "" : " (" + str.tostring(depth, "#.##") + " ATR)") + " " + (hi ? "above" : "below") + " the level, the candle closed back inside, and price did not close beyond the wick in the next " + str.tostring(confBars) + " candles. It went for the stops and came back.")
                    if showMarks
                        trapLines.push(line.new(s.poolStart, s.level, s.bar, s.level, color=color.new(hi ? colHigh : colLow, 40), width=1))
                        while trapLines.size() > MAXLINES
                            line.delete(trapLines.shift())
                    pending.remove(i)
 
    // 2 · Breaks. Close beyond the level = real break. Wick beyond + close back inside = sweep, to be judged.
    if highPools.size() > 0
        for i = highPools.size() - 1 to 0
            Pool p = highPools.get(i)
            if high > p.level
                if close < p.level
                    label m = na
                    if showMarks and not sweptHiNow
                        m := label.new(bar_index, high, "", yloc=yloc.abovebar, style=label.style_circle, color=color.new(colFail, 40), size=size.tiny, tooltip="Sweep of equal highs at " + f_px(p.level) + ": the wick went above and the candle closed back below. Judging: it becomes a TRAP if price does not close above " + f_px(high) + " in the next " + str.tostring(confBars) + " candles.")
                        marks.push(m)
                    pending.push(Sweep.new(1, bar_index, p.level, p.startBar, high, atr, m))
                    sweptHiNow := true
                else
                    nReal.set(0, nReal.get(0) + 1)
                highPools.remove(i)
            else if bar_index - p.lastBar > poolLife
                highPools.remove(i)
 
    if lowPools.size() > 0
        for i = lowPools.size() - 1 to 0
            Pool p = lowPools.get(i)
            if low < p.level
                if close > p.level
                    label m = na
                    if showMarks and not sweptLoNow
                        m := label.new(bar_index, low, "", yloc=yloc.belowbar, style=label.style_circle, color=color.new(colFail, 40), size=size.tiny, tooltip="Sweep of equal lows at " + f_px(p.level) + ": the wick went below and the candle closed back above. Judging: it becomes a TRAP if price does not close below " + f_px(low) + " in the next " + str.tostring(confBars) + " candles.")
                        marks.push(m)
                    pending.push(Sweep.new(-1, bar_index, p.level, p.startBar, low, atr, m))
                    sweptLoNow := true
                else
                    nReal.set(1, nReal.get(1) + 1)
                lowPools.remove(i)
            else if bar_index - p.lastBar > poolLife
                lowPools.remove(i)
 
    while marks.size() > MAXMARKS
        label.delete(marks.shift())
 
    // 3 · Swings already taken by price, or too old, stop being candidates
    if swHigh.size() > 0
        for i = swHigh.size() - 1 to 0
            if high > swHigh.get(i) + tol or bar_index - swHighBar.get(i) > poolLife
                swHigh.remove(i)
                swHighBar.remove(i)
    if swLow.size() > 0
        for i = swLow.size() - 1 to 0
            if low < swLow.get(i) - tol or bar_index - swLowBar.get(i) > poolLife
                swLow.remove(i)
                swLowBar.remove(i)
 
    // 4 · New swing high: joins a pool at the same price, or pairs with an earlier swing to make a new pool
    if not na(ph)
        int  pb     = bar_index - pivLen
        bool merged = false
        for p in highPools
            if not merged and math.abs(p.level - ph) <= tol
                p.level   := math.max(p.level, ph)
                p.lastBar := pb
                p.touches += 1
                merged    := true
        if not merged
            int match = -1
            if swHigh.size() > 0
                for i = swHigh.size() - 1 to 0
                    if match < 0 and math.abs(swHigh.get(i) - ph) <= tol and pb - swHighBar.get(i) >= pivLen
                        match := i
            if match >= 0
                highPools.push(Pool.new(math.max(ph, swHigh.get(match)), swHighBar.get(match), pb, 2))
                swHigh.remove(match)
                swHighBar.remove(match)
                if highPools.size() > MAXPOOLS
                    highPools.shift()
            else
                swHigh.push(ph)
                swHighBar.push(pb)
                if swHigh.size() > MAXSWINGS
                    swHigh.shift()
                    swHighBar.shift()
 
    if not na(pl)
        int  pb     = bar_index - pivLen
        bool merged = false
        for p in lowPools
            if not merged and math.abs(p.level - pl) <= tol
                p.level   := math.min(p.level, pl)
                p.lastBar := pb
                p.touches += 1
                merged    := true
        if not merged
            int match = -1
            if swLow.size() > 0
                for i = swLow.size() - 1 to 0
                    if match < 0 and math.abs(swLow.get(i) - pl) <= tol and pb - swLowBar.get(i) >= pivLen
                        match := i
            if match >= 0
                lowPools.push(Pool.new(math.min(pl, swLow.get(match)), swLowBar.get(match), pb, 2))
                swLow.remove(match)
                swLowBar.remove(match)
                if lowPools.size() > MAXPOOLS
                    lowPools.shift()
            else
                swLow.push(pl)
                swLowBar.push(pb)
                if swLow.size() > MAXSWINGS
                    swLow.shift()
                    swLowBar.shift()
 
//──────────────────────────────────────────────
// ALERTS
//──────────────────────────────────────────────
alertcondition(sweptHiNow, "Equal highs swept", "Liquidity Sweeps + Stop Depth [Rider Algo]: a candle wicked above equal highs and closed back below. Judging whether it is a trap.")
alertcondition(sweptLoNow, "Equal lows swept", "Liquidity Sweeps + Stop Depth [Rider Algo]: a candle wicked below equal lows and closed back above. Judging whether it is a trap.")
alertcondition(trapHiNow, "Trap confirmed at equal highs", "Liquidity Sweeps + Stop Depth [Rider Algo]: a sweep of equal highs held. It went for the stops and came back.")
alertcondition(trapLoNow, "Trap confirmed at equal lows", "Liquidity Sweeps + Stop Depth [Rider Algo]: a sweep of equal lows held. It went for the stops and came back.")
 
//──────────────────────────────────────────────
// DRAWING (last candle only)
//──────────────────────────────────────────────
var array<line>  drawLines  = array.new<line>()
var array<label> drawLabels = array.new<label>()
 
// Value at quantile q of a list (the same rule as the study in Python)
f_quantile(array<float> a, float q) =>
    float v = na
    int n = a.size()
    if n > 0
        array<float> s = a.copy()
        s.sort(order.ascending)
        v := s.get(math.min(n - 1, int(q * n)))
    v
 
// The nearest pools to price on one side, as dotted lines with a short name, and the stop depth line beyond them
f_drawPools(array<Pool> pools, bool isHigh, float q90) =>
    array<float> lv = array.new<float>()
    for p in pools
        lv.push(p.level)
    int shown = 0
    if lv.size() > 0
        array<int> idx  = lv.sort_indices(isHigh ? order.ascending : order.descending)
        color      col  = isHigh ? colHigh : colLow
        string     name = isHigh ? "Equal highs" : "Equal lows"
        string     past = isHigh ? "above" : "below"
        for k = 0 to math.min(maxPools, idx.size()) - 1
            Pool p = pools.get(idx.get(k))
            int x2 = bar_index + 2
            drawLines.push(line.new(p.startBar, p.level, x2, p.level, color=color.new(col, 20), style=line.style_dotted, width=2))
            string tip = name + " at " + f_px(p.level) + ": " + str.tostring(p.touches) + " swing " + (isHigh ? "highs" : "lows") + " at about the same price (within " + str.tostring(eqTol) + " ATR). Stop orders often rest just " + past + " such levels.\nIf a candle wicks " + past + " it and closes back inside, it is a sweep; if price then does not close beyond that wick in " + str.tostring(confBars) + " candles, it counts as a trap.\nFirst swing " + str.tostring(bar_index - p.startBar) + " candles ago."
            drawLabels.push(label.new(x2, p.level, name + (p.touches > 2 ? " ×" + str.tostring(p.touches) : ""), style=label.style_label_left, color=color.new(color.black, 100), textcolor=col, size=size.small, tooltip=tip))
            if showDepth and not na(q90)
                float y = p.level + (isHigh ? 1 : -1) * q90 * atr
                drawLines.push(line.new(p.startBar, y, x2, y, color=color.new(col, 65), style=line.style_dotted, width=1))
                string dTip = "Stop depth: on this chart, 9 of 10 confirmed traps of " + str.tostring(name) + " wicked less than " + str.tostring(q90, "#.##") + " ATR " + past + " the level. At today's ATR that is " + f_px(q90 * atr) + ", up to " + f_px(y) + ".\nA stop right at the level is where traps take it. Beyond this line, 9 of 10 past traps would have missed it. A real break goes through any stop."
                drawLabels.push(label.new(x2, y, "9 of 10 traps", style=label.style_label_left, color=color.new(color.black, 100), textcolor=color.new(col, 40), size=size.tiny, tooltip=dTip))
            shown += 1
    shown
 
//──────────────────────────────────────────────
// TABLE
//──────────────────────────────────────────────
// Written for someone who does not trade: one row per side, what it is doing now, how many breaks were traps and
// how far traps went; numbers and rules live in the tooltips. Monospace cells padded with non-breaking spaces, no
// merged cells.
NBSP = " "
 
f_colW(int col) =>
    col == 0 ? 28 : col == 1 ? 22 : 21
 
f_pad(string txt, int w) =>
    string t = str.length(txt) > w ? str.substring(txt, 0, w) : txt
    int extra = w - str.length(t)
    extra > 0 ? t + str.repeat(NBSP, extra) : t
 
var table tbl = table.new(tblPos, 3, 4, border_width=1, border_color=color.new(color.gray, 70))
 
f_put(int col, int row, string txt, color bg, color tc, string tip) =>
    tbl.cell(col, row, f_pad(txt, f_colW(col)), text_color=tc, bgcolor=bg, text_halign=text.align_left, text_size=tblSize, text_font_family=font.family_monospace, tooltip=tip)
 
// What each side is doing now: [text, tooltip, background, text color]
f_status(int d) =>
    bool        hi    = d == 0
    array<Pool> pools = hi ? highPools : lowPools
    string      side  = hi ? "Highs " : "Lows  "
    string      where = hi ? "above" : "below"
    int         k     = pools.size()
    int         age   = -1
    for s in pending
        if (s.dir == 1) == hi
            age := bar_index - s.bar
    string txt = side + "◌ " + str.tostring(k) + (k == 1 ? " pool " : " pools ") + where
    string tip = "Watching " + str.tostring(k) + " equal " + (hi ? "highs" : "lows") + " " + where + " the price."
    color  bg  = color.new(color.black, 30)
    color  tc  = color.white
    if k == 0
        txt := side + "○ No pools " + where
        tip := "No equal " + (hi ? "highs" : "lows") + " " + where + " the price right now."
        tc  := color.gray
    if age >= 0
        txt := side + "● Swept · " + str.tostring(age) + " of " + str.tostring(confBars)
        tip := "Equal " + (hi ? "highs" : "lows") + " were swept " + str.tostring(age) + " candles ago and the candle closed back " + (hi ? "below" : "above") + ". If price does not close " + where + " the tip of that wick within " + str.tostring(confBars) + " candles, it counts as a trap."
        bg  := color.new(hi ? colHigh : colLow, 45)
    [txt, tip, bg, tc]
 
// "3 of 12 ● MANY": traps among the judged breaks of one side
f_traps(int d) =>
    int   traps  = nTrap.get(d)
    int   judged = nReal.get(d) + nFail.get(d) + traps
    float rate   = judged > 0 ? 100.0 * traps / judged : 0.0
    string tag = switch
        judged < minN   => "· too few"
        rate >= manyPct => "● MANY"
        rate >= fewPct  => "● SOME"
        => "● FEW"
    color bg = switch
        judged < minN   => color.new(color.gray, 30)
        rate >= manyPct => color.new(color.orange, 30)
        rate >= fewPct  => color.new(#5d606b, 30)
        => color.new(#2962ff, 30)
    string txt = judged == 0 ? "No breaks yet" : str.tostring(traps) + " of " + str.tostring(judged) + " " + tag
    [txt, judged == 0 ? color.new(color.black, 30) : bg]
 
f_trapsTip(int d) =>
    bool   hi     = d == 0
    string name   = hi ? "equal highs" : "equal lows"
    string past   = hi ? "above" : "below"
    string back   = hi ? "below" : "above"
    int    traps  = nTrap.get(d)
    int    judged = nReal.get(d) + nFail.get(d) + traps
    string head   = "Breaks of " + name + " judged on this chart: " + str.tostring(judged) + (judged > 0 ? " (" + str.tostring(math.round(100.0 * traps / judged)) + "% traps)" : "") + "."
    head + "\n● Traps: " + str.tostring(traps) + ". Wicked " + past + ", closed back " + back + ", and did not close beyond the wick in " + str.tostring(confBars) + " candles.\n✕ Failed: " + str.tostring(nFail.get(d)) + ". Closed back " + back + ", then closed beyond the wick within " + str.tostring(confBars) + " candles.\nReal breaks: " + str.tostring(nReal.get(d)) + ". Closed " + past + " the level.\nMANY from " + str.tostring(manyPct) + "%, FEW below " + str.tostring(fewPct) + "%" + (judged < minN ? ". A count needs " + str.tostring(minN) + "+ breaks." : ".")
 
// "9 of 10 within 1.24%": how far past the level 9 of 10 traps reached, at today's ATR
f_depth(int d, float q90) =>
    array<float> dep = d == 0 ? depHigh : depLow
    int n = dep.size()
    float pctPx = not na(q90) and close > 0 ? 100.0 * q90 * atr / close : na
    n == 0 ? "No traps yet" : n < minN ? "· too few" : "9 of 10 within " + str.tostring(pctPx, "#.##") + "%"
 
f_depthTip(int d, float q50, float q90) =>
    bool         hi   = d == 0
    array<float> dep  = hi ? depHigh : depLow
    int          n    = dep.size()
    string past = hi ? "above" : "below"
    string head = "Confirmed traps of " + (hi ? "equal highs" : "equal lows") + " on this chart: " + str.tostring(n) + "."
    n < minN ? head + " The depth needs " + str.tostring(minN) + "+ traps." : head + "\nHow far the wick went " + past + " the level: half of them less than " + str.tostring(q50, "#.##") + " ATR, 9 of 10 less than " + str.tostring(q90, "#.##") + " ATR (ATR = the average size of one candle).\nAt today's ATR, 9 of 10 means " + f_px(q90 * atr) + " " + past + " the level.\nA stop right at the level is where traps take it. Beyond this distance, 9 of 10 past traps would have missed it. A real break goes through any stop."
 
if barstate.islast
    for l in drawLines
        line.delete(l)
    drawLines.clear()
    for l in drawLabels
        label.delete(l)
    drawLabels.clear()
 
    float q90Hi = depHigh.size() >= minN ? f_quantile(depHigh, DEPTHQ) : na
    float q90Lo = depLow.size() >= minN ? f_quantile(depLow, DEPTHQ) : na
    f_drawPools(highPools, true, q90Hi)
    f_drawPools(lowPools, false, q90Lo)
 
    if showTable
        color  hdr   = color.new(color.gray, 40)
        color  rowBg = color.new(color.black, 30)
        color  wht   = color.white
        string rule  = "A trap: a candle wicks beyond equal highs (or lows), closes back inside, and price does not close beyond the tip of that wick in the next " + str.tostring(confBars) + " candles. It went for the stops and came back. Judged on the " + str.tostring(bar_index + 1) + " candles of this chart, highs and lows apart. Tune it in Settings > 2 · Traps and 3 · Statistics. A statistics tool, not a buy or sell signal."
        string titleTip = "Liquidity Sweeps + Stop Depth on " + syminfo.ticker + " " + timeframe.period + ".\nLeft: what each side is doing right now.\nMiddle: how many past breaks were traps.\nRight: how far traps went past the level."
        f_put(0, 0, "Liquidity Sweeps · " + syminfo.ticker + " " + timeframe.period, hdr, wht, titleTip)
        f_put(1, 0, "Breaks that were traps", hdr, wht, rule)
        f_put(2, 0, "How far traps went", hdr, wht, "Stop depth: how far past the level 9 of 10 confirmed traps reached, as a share of today's price. Hover each row for the detail.")
        for d = 0 to 1
            float q90 = d == 0 ? q90Hi : q90Lo
            array<float> dep = d == 0 ? depHigh : depLow
            float q50 = dep.size() >= minN ? f_quantile(dep, 0.5) : na
            [sTxt, sTip, sBg, sTc] = f_status(d)
            f_put(0, d + 1, sTxt, sBg, sTc, sTip)
            [tTxt, tBg] = f_traps(d)
            f_put(1, d + 1, tTxt, tBg, wht, f_trapsTip(d))
            f_put(2, d + 1, f_depth(d, q90), rowBg, wht, f_depthTip(d, q50, q90))
        f_put(0, 3, "ⓘ Trap = swept and held", rowBg, color.gray, rule)
        f_put(1, 3, "for " + str.tostring(confBars) + " candles", rowBg, color.gray, rule)
        f_put(2, 3, "Not a buy/sell signal", rowBg, color.gray, rule)

← 返回列表