Liquidity Hunter [JOAT]

officialjackofalltrades · study · 968 行 · 点赞 280 · TradingView 原页

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

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © officialjackofalltrades
//@version=6
indicator("Liquidity Hunter [JOAT]", shorttitle = "LH [JOAT]", overlay = true, max_lines_count = 400, max_labels_count = 400, max_boxes_count = 100)
 
// ─── Inputs ───────────────────────────────────────────────────────────────
const string G_GEN  = "General"
const string G_LIQ  = "Liquidity levels"
const string G_SWP  = "Sweeps & structure"
const string G_IDM  = "Inducement"
const string G_VOID = "Liquidity voids"
const string G_HTF  = "HTF liquidity"
const string G_DASH = "Dashboard"
const string G_COL  = "Custom theme colours"
 
dispMode  = input.string("Live", "Display mode", options = ["Live", "All History"], group = G_GEN, tooltip = "Live keeps only the newest structure tags, sweeps and inducements on the chart (see Recent events kept). All History keeps up to 100 structure breaks, 60 sweeps and 30 inducements.", display = display.none)
theme     = input.string("Ice Magenta", "Theme", options = ["Ice Magenta", "Mystic", "Emerald Ruby", "Royal Gold", "Aqua Ember", "Ocean Amber", "Sakura Teal", "Aurora", "Mono", "Custom"], group = G_GEN, tooltip = "Colour pair for the bull side (sell-side liquidity, bullish structure) and the bear side (buy-side liquidity, bearish structure), plus the dashboard colours. Mono is a clean grey preset that turns dark on a light chart. Custom uses the colours in the last group.", display = display.none)
paintBars = input.bool(true, "Paint candles by bias", group = G_GEN, tooltip = "Candles take the bull colour after a bullish BOS / CHoCH and the bear colour after a bearish one.", display = display.none)
keepLive  = input.int(6, "Recent events kept (Live)", minval = 1, maxval = 20, group = G_GEN, tooltip = "In Live mode, how many structure breaks and sweeps stay on the chart (the newest ones). Older ones are removed so history does not litter the chart.", display = display.none)
 
swingAtr  = input.float(1.5, "Swing size (ATR)", minval = 0.5, maxval = 6.0, step = 0.1, group = G_LIQ, tooltip = "A swing high is confirmed once price falls this many ATR below it, a swing low once price rises this many ATR above it. These major swings are the liquidity levels and the BOS / CHoCH references. Larger = fewer, more major levels.", display = display.none)
atrLen    = input.int(14, "ATR length", minval = 1, maxval = 200, group = G_LIQ, tooltip = "ATR used for every distance, tolerance and size on the chart.", display = display.none)
lvlMax    = input.int(4, "Levels per side", minval = 0, maxval = 8, group = G_LIQ, tooltip = "Single (unpooled) levels drawn on each side: the nearest ones to the close within Draw within (ATR). Every live level is still tracked and counted on the dashboard.", display = display.none)
poolMax   = input.int(2, "Pools per side", minval = 0, maxval = 4, group = G_LIQ, tooltip = "Pools (equal highs or lows) drawn on each side, nearest first, within Draw within (ATR).", display = display.none)
eqTol     = input.float(0.20, "Equal highs / lows tolerance (ATR)", minval = 0.0, maxval = 1.0, step = 0.01, group = G_LIQ, tooltip = "A new swing within this many ATR of a live level on the same side joins it as a pool instead of starting a new level. The pool keeps the extreme price and counts its swings.", display = display.none)
poolMinor = input.bool(true, "Minor swings join pools", group = G_LIQ, tooltip = "Also let minor swings (see Minor swing length) join a live level's pool when they form within the tolerance. Minor swings never start a level of their own.", display = display.none)
minorLen  = input.int(4, "Minor swing length", minval = 2, maxval = 20, group = G_LIQ, tooltip = "Bars on each side that confirm a minor swing. Minor swings feed pools, the inducement (IDM) and the internal structure.", display = display.none)
drawAtr   = input.float(8.0, "Draw within (ATR)", minval = 1.0, maxval = 50.0, step = 0.5, group = G_LIQ, tooltip = "Only levels, pools, HTF levels and voids within this many ATR of the close are drawn, so a far object cannot squash the candles. The dashboard still reads every live level.", display = display.none)
extBars   = input.int(8, "Extend right (bars)", minval = 2, maxval = 60, group = G_LIQ, tooltip = "How far right of the last bar levels, pools and voids end. Their tags sit 2 bars further right.", display = display.none)
glowOn    = input.bool(true, "Soft glow under levels", group = G_LIQ, tooltip = "A wide faint line under each single level.", display = display.none)
 
showSweep = input.bool(true, "Show sweeps", group = G_SWP, tooltip = "A wick through a live level that closes back inside: a filled X on the wick, the level turns dim and dotted, and 'swept 3.4' gives the wick depth past the level in points.", display = display.none)
minDepth  = input.float(0.05, "Min sweep depth (ATR)", minval = 0.0, maxval = 2.0, step = 0.01, group = G_SWP, tooltip = "A wick must pass the level by at least this many ATR to count as a sweep. A smaller poke that closes back inside leaves the level live (and a swing there can join its pool).", display = display.none)
showMajor = input.bool(true, "Major BOS / CHoCH", group = G_SWP, tooltip = "A close through the last major swing high or low. BOS continues the bias, CHoCH flips it.", display = display.none)
showMinor = input.bool(false, "Internal BOS / CHoCH", group = G_SWP, tooltip = "The same for minor swings, drawn dashed with smaller tags (iBOS / iCHoCH). Off by default to keep the chart clean.", display = display.none)
 
showIdm   = input.bool(true, "Show inducement (IDM)", group = G_IDM, tooltip = "After a BOS / CHoCH, the first minor swing that forms in the pullback is tagged IDM with a dashed line until price takes it; then 'IDM ✓' marks the bar that took it.", display = display.none)
 
showVoid  = input.bool(true, "Show liquidity voids", group = G_VOID, tooltip = "A run of same-direction candles with large bodies and little wick overlap leaves a void: price moved through that range one way with little two-way trade.", display = display.none)
voidBody  = input.float(1.0, "Min body (ATR)", minval = 0.3, maxval = 4.0, step = 0.1, group = G_VOID, tooltip = "Each candle of the run needs a body of at least this many ATR (ATR of the bar before it).", display = display.none)
voidRun   = input.int(2, "Min candles in a run", minval = 2, maxval = 6, group = G_VOID, tooltip = "Consecutive candles needed to leave a void.", display = display.none)
voidOv    = input.float(0.40, "Max wick overlap (× body)", minval = 0.0, maxval = 1.0, step = 0.05, group = G_VOID, tooltip = "How far a candle's range may dip back into the previous candle's range, as a share of its body. Lower = only the cleanest runs.", display = display.none)
voidMax   = input.int(3, "Open voids kept", minval = 1, maxval = 6, group = G_VOID, tooltip = "Open voids tracked and drawn; the oldest is dropped when a new one forms.", display = display.none)
 
showPD    = input.bool(true, "Previous day high / low", group = G_HTF, tooltip = "PDH / PDL from the previous closed day (on charts below 1D). A level the current day has already traded through turns dotted and loses its tag.", display = display.none)
showPW    = input.bool(true, "Previous week high / low", group = G_HTF, tooltip = "PWH / PWL from the previous closed week (on charts below 1W).", display = display.none)
 
showDash  = input.bool(true, "Show dashboard", group = G_DASH, display = display.none)
dashPos   = input.string("Top Right", "Position", options = ["Top Right", "Top Center", "Top Left", "Middle Right", "Middle Center", "Middle Left", "Bottom Right", "Bottom Center", "Bottom Left"], group = G_DASH, display = display.none)
dashSize  = input.string("Small", "Text size", options = ["Small", "Normal", "Large"], group = G_DASH, display = display.none)
dashTrans = input.int(15, "Background transparency", minval = 0, maxval = 80, group = G_DASH, display = display.none)
 
cBull     = input.color(#00B7FF, "Bull / sell-side", group = G_COL)
cBear     = input.color(#FF2EA6, "Bear / buy-side", group = G_COL)
cBg       = input.color(#1A1035, "Dashboard background", group = G_COL)
cFrame    = input.color(#2A1A50, "Dashboard frame", group = G_COL)
cHi       = input.color(#C77DFF, "Highlight row and HTF levels", group = G_COL)
 
// ─── Constants ────────────────────────────────────────────────────────────
const int   PAST_MAX  = 4990        // furthest back a drawing starts
const int   FWD_MAX   = 490         // furthest ahead anything is drawn
const int   MAX_LIVE  = 60          // live levels tracked per side; the oldest past this is dropped
const int   SWEEP_WIN = 50          // bars over which a sweep's weight in the score fades to 0
const int   LEAD      = 2           // bars between the end of a level and its tag
const color TR        = #00000000
const color C_WHITE   = #FFFFFF
const color C_INK     = #0B0B12
const color C_TXT_M   = #A8B0BD
 
// a drawing anchored far back needs the bar times that far back
max_bars_back(time, 5000)
 
// ─── Colours ──────────────────────────────────────────────────────────────
chan(float v) =>
    u = v / 255.0
    u <= 0.03928 ? u / 12.92 : math.pow((u + 0.055) / 1.055, 2.4)
lumOf(color c) =>
    0.2126 * chan(color.r(c)) + 0.7152 * chan(color.g(c)) + 0.0722 * chan(color.b(c))
 
light = lumOf(chart.bg_color) > 0.40
 
themeCols(string t, bool lt) =>
    color b1 = #00B7FF
    color b2 = #FF2EA6
    color bg = #1A1035
    color fr = #2A1A50
    color hi = #C77DFF
    if t == "Mystic"
        b1 := #00CED1
        b2 := #9400D3
        bg := #191970
        fr := #241A3A
        hi := #B39DDB
    else if t == "Emerald Ruby"
        b1 := #00C896
        b2 := #E0115F
        bg := #0B2A26
        fr := #123D36
        hi := #7FFFD4
    else if t == "Royal Gold"
        b1 := #FFC233
        b2 := #8A5CFF
        bg := #1C1433
        fr := #2C2150
        hi := #FFE08A
    else if t == "Aqua Ember"
        b1 := #00E5C0
        b2 := #FF8C1A
        bg := #0F2230
        fr := #1B3448
        hi := #FFD2A1
    else if t == "Ocean Amber"
        b1 := #00A8E8
        b2 := #FFB000
        bg := #0A1F33
        fr := #15324F
        hi := #7FD8FF
    else if t == "Sakura Teal"
        b1 := #2EC4B6
        b2 := #FF6B9D
        bg := #1B1530
        fr := #2C2248
        hi := #FFC2D6
    else if t == "Aurora"
        b1 := #00F5A0
        b2 := #7B2FF7
        bg := #120D2B
        fr := #221A45
        hi := #B8F5DC
    else if t == "Mono"
        b1 := lt ? #2A2A2A : #E6E6E6
        b2 := #7A7A7A
        bg := #111111
        fr := #2A2A2A
        hi := #BDBDBD
    else if t == "Custom"
        b1 := cBull
        b2 := cBear
        bg := cBg
        fr := cFrame
        hi := cHi
    [b1, b2, bg, fr, hi]
 
[C_BULL, C_BEAR, C_BG, C_FRAME, C_HI] = themeCols(theme, light)
// dashboard text sits on the dashboard's own dark background, so Mono keeps its light grey there
D_BULL = theme == "Mono" ? #E6E6E6 : C_BULL
C_NEU  = color.new(#F0F8FF, 30)
 
shade(color c) =>
    color.rgb(color.r(c) * 0.70, color.g(c) * 0.70, color.b(c) * 0.70)
// text on a filled tag: white, or dark ink when the fill is a light colour
inkOn(color c) =>
    lumOf(c) > 0.55 ? C_INK : C_WHITE
// plain text on the chart: deeper shade on a light chart background
txtCol(color c) =>
    light ? shade(c) : c
// side 1 = buy-side (highs, above price), -1 = sell-side (lows, below price)
sideCol(int side) =>
    side == 1 ? C_BEAR : C_BULL
dashSideCol(int side) =>
    side == 1 ? C_BEAR : D_BULL
 
// ─── Types ────────────────────────────────────────────────────────────────
// one liquidity level: a single major swing, or a pool of equal swings
type Liq
    float      price      // the level: the swing's price, or the pool's extreme
    float      lo         // lowest swing in the pool
    float      hi         // highest swing in the pool
    int        side       // 1 = buy-side (swing high), -1 = sell-side (swing low)
    int        bar        // bar of the earliest swing in the pool
    int        born       // bar the first swing was confirmed on
    int        count      // swings in the pool
    array<int> bars       // bars of every swing in the pool
 
type Piv
    int   bar
    float price
    int   kind
 
// a liquidity void: the body range of a fast one-way run
type VoidZ
    float top
    float bot
    int   dir             // 1 = left by a bullish run, -1 = by a bearish run
    int   bar             // first candle of the run
    float sizeAtr         // height in ATR of the bar before the run
    int   candles
    bool  growing         // the run is still going
    float filled          // deepest share of the void price has traded back into (0..1)
 
// inducement: the first minor swing of the pullback after a break of structure
type Idm
    float price
    int   bar
    int   side            // 1 = a swing high (after a bearish break), -1 = a swing low (after a bullish break)
    line  ln
    label tag
 
// ─── State ────────────────────────────────────────────────────────────────
var array<Liq>   bsl       = array.new<Liq>()
var array<Liq>   ssl       = array.new<Liq>()
var array<VoidZ> voids     = array.new<VoidZ>()
var array<line>  stLines   = array.new<line>()     // structure history
var array<label> stLabels  = array.new<label>()
var array<line>  swLines   = array.new<line>()     // swept levels
var array<label> swLabels  = array.new<label>()
var array<line>  idLines   = array.new<line>()     // inducements
var array<label> idLabels  = array.new<label>()
var array<box>   fadeBoxes = array.new<box>()      // voids traded through
var array<line>  eLines    = array.new<line>()     // right-edge layer, rebuilt on the last bar
var array<label> eLabels   = array.new<label>()
var array<box>   eBoxes    = array.new<box>()
 
isLive   = dispMode == "Live"
keepSt   = isLive ? keepLive : 100
keepSw   = isLive ? keepLive : 60
keepId   = isLive ? 3 : 30
keepFade = isLive ? 2 : 15
 
// ─── Helpers ──────────────────────────────────────────────────────────────
// decimals of the symbol's tick, so prices print like the price scale
decCount(float t) =>
    int   d = 0
    float m = t
    while d < 8 and math.abs(m - math.round(m)) > 1e-6
        m := m * 10
        d += 1
    d
var int DEC = decCount(syminfo.mintick)
 
// number with thousands separators: fixed = always DEC decimals, else up to DEC
fmt(float v, int dec, bool fixed) =>
    string pat = dec > 0 ? "0." + str.repeat(fixed ? "0" : "#", dec) : "0"
    string s   = str.tostring(math.abs(v), pat)
    array<string> parts = str.split(s, ".")
    string ip  = parts.size() > 0 ? parts.get(0) : s
    string fp  = parts.size() > 1 ? parts.get(1) : ""
    int    n   = str.length(ip)
    string g   = ""
    if n > 0
        for i = 0 to n - 1
            g += str.substring(ip, i, i + 1)
            int rem = n - 1 - i
            if rem > 0 and rem % 3 == 0
                g += ","
    (v < 0 ? "-" : "") + g + (str.length(fp) > 0 ? "." + fp : "")
fmtP(float v) =>
    fmt(v, DEC, true)
fmtD(float v) =>
    fmt(v, DEC, false)
 
// every drawing origin goes through this: never more than 4,990 bars back
clampX(int x) =>
    math.max(x, bar_index - PAST_MAX)
 
trimLines(array<line> a, int keep) =>
    while a.size() > keep
        line.delete(a.shift())
    0
trimLabels(array<label> a, int keep) =>
    while a.size() > keep
        label.delete(a.shift())
    0
trimBoxes(array<box> a, int keep) =>
    while a.size() > keep
        box.delete(a.shift())
    0
 
// dashboard row transparency fades a little down the rows
f_grad(color base, int row, int rows, int minT, int maxT) =>
    float t = rows <= 1 ? float(minT) : float(minT) + float(maxT - minT) * (float(row) / float(rows - 1))
    color.new(base, int(t))
 
posOf(string s) =>
    switch s
        "Top Left"      => position.top_left
        "Top Center"    => position.top_center
        "Middle Right"  => position.middle_right
        "Middle Center" => position.middle_center
        "Middle Left"   => position.middle_left
        "Bottom Right"  => position.bottom_right
        "Bottom Center" => position.bottom_center
        "Bottom Left"   => position.bottom_left
        => position.top_right
 
sizeOf(string s) =>
    switch s
        "Normal" => size.normal
        "Large"  => size.large
        => size.small
 
// ─── Core series ──────────────────────────────────────────────────────────
atr  = ta.atr(atrLen)
atrP = nz(atr[1], atr)
mph  = ta.pivothigh(high, minorLen, minorLen)
mpl  = ta.pivotlow(low, minorLen, minorLen)
body = math.abs(close - open)
 
// previous closed day / week high and low: [1] with lookahead_on reads the finished period only
[pdh, pdl] = request.security(syminfo.tickerid, "D", [high[1], low[1]], lookahead = barmerge.lookahead_on)
[pwh, pwl] = request.security(syminfo.tickerid, "W", [high[1], low[1]], lookahead = barmerge.lookahead_on)
tfSec = timeframe.in_seconds()
dOk   = showPD and tfSec < 86400
wOk   = showPW and tfSec < 604800
 
// the current day / week: where its lines start and how far it has traded
var int   dStart = 0
var int   wStart = 0
var float dHi    = na
var float dLo    = na
var float wHi    = na
var float wLo    = na
newDay  = timeframe.change("D")
newWeek = timeframe.change("W")
if newDay or na(dHi)
    dStart := bar_index
    dHi    := high
    dLo    := low
else
    dHi := math.max(dHi, high)
    dLo := math.min(dLo, low)
if newWeek or na(wHi)
    wStart := bar_index
    wHi    := high
    wLo    := low
else
    wHi := math.max(wHi, high)
    wLo := math.min(wLo, low)
 
// the visible bars' price range: the tag gap is a share of the displayed span
var float visHi = na
var float visLo = na
if time >= chart.left_visible_bar_time and time <= chart.right_visible_bar_time
    visHi := na(visHi) ? high : math.max(visHi, high)
    visLo := na(visLo) ? low : math.min(visLo, low)
 
// ─── Structure, sweep, inducement and void state ──────────────────────────
var float  rcHigh     = na
var int    rcHighBar  = na
var float  rcLow      = na
var int    rcLowBar   = na
var int    lastConf   = 0
var int    bias       = 0
var string lastKind   = ""
var int    lastBrkBar = na
var float  pendH      = na
var int    pendHBar   = na
var float  pendL      = na
var int    pendLBar   = na
var int    ibias      = 0
var float  pendHm     = na
var int    pendHmBar  = na
var float  pendLm     = na
var int    pendLmBar  = na
 
var int    lastSwBar   = na
var int    lastSwSide  = 0
var float  lastSwDepth = na
 
var int    idmNeed      = 0
var int    idmFrom      = na
var Idm    idmLive      = na
var int    idmTakenBar  = na
var int    idmTakenSide = 0
 
var int    runDir   = 0
var int    runLen   = 0
var int    runStart = na
var float  runOpen  = na
var float  runAtr   = na
var VoidZ  growV    = na
 
// ─── Detection helpers ────────────────────────────────────────────────────
// a BOS / CHoCH: solid line from the broken swing to the break bar, filled tag at the break
drawStruct(int x1, float y, int x2, string txt, int dir, bool internal) =>
    col = dir == 1 ? C_BULL : C_BEAR
    stLines.push(line.new(clampX(x1), y, x2, y, color = internal ? color.new(col, 30) : col, style = internal ? line.style_dashed : line.style_solid, width = internal ? 1 : 2))
    stLabels.push(label.new(x2, y, txt, style = internal ? label.style_label_right : label.style_label_left, color = color.new(col, internal ? 35 : 15), textcolor = inkOn(col), size = size.small, tooltip = (dir == 1 ? "Bullish " : "Bearish ") + txt + ": close through " + fmtP(y) + "\nSwing formed " + str.tostring(x2 - x1) + " bars before the break"))
    trimLines(stLines, keepSt)
    trimLabels(stLabels, keepSt)
 
// sweeps and closes through the live levels of one side, on a closed bar
sweepSide(array<Liq> lv, int side, float minD) =>
    int   nSw  = 0
    float outP = na
    float dep  = na
    int   cnt  = 0
    if lv.size() > 0
        for i = lv.size() - 1 to 0
            o = lv.get(i)
            bool through = side == 1 ? high > o.price : low < o.price
            if through
                bool  beyond = side == 1 ? close > o.price : close < o.price
                float d      = side == 1 ? high - o.price : o.price - low
                if beyond
                    lv.remove(i)
                else if d >= minD
                    nSw += 1
                    if showSweep
                        swLines.push(line.new(clampX(o.bar), o.price, bar_index, o.price, color = color.new(sideCol(side), 55), style = line.style_dotted, width = 1))
                    // the outermost level swept on this bar names the sweep
                    if na(outP) or (side == 1 ? o.price > outP : o.price < outP)
                        outP := o.price
                        dep  := d
                        cnt  := o.count
                    lv.remove(i)
    [nSw, outP, dep, cnt]
 
// a swing that sits within the bar distance of a swing already in the pool is the same swing
farFrom(Liq o, int pBar) =>
    bool ok = true
    for b in o.bars
        if math.abs(pBar - b) <= minorLen
            ok := false
            break
    ok
 
// a new swing: joins the nearest live level within the tolerance (a pool), or starts a level if it is major
// returns 0 = nothing, 1 = new level, 2 = joined a pool
addPivot(array<Liq> lv, int side, int pBar, float pPrice, float tol, bool isMajor) =>
    int   best  = -1
    float bestD = na
    if lv.size() > 0
        for i = 0 to lv.size() - 1
            o = lv.get(i)
            float d = math.abs(pPrice - o.price)
            if d <= tol and (na(bestD) or d < bestD)
                best  := i
                bestD := d
    int res = 0
    if best >= 0
        o = lv.get(best)
        if farFrom(o, pBar)
            o.count += 1
            o.bars.push(pBar)
            o.lo    := math.min(o.lo, pPrice)
            o.hi    := math.max(o.hi, pPrice)
            o.price := side == 1 ? o.hi : o.lo
            o.bar   := math.min(o.bar, pBar)
            res     := 2
    else if isMajor
        lv.push(Liq.new(pPrice, pPrice, pPrice, side, pBar, bar_index, 1, array.from(pBar)))
        if lv.size() > MAX_LIVE
            lv.shift()
        res := 1
    res
 
makeIdm(int side, int pb, float p) =>
    col = sideCol(side)
    ln  = line.new(clampX(pb), p, bar_index, p, color = color.new(col, 20), style = line.style_dashed, width = 1)
    tg  = label.new(pb, p, "IDM", style = side == 1 ? label.style_label_down : label.style_label_up, color = TR, textcolor = txtCol(col), size = size.small, tooltip = "Inducement: the first " + (side == 1 ? "swing high" : "swing low") + " of the pullback after the " + (side == 1 ? "bearish " : "bullish ") + lastKind + "\n" + fmtP(p))
    idLines.push(ln)
    idLabels.push(tg)
    trimLines(idLines, keepId)
    trimLabels(idLabels, keepId * 2)
    Idm.new(p, pb, side, ln, tg)
 
// ─── Detection, on closed bars only ───────────────────────────────────────
bool evBslSwept  = false
bool evSslSwept  = false
bool evBullBreak = false
bool evBearBreak = false
bool evIdmTaken  = false
bool evPool      = false
 
if barstate.isconfirmed and atr > 0 and bar_index > minorLen + 2
    // 1. sweeps and closes through the live levels
    [nB, oB, dB, cB] = sweepSide(bsl, 1, minDepth * atr)
    [nS, oS, dS, cS] = sweepSide(ssl, -1, minDepth * atr)
    if nB > 0
        evBslSwept  := true
        lastSwBar   := bar_index
        lastSwSide  := 1
        lastSwDepth := dB
        if showSweep
            swLabels.push(label.new(bar_index, high, "X", style = label.style_label_down, color = C_BEAR, textcolor = inkOn(C_BEAR), size = size.small, tooltip = "Buy-side liquidity swept" + (cB > 1 ? " (pool ×" + str.tostring(cB) + ")" : "") + "\nLevel " + fmtP(oB) + " · wick " + fmtD(dB) + " past it\nClosed back below at " + fmtP(close) + (nB > 1 ? "\n" + str.tostring(nB) + " levels swept on this bar" : "")))
            swLabels.push(label.new(bar_index - 2, oB, "swept " + fmtD(dB), style = label.style_label_lower_right, color = TR, textcolor = color.new(txtCol(C_BEAR), 15), size = size.small))
    if nS > 0
        evSslSwept  := true
        lastSwBar   := bar_index
        lastSwSide  := -1
        lastSwDepth := dS
        if showSweep
            swLabels.push(label.new(bar_index, low, "X", style = label.style_label_up, color = C_BULL, textcolor = inkOn(C_BULL), size = size.small, tooltip = "Sell-side liquidity swept" + (cS > 1 ? " (pool ×" + str.tostring(cS) + ")" : "") + "\nLevel " + fmtP(oS) + " · wick " + fmtD(dS) + " past it\nClosed back above at " + fmtP(close) + (nS > 1 ? "\n" + str.tostring(nS) + " levels swept on this bar" : "")))
            swLabels.push(label.new(bar_index - 2, oS, "swept " + fmtD(dS), style = label.style_label_upper_right, color = TR, textcolor = color.new(txtCol(C_BULL), 15), size = size.small))
    trimLines(swLines, keepSw)
    trimLabels(swLabels, keepSw * 2)
 
    // 2. the live inducement: taken by a wick through it, otherwise its line follows the bars
    if not na(idmLive)
        bool tk = idmLive.side == -1 ? low < idmLive.price : high > idmLive.price
        line.set_x2(idmLive.ln, bar_index)
        if tk
            evIdmTaken   := true
            idmTakenBar  := bar_index
            idmTakenSide := idmLive.side
            line.set_color(idmLive.ln, color.new(sideCol(idmLive.side), 60))
            idLabels.push(label.new(bar_index - 2, idmLive.price, "IDM ✓", style = idmLive.side == -1 ? label.style_label_upper_right : label.style_label_lower_right, color = TR, textcolor = color.new(txtCol(sideCol(idmLive.side)), 25), size = size.small, tooltip = "Inducement at " + fmtP(idmLive.price) + " taken " + str.tostring(bar_index - idmLive.bar) + " bars after its swing"))
            trimLabels(idLabels, keepId * 2)
            idmLive := na
 
    // 3. liquidity voids: runs of large same-direction bodies with little wick overlap
    bool bigBull = close > open and body >= voidBody * atrP
    bool bigBear = close < open and body >= voidBody * atrP
    bool cont    = runDir == 1 ? bigBull and math.max(0.0, high[1] - low) <= voidOv * body : runDir == -1 ? bigBear and math.max(0.0, high - low[1]) <= voidOv * body : false
    if cont
        runLen += 1
        if runLen == voidRun
            float vTop = runDir == 1 ? close : runOpen
            float vBot = runDir == 1 ? runOpen : close
            growV := VoidZ.new(vTop, vBot, runDir, runStart, (vTop - vBot) / runAtr, runLen, true, 0.0)
            voids.push(growV)
            if voids.size() > voidMax
                voids.shift()
        else if runLen > voidRun and not na(growV)
            if runDir == 1
                growV.top := close
            else
                growV.bot := close
            growV.sizeAtr := (growV.top - growV.bot) / runAtr
            growV.candles := runLen
    else
        if not na(growV)
            growV.growing := false
            growV := na
        runDir   := bigBull ? 1 : bigBear ? -1 : 0
        runLen   := runDir != 0 ? 1 : 0
        runStart := bar_index
        runOpen  := open
        runAtr   := atrP
    // how far price has traded back into each finished void; through it = faded
    if voids.size() > 0
        for i = voids.size() - 1 to 0
            v = voids.get(i)
            if not v.growing
                float h = v.top - v.bot
                float f = h > 0 ? (v.dir == 1 ? (v.top - low) / h : (high - v.bot) / h) : 1.0
                v.filled := math.max(v.filled, math.min(1.0, math.max(0.0, f)))
                if v.filled >= 1.0
                    if showVoid
                        vc = v.dir == 1 ? C_BULL : C_BEAR
                        fadeBoxes.push(box.new(clampX(v.bar), v.top, bar_index, v.bot, bgcolor = color.new(vc, 93), border_color = color.new(vc, 85), border_width = 1))
                        trimBoxes(fadeBoxes, keepFade)
                    voids.remove(i)
 
    // 4. adaptive ZigZag: a swing is confirmed once price moves swingAtr x ATR away from its extreme
    Piv newMajor = na
    float thr = atr * swingAtr
    if na(rcHigh)
        rcHigh    := high
        rcHighBar := bar_index
        rcLow     := low
        rcLowBar  := bar_index
    if high >= rcHigh
        rcHigh    := high
        rcHighBar := bar_index
    if low <= rcLow
        rcLow    := low
        rcLowBar := bar_index
    if lastConf != 1 and rcHigh - low >= thr
        newMajor  := Piv.new(rcHighBar, rcHigh, 1)
        lastConf  := 1
        rcLow     := low
        rcLowBar  := bar_index
    else if lastConf != -1 and high - rcLow >= thr
        newMajor  := Piv.new(rcLowBar, rcLow, -1)
        lastConf  := -1
        rcHigh    := high
        rcHighBar := bar_index
 
    // 5. major structure: a close through the last major swing
    if not na(newMajor)
        if newMajor.kind == 1
            pendH    := newMajor.price
            pendHBar := newMajor.bar
        else
            pendL    := newMajor.price
            pendLBar := newMajor.bar
    if not na(pendH) and close > pendH
        string k = bias == -1 ? "CHoCH" : "BOS"
        if showMajor
            drawStruct(pendHBar, pendH, bar_index, k, 1, false)
        bias        := 1
        lastKind    := k
        lastBrkBar  := bar_index
        pendH       := na
        evBullBreak := true
        idmNeed     := 1
        idmFrom     := bar_index
    if not na(pendL) and close < pendL
        string k = bias == 1 ? "CHoCH" : "BOS"
        if showMajor
            drawStruct(pendLBar, pendL, bar_index, k, -1, false)
        bias        := -1
        lastKind    := k
        lastBrkBar  := bar_index
        pendL       := na
        evBearBreak := true
        idmNeed     := -1
        idmFrom     := bar_index
 
    // 6. a new major swing is a liquidity level, or joins a pool
    if not na(newMajor)
        int r = addPivot(newMajor.kind == 1 ? bsl : ssl, newMajor.kind, newMajor.bar, newMajor.price, eqTol * atr, true)
        if r == 2
            evPool := true
 
    // 7. minor swings: pools, inducement, internal structure
    if not na(mph)
        int pb = bar_index - minorLen
        if poolMinor
            int r = addPivot(bsl, 1, pb, mph, eqTol * atr, false)
            if r == 2
                evPool := true
        if showIdm and idmNeed == -1 and pb > idmFrom
            if not na(idmLive)
                line.delete(idmLive.ln)
                label.delete(idmLive.tag)
            idmLive := makeIdm(1, pb, mph)
            idmNeed := 0
        pendHm    := mph
        pendHmBar := pb
    if not na(mpl)
        int pb = bar_index - minorLen
        if poolMinor
            int r = addPivot(ssl, -1, pb, mpl, eqTol * atr, false)
            if r == 2
                evPool := true
        if showIdm and idmNeed == 1 and pb > idmFrom
            if not na(idmLive)
                line.delete(idmLive.ln)
                label.delete(idmLive.tag)
            idmLive := makeIdm(-1, pb, mpl)
            idmNeed := 0
        pendLm    := mpl
        pendLmBar := pb
    if showMinor
        if not na(pendHm) and close > pendHm
            drawStruct(pendHmBar, pendHm, bar_index, ibias == -1 ? "iCHoCH" : "iBOS", 1, true)
            ibias  := 1
            pendHm := na
        if not na(pendLm) and close < pendLm
            drawStruct(pendLmBar, pendLm, bar_index, ibias == 1 ? "iCHoCH" : "iBOS", -1, true)
            ibias  := -1
            pendLm := na
 
// ─── Liquidity Score (0-100) ──────────────────────────────────────────────
// per side: w = Σ swings × proximity over live levels within Draw within (ATR); best = the largest pool near price
// proximity = 1 - distance / Draw within, so a level at the close weighs 1 and one at the draw limit weighs 0
scoreSide(array<Liq> lv, float c, float a) =>
    float w    = 0.0
    float best = 0.0
    if a > 0 and lv.size() > 0
        for o in lv
            float d = math.abs(o.price - c) / a
            if d <= drawAtr
                float pr = 1.0 - d / drawAtr
                w    += o.count * pr
                best := math.max(best, math.min(o.count, 4) / 4.0 * pr)
    [w, best]
 
[wBsl, prBsl] = scoreSide(bsl, close, atr)
[wSsl, prSsl] = scoreSide(ssl, close, atr)
// pools (0-40): the best pool by size (×4 or more = full) and closeness
float scPool = 40.0 * math.max(prBsl, prSsl)
// sweep (0-30): full on the sweep bar, fading to 0 over SWEEP_WIN bars
float scSwp  = na(lastSwBar) ? 0.0 : 30.0 * math.max(0.0, 1.0 - float(bar_index - lastSwBar) / SWEEP_WIN)
// concentration (0-30): how one-sided the nearby liquidity is, scaled down while there is little of it
float wSum   = wBsl + wSsl
float scConc = wSum > 0 ? 30.0 * math.abs(wBsl - wSsl) / wSum * math.min(1.0, wSum / 2.0) : 0.0
int   score  = int(math.round(scPool + scSwp + scConc))
 
// ─── Right-edge layer: rebuilt on the last bar ────────────────────────────
// indices of the nearest levels (pools or singles) within the draw distance
pickNearest(array<Liq> lv, bool pools, int maxN, float c, float a) =>
    array<float> ds  = array.new<float>()
    array<int>   ix  = array.new<int>()
    array<int>   res = array.new<int>()
    if lv.size() > 0 and a > 0
        for i = 0 to lv.size() - 1
            o = lv.get(i)
            float d = math.abs(o.price - c) / a
            if (o.count >= 2) == pools and d <= drawAtr
                ds.push(d)
                ix.push(i)
    if maxN > 0 and ds.size() > 0
        srt = ds.sort_indices(order.ascending)
        for k = 0 to math.min(maxN, srt.size()) - 1
            res.push(ix.get(srt.get(k)))
    res
 
renderSide(array<Liq> lv, int side, int xEnd, float c, float a, array<float> tY, array<string> tTx, array<color> tBg, array<color> tFg, array<color> tLn, array<string> tTip, array<float> ext) =>
    col         = sideCol(side)
    string nm   = side == 1 ? "BSL" : "SSL"
    string full = side == 1 ? "Buy-side liquidity" : "Sell-side liquidity"
    string rel  = side == 1 ? "above" : "below"
    array<int> pIdx = pickNearest(lv, true, poolMax, c, a)
    array<int> sIdx = pickNearest(lv, false, lvlMax, c, a)
    for i in pIdx
        o = lv.get(i)
        float d    = math.abs(o.price - c) / a
        float minH = 0.08 * a
        float top  = side == 1 ? o.price : math.max(o.hi, o.price + minH)
        float bot  = side == 1 ? math.min(o.lo, o.price - minH) : o.price
        int   x1   = clampX(o.bar)
        eBoxes.push(box.new(x1, top, xEnd, bot, bgcolor = color.new(col, 80), border_color = color.new(col, 45), border_width = 1))
        eLines.push(line.new(x1, o.price, xEnd, o.price, color = col, width = 2))
        ext.set(0, math.max(ext.get(0), top))
        ext.set(1, math.min(ext.get(1), bot))
        tY.push(o.price)
        tTx.push(nm + " POOL ×" + str.tostring(o.count) + " · " + fmtP(o.price))
        tBg.push(color.new(col, 5))
        tFg.push(inkOn(col))
        tLn.push(color.new(col, 30))
        tTip.push(full + " pool: " + str.tostring(o.count) + " equal " + (side == 1 ? "highs" : "lows") + "\nRange " + fmtP(o.lo) + " to " + fmtP(o.hi) + "\n" + str.tostring(d, "0.0") + " ATR (" + fmtD(math.abs(o.price - c)) + ") " + rel + " the close\nFirst swing " + str.tostring(bar_index - o.bar) + " bars ago")
    for i in sIdx
        o = lv.get(i)
        float d  = math.abs(o.price - c) / a
        int   x1 = clampX(o.bar)
        if glowOn
            eLines.push(line.new(x1, o.price, xEnd, o.price, color = color.new(col, 86), width = 5))
        eLines.push(line.new(x1, o.price, xEnd, o.price, color = color.new(col, 10), width = 1))
        tY.push(o.price)
        tTx.push(nm + " " + fmtP(o.price) + " · " + str.tostring(d, "0.0") + " ATR")
        tBg.push(color.new(col, 20))
        tFg.push(inkOn(col))
        tLn.push(color.new(col, 40))
        tTip.push(full + " (swing " + (side == 1 ? "high" : "low") + ")\n" + fmtP(o.price) + " · " + fmtD(math.abs(o.price - c)) + " " + rel + " the close\nSwing formed " + str.tostring(bar_index - o.bar) + " bars ago")
    0
 
renderHtf(string nm, string full, float lvl, bool taken, int x0, int xEnd, float c, float a, array<float> tY, array<string> tTx, array<color> tBg, array<color> tFg, array<color> tLn, array<string> tTip) =>
    if not na(lvl) and a > 0
        float d = math.abs(lvl - c) / a
        if d <= drawAtr
            eLines.push(line.new(clampX(x0), lvl, xEnd, lvl, color = color.new(C_HI, taken ? 65 : 20), style = taken ? line.style_dotted : line.style_dashed, width = 1))
            if not taken
                tY.push(lvl)
                tTx.push(nm + " " + fmtP(lvl))
                tBg.push(color.new(C_HI, 20))
                tFg.push(inkOn(C_HI))
                tLn.push(color.new(C_HI, 40))
                tTip.push(full + "\n" + fmtP(lvl) + " · " + str.tostring(d, "0.0") + " ATR " + (lvl > c ? "above" : "below") + " the close")
    0
 
renderVoids(int xEnd, float c, float a, array<float> tY, array<string> tTx, array<color> tBg, array<color> tFg, array<color> tLn, array<string> tTip, array<float> ext) =>
    if a > 0
        for v in voids
            float d = c > v.top ? (c - v.top) / a : c < v.bot ? (v.bot - c) / a : 0.0
            if d <= drawAtr
                vc = v.dir == 1 ? C_BULL : C_BEAR
                eBoxes.push(box.new(clampX(v.bar), v.top, xEnd, v.bot, bgcolor = color.new(vc, 87), border_color = color.new(vc, 60), border_width = 1))
                ext.set(0, math.max(ext.get(0), v.top))
                ext.set(1, math.min(ext.get(1), v.bot))
                tY.push((v.top + v.bot) / 2.0)
                tTx.push("VOID " + str.tostring(v.sizeAtr, "0.0") + " ATR" + (v.filled >= 0.05 ? " · " + str.tostring(math.round(v.filled * 100)) + "% filled" : ""))
                tBg.push(color.new(vc, 35))
                tFg.push(inkOn(vc))
                tLn.push(color.new(vc, 50))
                tTip.push("Liquidity void: " + str.tostring(v.candles) + (v.dir == 1 ? " bullish" : " bearish") + " candles, bodies ≥ " + str.tostring(voidBody, "0.0") + " ATR\n" + fmtP(v.bot) + " to " + fmtP(v.top) + "\nTraded back into: " + str.tostring(math.round(v.filled * 100)) + "%" + (v.growing ? " (run still going)" : ""))
    0
 
// least-squares stacking of sorted tag heights with a minimum gap: overlapping tags merge into a cluster centred on
// their own levels, so a tag moves as little as it can
stackTags(array<float> ys, float gap) =>
    int n = ys.size()
    array<int>   cS   = array.new<int>()
    array<int>   cN   = array.new<int>()
    array<float> cSum = array.new<float>()
    array<float> out  = array.new<float>(n, 0.0)
    if n > 0
        for i = 0 to n - 1
            cS.push(i)
            cN.push(1)
            cSum.push(ys.get(i))
            while cS.size() > 1
                int   m  = cS.size()
                int   nA = cN.get(m - 2)
                int   nB = cN.get(m - 1)
                float pA = cSum.get(m - 2) / nA
                float pB = cSum.get(m - 1) / nB
                if pA + nA * gap > pB
                    cSum.set(m - 2, cSum.get(m - 2) + cSum.get(m - 1) - nB * nA * gap)
                    cN.set(m - 2, nA + nB)
                    cS.pop()
                    cN.pop()
                    cSum.pop()
                else
                    break
        for q = 0 to cS.size() - 1
            float p = cSum.get(q) / cN.get(q)
            for k = 0 to cN.get(q) - 1
                out.set(cS.get(q) + k, p + k * gap)
    out
 
if barstate.islast
    for l in eLines
        line.delete(l)
    eLines.clear()
    for l in eLabels
        label.delete(l)
    eLabels.clear()
    for b in eBoxes
        box.delete(b)
    eBoxes.clear()
    if atr > 0
        int xEnd = bar_index + math.min(extBars, FWD_MAX - LEAD - 1)
        int xTag = xEnd + LEAD
        array<float>  tY   = array.new<float>()
        array<string> tTx  = array.new<string>()
        array<color>  tBg  = array.new<color>()
        array<color>  tFg  = array.new<color>()
        array<color>  tLn  = array.new<color>()
        array<string> tTip = array.new<string>()
        array<float>  ext  = array.from(nz(visHi, high), nz(visLo, low))
        renderSide(bsl, 1, xEnd, close, atr, tY, tTx, tBg, tFg, tLn, tTip, ext)
        renderSide(ssl, -1, xEnd, close, atr, tY, tTx, tBg, tFg, tLn, tTip, ext)
        if dOk
            renderHtf("PDH", "Previous day high", pdh, dHi > pdh, dStart, xEnd, close, atr, tY, tTx, tBg, tFg, tLn, tTip)
            renderHtf("PDL", "Previous day low", pdl, dLo < pdl, dStart, xEnd, close, atr, tY, tTx, tBg, tFg, tLn, tTip)
        if wOk
            renderHtf("PWH", "Previous week high", pwh, wHi > pwh, wStart, xEnd, close, atr, tY, tTx, tBg, tFg, tLn, tTip)
            renderHtf("PWL", "Previous week low", pwl, wLo < pwl, wStart, xEnd, close, atr, tY, tTx, tBg, tFg, tLn, tTip)
        if showVoid
            renderVoids(xEnd, close, atr, tY, tTx, tBg, tFg, tLn, tTip, ext)
        int n = tY.size()
        if n > 0
            for y in tY
                ext.set(0, math.max(ext.get(0), y))
                ext.set(1, math.min(ext.get(1), y))
            float span = math.max(ext.get(0) - ext.get(1), 10 * syminfo.mintick)
            float gap  = 0.045 * span
            array<int>   srt = tY.sort_indices(order.ascending)
            array<float> ys  = array.new<float>()
            for k in srt
                ys.push(tY.get(k))
            array<float> placed = stackTags(ys, gap)
            for k = 0 to n - 1
                int   j  = srt.get(k)
                float y0 = tY.get(j)
                float y1 = placed.get(k)
                // a short leader from the level to its tag, so a moved tag still points at its own level
                eLines.push(line.new(xEnd, y0, xTag, y1, color = tLn.get(j), width = 1))
                eLabels.push(label.new(xTag, y1, tTx.get(j), style = label.style_label_left, color = tBg.get(j), textcolor = tFg.get(j), size = size.small, tooltip = tTip.get(j)))
 
// ─── Dashboard ────────────────────────────────────────────────────────────
nearestIdx(array<Liq> lv, float c) =>
    int   idx  = -1
    float best = na
    if lv.size() > 0
        for i = 0 to lv.size() - 1
            float d = math.abs(lv.get(i).price - c)
            if na(best) or d < best
                best := d
                idx  := i
    idx
 
// largest pool on a side: [swings, distance in price], nearest wins a tie
bigPool(array<Liq> lv, float c) =>
    int   cnt = 1
    float dst = na
    for o in lv
        float d = math.abs(o.price - c)
        if o.count >= 2 and (o.count > cnt or (o.count == cnt and d < dst))
            cnt := o.count
            dst := d
    [cnt, dst]
 
sideText(array<Liq> lv, float c, float a) =>
    int i = nearestIdx(lv, c)
    i < 0 ? "None" : str.tostring(lv.size()) + " · " + fmtP(lv.get(i).price) + " · " + str.tostring(math.abs(lv.get(i).price - c) / a, "0.0") + " ATR"
 
htfNear(string nm, float lvl, bool ok, bool taken, float c, float a) =>
    ok and not taken and not na(lvl) and a > 0 and math.abs(lvl - c) / a <= 1.0 ? nm + " " + str.tostring(math.abs(lvl - c) / a, "0.0") : ""
 
var table dash = showDash ? table.new(posOf(dashPos), 2, 10, bgcolor = color.new(C_BG, 100), frame_color = color.new(C_FRAME, 60), frame_width = 1, border_color = color.new(C_FRAME, 65), border_width = 1) : na
 
rowSet(table t, int r, int rows, string k, string v, color vc, string tip) =>
    table.cell(t, 0, r, k, text_color = color.new(C_TXT_M, 10), bgcolor = f_grad(C_BG, r, rows, dashTrans, dashTrans + 25), text_size = sizeOf(dashSize))
    table.cell(t, 1, r, v, text_color = vc, bgcolor = f_grad(C_BG, r, rows, dashTrans, dashTrans + 25), text_halign = text.align_right, text_size = sizeOf(dashSize), tooltip = tip)
    0
 
if barstate.islast and showDash and not na(dash) and atr > 0
    int rows = 10
    hdrBg = f_grad(C_BG, 0, rows, dashTrans, dashTrans + 5)
    table.cell(dash, 0, 0, "LIQUIDITY CONFLUENCE", text_color = C_WHITE, bgcolor = hdrBg, text_font_family = font.family_monospace, text_size = sizeOf(dashSize), tooltip = "Swing size " + str.tostring(swingAtr, "0.0") + " ATR · pool tolerance " + str.tostring(eqTol, "0.00") + " ATR · draw within " + str.tostring(drawAtr, "0.0") + " ATR\nEvery value is read on closed bars.")
    table.cell(dash, 1, 0, "STATE", text_color = C_WHITE, bgcolor = hdrBg, text_halign = text.align_right, text_font_family = font.family_monospace, text_size = sizeOf(dashSize))
 
    // bias
    string bTxt = bias == 1 ? "Bull · " + lastKind : bias == -1 ? "Bear · " + lastKind : "Neutral"
    color  bCol = bias == 1 ? color.new(D_BULL, 50) : bias == -1 ? color.new(C_BEAR, 50) : color.new(color.gray, 70)
    rowSet(dash, 1, rows, "Bias", bTxt, bCol, na(lastBrkBar) ? "No major break yet" : "Last major break " + str.tostring(bar_index - lastBrkBar) + " bars ago")
 
    // buy-side / sell-side
    rowSet(dash, 2, rows, "BSL above", sideText(bsl, close, atr), bsl.size() > 0 ? C_BEAR : C_NEU, "Live buy-side levels · nearest price · its distance from the close")
    rowSet(dash, 3, rows, "SSL below", sideText(ssl, close, atr), ssl.size() > 0 ? D_BULL : C_NEU, "Live sell-side levels · nearest price · its distance from the close")
 
    // largest pool
    [pcB, pdB] = bigPool(bsl, close)
    [pcS, pdS] = bigPool(ssl, close)
    string poolTxt = "None"
    color  poolCol = C_NEU
    if pcB >= 2 or pcS >= 2
        bool bslBig = pcB > pcS or (pcB == pcS and pdB <= pdS)
        poolTxt := (bslBig ? "BSL" : "SSL") + " · ×" + str.tostring(bslBig ? pcB : pcS)
        poolCol := bslBig ? C_BEAR : D_BULL
    rowSet(dash, 4, rows, "Largest pool", poolTxt, poolCol, "The live pool with the most equal swings, any distance")
 
    // last sweep
    string swTxt = na(lastSwBar) ? "None" : (lastSwSide == 1 ? "BSL" : "SSL") + " · " + str.tostring(bar_index - lastSwBar) + " bars · " + fmtD(lastSwDepth)
    rowSet(dash, 5, rows, "Last sweep", swTxt, na(lastSwBar) ? C_NEU : dashSideCol(lastSwSide), "Side swept · bars ago · wick depth past the level in points")
 
    // inducement
    string iTxt = "None"
    color  iCol = C_NEU
    if not showIdm
        iTxt := "Off"
    else if not na(idmLive)
        iTxt := "Pending · " + fmtP(idmLive.price)
        iCol := dashSideCol(idmLive.side)
    else if idmNeed != 0
        iTxt := "Forming"
    else if not na(idmTakenBar)
        iTxt := "Taken · " + str.tostring(bar_index - idmTakenBar) + " bars"
        iCol := color.new(dashSideCol(idmTakenSide), 40)
    rowSet(dash, 6, rows, "IDM", iTxt, iCol, "Pending: the pullback swing after the last break is still untaken. Forming: a break printed and its pullback swing has not formed yet.")
 
    // voids
    string vTxt = "Off"
    color  vCol = C_NEU
    if showVoid
        float vBest = na
        int   vSide = 0
        for v in voids
            float d = close > v.top ? (close - v.top) / atr : close < v.bot ? (v.bot - close) / atr : 0.0
            if na(vBest) or d < vBest
                vBest := d
                vSide := v.dir
        vTxt := voids.size() == 0 ? "0" : str.tostring(voids.size()) + " · nearest " + str.tostring(vBest, "0.0") + " ATR"
        vCol := voids.size() == 0 ? C_NEU : vSide == 1 ? D_BULL : C_BEAR
    rowSet(dash, 7, rows, "Voids open", vTxt, vCol, "Voids price has not traded back through yet · distance of the nearest edge")
 
    // HTF levels within 1 ATR
    string hTxt = "Off"
    if dOk or wOk
        array<string> hs = array.new<string>()
        for s in array.from(htfNear("PDH", pdh, dOk, dHi > pdh, close, atr), htfNear("PDL", pdl, dOk, dLo < pdl, close, atr), htfNear("PWH", pwh, wOk, wHi > pwh, close, atr), htfNear("PWL", pwl, wOk, wLo < pwl, close, atr))
            if str.length(s) > 0
                hs.push(s)
        hTxt := hs.size() == 0 ? "None" : hs.join(" · ") + " ATR"
    rowSet(dash, 8, rows, "HTF levels near", hTxt, hTxt == "None" or hTxt == "Off" ? C_NEU : C_HI, "Untaken previous day / week highs and lows within 1 ATR of the close")
 
    // liquidity score: the highlighted last row
    color scInk = inkOn(C_HI)
    table.cell(dash, 0, 9, "Liquidity Score", text_color = scInk, bgcolor = color.new(C_HI, 60), text_font_family = font.family_monospace, text_size = sizeOf(dashSize))
    table.cell(dash, 1, 9, str.tostring(score) + " / 100", text_color = scInk, bgcolor = color.new(C_HI, 30), text_halign = text.align_right, text_font_family = font.family_monospace, text_size = sizeOf(dashSize), tooltip = "Pools " + str.tostring(math.round(scPool)) + " / 40 · Sweep " + str.tostring(math.round(scSwp)) + " / 30 · Concentration " + str.tostring(math.round(scConc)) + " / 30\nPools: the largest nearby pool by size and closeness. Sweep: fades over " + str.tostring(SWEEP_WIN) + " bars. Concentration: how one-sided the nearby liquidity is.")
 
// ─── Plots (4 of 64) and alerts (6) ───────────────────────────────────────
barcolor(paintBars and bias != 0 ? (bias == 1 ? C_BULL : C_BEAR) : na, title = "Bias candles", editable = false)
plot(close, "Price scale anchor", color = TR, display = display.pane, editable = false)
plot(score, "Liquidity Score", color = C_HI, display = display.data_window, editable = false)
plot(bias, "Structure bias", color = C_HI, display = display.data_window, editable = false)
 
alertcondition(evBslSwept, "BSL swept", "Liquidity Hunter: buy-side liquidity swept on {{ticker}} ({{interval}})")
alertcondition(evSslSwept, "SSL swept", "Liquidity Hunter: sell-side liquidity swept on {{ticker}} ({{interval}})")
alertcondition(evBullBreak, "Bullish BOS / CHoCH", "Liquidity Hunter: bullish break of structure on {{ticker}} ({{interval}})")
alertcondition(evBearBreak, "Bearish BOS / CHoCH", "Liquidity Hunter: bearish break of structure on {{ticker}} ({{interval}})")
alertcondition(evIdmTaken, "Inducement taken", "Liquidity Hunter: inducement taken on {{ticker}} ({{interval}})")
alertcondition(evPool, "Liquidity pool grew", "Liquidity Hunter: a swing joined a liquidity pool on {{ticker}} ({{interval}})")

← 返回列表