STA FVG Locator

lenorenagel · study · 507 行 · 点赞 29 · TradingView 原页

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

Pine Script

//@version=6
// Indicator: STA FVG Locator
// Derived from "TR FVG & Swing High Low Finder" by traderriazofficial (original copyright (c)).
//
// FIXES vs original (see review notes):
//   1. Untested-swing arrays are now PRUNED (tested swings are removed, not flagged)
//      + hard-capped  -> kills the O(n^2) per-bar scan that caused the timeout on 1m/3m.
//   2. All drawing/deleting now happens ONLY on the last bar (barstate.islast).
//   3. FVG box top/bottom were swapped (top held the LOWER price). Now correct.
//   4. Loop guards moved OUTSIDE the loops (for i = 0 to size-1 counts DOWN when size = 0).
//   5. Dead comparison to "Next Liquidity Target" removed.
//   6. Stale `var` nearest-swing state removed.
//   7. max_boxes/lines/labels raised so higher input limits don't silently drop drawings.
//   8. 5-SMA direction filter DROPPED - both liquidity sides are reported instead.
//   9. Gap fill tracking added; panel reports landmarks only (see DEFINITION KEY).
//  10. Swing High / Swing Low labels REMOVED - the chart marks only the gap, its
//      origin swing, and the next liquidity. Locating, not recommending.
 
// ============================ DEFINITION KEY =================================
// This indicator REPORTS structural landmarks. It does not name trades, place
// stops, or grade setups. Every term below is an observation about price.
//
//   FVG (fair value gap)  Three-bar imbalance. Bullish: high[2] < low.
//                         Bearish: low[2] > high.
//   UNFILLED              Price has not traded through the gap's far edge.
//                         A wick INTO the gap is a partial fill; still unfilled.
//   MIDLINE               The middle of the gap, snapped to the instrument's tick
//                         grid. A gap's true centre can fall on a half tick; the
//                         snapped value is what the panel shows, what the line is
//                         drawn at, and what DISTANCE and SWING : LIQUIDITY are
//                         computed from. A reference level, not an entry instruction.
//   DISTANCE              Current price minus the midline. Signed: positive means
//                         price is above the midline, negative means below.
//   SWING / ORIGIN SWING  The swing that preceded the displacement which created
//                         the gap. Bullish gap -> the swing LOW before the move up.
//                         Bearish gap -> the swing HIGH before the move down.
//                         Captured when the gap forms; it never moves afterward.
//                         Panel row: "Swing". Chart label: "Gap Swing".
//   UNTESTED (swing)      Price has not yet traded through that swing level. Tracked
//                         internally; only the nearest one is drawn (Next Liquidity).
//   NEXT LIQUIDITY        Nearest untested swing level price has not yet reached, on
//                         the side this gap's own type implies - below for a bearish
//                         gap, above for a bullish one. The gap chooses, not a
//                         directional call. Same level in the panel and on the chart.
//                         The opposite side is tracked internally but NOT drawn.
//   SWING : LIQUIDITY     Ratio of two measured distances, both from the midline:
//                         midline-to-origin-swing vs midline-to-liquidity on the
//                         side the gap's own type implies. It is arithmetic on two
//                         landmarks - NOT a risk:reward claim. What counts as risk
//                         is the trader's decision, not the indicator's.
// =============================================================================
 
indicator("STA FVG Locator", shorttitle="STA FVG Locator", overlay=true,
     max_boxes_count=500, max_lines_count=500, max_labels_count=500,
     max_bars_back=5000)
 
// --- Inputs ---
bullishFvgLimit = input.int(1, "Number of Bullish FVGs to Show", minval=1, maxval=20)
bearishFvgLimit = input.int(1, "Number of Bearish FVGs to Show", minval=1, maxval=20)
gapMode         = input.string("Unfilled only", "Gaps shown",
     options=["Unfilled only", "All recent"],
     tooltip="Unfilled = price has not traded through the far edge. Wicks into the gap do NOT fill it, so the gap stays on the board while price works into it.")
showUnfilledOnly = gapMode == "Unfilled only"
 
// --- Visuals (palette) ---
// Every color on the chart is one of these seven at some transparency.
// Nothing is hard-coded - swap any swatch here without touching the code below.
visGroup = "Visuals"
deepOcean    = input.color(#18454E, "Deep Ocean - bullish FVG, Next Liquidity, panel", group=visGroup)
earlySunrise = input.color(#F3492B, "Early Sunrise - bearish FVG border", group=visGroup)
conchShell   = input.color(#F1A3A4, "Conch Shell - bearish FVG shading", group=visGroup)
morningHaze  = input.color(#E08D2D, "Morning Haze - FVG midline (limit/entry)", group=visGroup)
eveningLight = input.color(#E56F33, "Evening Light - Gap Swing line", group=visGroup)
paper        = input.color(#F6EDE7, "Paper - label text and light label fills", group=visGroup)
 
fvgFillTransp   = input.int(88, "FVG fill transparency",   minval=0, maxval=100, group=visGroup)
fvgBorderTransp = input.int(35, "FVG border transparency", minval=0, maxval=100, group=visGroup)
inactiveFade    = input.int(30, "Inactive gap fade (added transparency)", minval=0, maxval=90, group=visGroup,
     tooltip="Gaps other than the one the dashboard describes are drawn this much fainter.")
laneGap         = input.int(10, "Label lane spacing (bars)", minval=0, maxval=60, group=visGroup,
     tooltip="How far right of the last bar the Gap Swing and Next Liquidity labels sit.")
 
sizeOf(opt) =>
    switch opt
        "Tiny"   => size.tiny
        "Small"  => size.small
        "Normal" => size.normal
        "Large"  => size.large
        =>          size.huge
 
fvgLabelSizeOpt   = input.string("Large", "FVG label text size", group=visGroup,
     options=["Tiny", "Small", "Normal", "Large", "Huge"])
swingLabelSizeOpt = input.string("Small", "Level label text size", group=visGroup,
     options=["Tiny", "Small", "Normal", "Large", "Huge"],
     tooltip="Controls the Gap Swing and Next Liquidity labels.")
 
fvgLabelSize   = sizeOf(fvgLabelSizeOpt)
swingLabelSize = sizeOf(swingLabelSizeOpt)
 
// Role assignments - change these lines to re-map a swatch to a different element.
bullishColor    = deepOcean
bullishFill     = deepOcean
bearishColor    = earlySunrise
bearishFill     = conchShell
 
extendGroup   = "FVG Box Extend Options"
extendOption  = input.string("Default", "Extend Option", options=["None", "Limited", "Default"], group=extendGroup)
extendCandles = input.int(8, "Extend Candles (Only Applies if Limited Selected)", minval=1, maxval=100, step=1, group=extendGroup)
 
dashGroup   = "Dashboard"
showDash    = input.bool(true, "Show dashboard", group=dashGroup)
dashPosOpt  = input.string("Top right", "Position", group=dashGroup,
     options=["Top right", "Top left", "Bottom right", "Bottom left", "Middle right"])
dashSizeOpt = input.string("Normal", "Dashboard text size", group=dashGroup,
     options=["Tiny", "Small", "Normal", "Large", "Huge"])
 
perfGroup    = "Performance"
untestedCap  = input.int(300, "Max untested swings tracked per side", minval=20, maxval=2000, group=perfGroup,
     tooltip="Hard cap so the nearest-liquidity scan can never grow unbounded on low timeframes.")
 
// --- Data arrays ---
var array<float>  bullishFvgTop      = array.new_float(0)
var array<float>  bullishFvgBottom   = array.new_float(0)
var array<int>    bullishFvgStartBar = array.new_int(0)
var array<float>  bullishFvgOrigin   = array.new_float(0)
var array<int>    bullishFvgOriginBar = array.new_int(0)
 
var array<float>  bearishFvgTop      = array.new_float(0)
var array<float>  bearishFvgBottom   = array.new_float(0)
var array<int>    bearishFvgStartBar = array.new_int(0)
var array<float>  bearishFvgOrigin   = array.new_float(0)
var array<int>    bearishFvgOriginBar = array.new_int(0)
 
// UNTESTED swings only - tested ones are removed outright, so these stay small.
var array<float>  openSwingHighs    = array.new_float(0)
var array<int>    openSwingHighBars = array.new_int(0)
var array<float>  openSwingLows     = array.new_float(0)
var array<int>    openSwingLowBars  = array.new_int(0)
 
// --- Drawing-object handles ---
var array<box>   bullishFvgBoxes  = array.new_box(0)
var array<label> bullishFvgLabels = array.new_label(0)
var array<line>  bullishFvgLines  = array.new_line(0)
 
var array<box>   bearishFvgBoxes  = array.new_box(0)
var array<label> bearishFvgLabels = array.new_label(0)
var array<line>  bearishFvgLines  = array.new_line(0)
 
var array<line>  originLines  = array.new_line(0)
var array<label> originLabels = array.new_label(0)
 
var array<line>  nearestSwingLines  = array.new_line(0)
var array<label> nearestSwingLabels = array.new_label(0)
 
// --- Most recent swing, kept so a new gap can capture its origin ---
var float lastSwingHigh    = na
var int   lastSwingHighBar = na
var float lastSwingLow     = na
var int   lastSwingLowBar  = na
 
// --- Detection ---
bullishFVG = high[2] < low
bearishFVG = low[2] > high
 
swingHigh = high[1] > high[2] and high[1] > high
swingLow  = low[1]  < low[2]  and low[1]  < low
 
// --- Store FVGs (top = higher price, bottom = lower price) ---
if bullishFVG
    array.push(bullishFvgTop,      low)
    array.push(bullishFvgBottom,   high[2])
    array.push(bullishFvgStartBar, bar_index[2])
    array.push(bullishFvgOrigin,    lastSwingLow)     // swing low before the move up
    array.push(bullishFvgOriginBar, lastSwingLowBar)
 
if bearishFVG
    array.push(bearishFvgTop,      low[2])
    array.push(bearishFvgBottom,   high)
    array.push(bearishFvgStartBar, bar_index[2])
    array.push(bearishFvgOrigin,    lastSwingHigh)    // swing high before the move down
    array.push(bearishFvgOriginBar, lastSwingHighBar)
 
// --- Store swings ---
if swingHigh
    array.push(openSwingHighs,    high[1])
    array.push(openSwingHighBars, bar_index[1])
    lastSwingHigh    := high[1]
    lastSwingHighBar := bar_index[1]
 
if swingLow
    array.push(openSwingLows,    low[1])
    array.push(openSwingLowBars, bar_index[1])
    lastSwingLow    := low[1]
    lastSwingLowBar := bar_index[1]
 
// --- Retire swings that price has now traded through ---
if array.size(openSwingHighs) > 0
    for i = array.size(openSwingHighs) - 1 to 0
        if high >= array.get(openSwingHighs, i)
            array.remove(openSwingHighs, i)
            array.remove(openSwingHighBars, i)
 
if array.size(openSwingLows) > 0
    for i = array.size(openSwingLows) - 1 to 0
        if low <= array.get(openSwingLows, i)
            array.remove(openSwingLows, i)
            array.remove(openSwingLowBars, i)
 
while array.size(openSwingHighs) > untestedCap
    array.shift(openSwingHighs)
    array.shift(openSwingHighBars)
 
while array.size(openSwingLows) > untestedCap
    array.shift(openSwingLows)
    array.shift(openSwingLowBars)
 
// --- Retire gaps price has now filled ---
// Bullish gap fills when price trades below its bottom; bearish when price trades
// above its top. A wick INTO the gap is a partial fill and leaves it live.
if showUnfilledOnly
    if array.size(bullishFvgBottom) > 0
        for i = array.size(bullishFvgBottom) - 1 to 0
            if low < array.get(bullishFvgBottom, i)
                array.remove(bullishFvgTop, i)
                array.remove(bullishFvgBottom, i)
                array.remove(bullishFvgStartBar, i)
                array.remove(bullishFvgOrigin, i)
                array.remove(bullishFvgOriginBar, i)
 
    if array.size(bearishFvgTop) > 0
        for i = array.size(bearishFvgTop) - 1 to 0
            if high > array.get(bearishFvgTop, i)
                array.remove(bearishFvgTop, i)
                array.remove(bearishFvgBottom, i)
                array.remove(bearishFvgStartBar, i)
                array.remove(bearishFvgOrigin, i)
                array.remove(bearishFvgOriginBar, i)
 
// --- Enforce display limits ---
while array.size(bullishFvgTop) > bullishFvgLimit
    array.shift(bullishFvgTop)
    array.shift(bullishFvgBottom)
    array.shift(bullishFvgStartBar)
    array.shift(bullishFvgOrigin)
    array.shift(bullishFvgOriginBar)
 
while array.size(bearishFvgTop) > bearishFvgLimit
    array.shift(bearishFvgTop)
    array.shift(bearishFvgBottom)
    array.shift(bearishFvgStartBar)
    array.shift(bearishFvgOrigin)
    array.shift(bearishFvgOriginBar)
 
// --- Helpers ---
// A drawing anchored with xloc.bar_index cannot reach further back than the
// historical buffer. Untested swings and unfilled gaps can be very old, so clamp
// the left edge. The price level stays exact; only the line's start is pulled in.
BAR_FLOOR = 4500
safeBar(b) => math.max(b, bar_index - BAR_FLOOR)
 
formatTimeframe(tf, isBullish) =>
    suffix = isBullish ? "Bullish FVG" : "Bearish FVG"
    switch tf
        "1"   => "1m "      + suffix
        "3"   => "3m "      + suffix
        "5"   => "5m "      + suffix
        "15"  => "15m "     + suffix
        "30"  => "30m "     + suffix
        "60"  => "1h "      + suffix
        "240" => "4h "      + suffix
        "1D"  => "Daily "   + suffix
        "1W"  => "Weekly "  + suffix
        "1M"  => "Monthly " + suffix
        =>       tf + " "   + suffix
 
drawBox(startBar, endBar, topPrice, bottomPrice, fillColor, borderColor, textColor, isBullish,
     isActive, boxArray, labelArray, lineArray) =>
    // Snapped to the tick grid so the line, the panel and the arithmetic all agree,
    // and so Mid is a price an order can actually rest at.
    mid = math.round_to_mintick((topPrice + bottomPrice) / 2)
    array.push(boxArray, box.new(left=safeBar(startBar), top=topPrice, right=endBar, bottom=bottomPrice,
         bgcolor=fillColor, border_color=borderColor, border_width=isActive ? 2 : 1))
    array.push(labelArray, label.new(x=endBar, y=mid,
         text=formatTimeframe(timeframe.period, isBullish), color=color.new(color.gray, 100),
         textcolor=textColor, style=label.style_label_right,
         size=fvgLabelSize, textalign=text.align_right))
    // The midline IS the dashboard's Entry price - make the active one unmistakable.
    array.push(lineArray, line.new(x1=safeBar(startBar), y1=mid, x2=endBar, y2=mid,
         color=color.new(morningHaze, isActive ? 0 : math.min(100, 15 + inactiveFade)),
         width=isActive ? 2 : 1,
         style=isActive ? line.style_solid : line.style_dashed))
 
// --- Next Liquidity badge + dashboard plumbing ---
drawLiq(price, startBar, endBar, txt, isAbove, lineArray, labelArray) =>
    array.push(lineArray, line.new(x1=safeBar(startBar), y1=price, x2=endBar, y2=price,
         color=color.new(deepOcean, 20), width=1, style=line.style_solid))
    array.push(labelArray, label.new(x=endBar, y=price, text=txt,
         color=color.new(deepOcean, 5), textcolor=paper,
         style=isAbove ? label.style_label_down : label.style_label_up,
         size=swingLabelSize))
 
var table dash = table.new(position.top_right, 2, 10, border_width=1)
 
dashPosition = switch dashPosOpt
    "Top right"    => position.top_right
    "Top left"     => position.top_left
    "Bottom right" => position.bottom_right
    "Bottom left"  => position.bottom_left
    =>                position.middle_right
 
fmtPrice(x) => na(x) ? "--" : str.tostring(x, format.mintick)
fmtPts(x)   => na(x) ? "--" : str.tostring(x, "#.##")
fmtSigned(x) => na(x) ? "--" : (x >= 0 ? "+" : "") + str.tostring(x, "#.##")
 
// --- Draw once, on the last bar only ---
if barstate.islast
 
    if array.size(bullishFvgBoxes) > 0
        for i = 0 to array.size(bullishFvgBoxes) - 1
            box.delete(array.get(bullishFvgBoxes, i))
            label.delete(array.get(bullishFvgLabels, i))
            line.delete(array.get(bullishFvgLines, i))
        array.clear(bullishFvgBoxes)
        array.clear(bullishFvgLabels)
        array.clear(bullishFvgLines)
 
    if array.size(bearishFvgBoxes) > 0
        for i = 0 to array.size(bearishFvgBoxes) - 1
            box.delete(array.get(bearishFvgBoxes, i))
            label.delete(array.get(bearishFvgLabels, i))
            line.delete(array.get(bearishFvgLines, i))
        array.clear(bearishFvgBoxes)
        array.clear(bearishFvgLabels)
        array.clear(bearishFvgLines)
 
    if array.size(originLines) > 0
        for i = 0 to array.size(originLines) - 1
            line.delete(array.get(originLines, i))
            label.delete(array.get(originLabels, i))
        array.clear(originLines)
        array.clear(originLabels)
 
    if array.size(nearestSwingLines) > 0
        for i = 0 to array.size(nearestSwingLines) - 1
            line.delete(array.get(nearestSwingLines, i))
            label.delete(array.get(nearestSwingLabels, i))
        array.clear(nearestSwingLines)
        array.clear(nearestSwingLabels)
 
    // ---- Which gap is the dashboard describing? Nearest midline to price. ----
    activeLane = bar_index + 5 + laneGap
 
    float actBullMid = na
    int   actBullIdx = na
    if array.size(bullishFvgTop) > 0
        for i = 0 to array.size(bullishFvgTop) - 1
            m = (array.get(bullishFvgTop, i) + array.get(bullishFvgBottom, i)) / 2
            if na(actBullMid) or math.abs(close - m) < math.abs(close - actBullMid)
                actBullMid := m
                actBullIdx := i
 
    float actBearMid = na
    int   actBearIdx = na
    if array.size(bearishFvgTop) > 0
        for i = 0 to array.size(bearishFvgTop) - 1
            m = (array.get(bearishFvgTop, i) + array.get(bearishFvgBottom, i)) / 2
            if na(actBearMid) or math.abs(close - m) < math.abs(close - actBearMid)
                actBearMid := m
                actBearIdx := i
 
    bool useBull      = na(actBearMid) or (not na(actBullMid) and math.abs(close - actBullMid) <= math.abs(close - actBearMid))
    bool activeIsBull = useBull and not na(actBullMid)
    bool activeIsBear = not useBull and not na(actBearMid)
 
    if array.size(bullishFvgTop) > 0
        for i = 0 to array.size(bullishFvgTop) - 1
            bTop   = array.get(bullishFvgTop, i)
            bBot   = array.get(bullishFvgBottom, i)
            bStart = array.get(bullishFvgStartBar, i)
            bEnd   = extendOption == "Default" ? bar_index + 3 : extendOption == "Limited" ? bStart + extendCandles : bStart + 2
            act    = activeIsBull and i == actBullIdx
            fade   = act ? 0 : inactiveFade
            drawBox(bStart, bEnd, bTop, bBot, color.new(bullishFill, math.min(100, fvgFillTransp + fade)),
                 color.new(bullishColor, math.min(100, fvgBorderTransp + fade)), bullishColor, true, act,
                 bullishFvgBoxes, bullishFvgLabels, bullishFvgLines)
 
    if array.size(bearishFvgTop) > 0
        for i = 0 to array.size(bearishFvgTop) - 1
            bTop   = array.get(bearishFvgTop, i)
            bBot   = array.get(bearishFvgBottom, i)
            bStart = array.get(bearishFvgStartBar, i)
            bEnd   = extendOption == "Default" ? bar_index + 3 : extendOption == "Limited" ? bStart + extendCandles : bStart + 2
            act    = activeIsBear and i == actBearIdx
            fade   = act ? 0 : inactiveFade
            drawBox(bStart, bEnd, bTop, bBot, color.new(bearishFill, math.min(100, fvgFillTransp + fade)),
                 color.new(bearishColor, math.min(100, fvgBorderTransp + fade)), bearishColor, false, act,
                 bearishFvgBoxes, bearishFvgLabels, bearishFvgLines)
 
    // Nearest untested liquidity on BOTH sides. The indicator does not pick a
    // direction - it reports what is above and what is below.
    float liqUp    = na
    int   liqUpBar = na
    if array.size(openSwingHighs) > 0
        for i = 0 to array.size(openSwingHighs) - 1
            p = array.get(openSwingHighs, i)
            if p > close and (na(liqUp) or p < liqUp)
                liqUp    := p
                liqUpBar := array.get(openSwingHighBars, i)
 
    float liqDn    = na
    int   liqDnBar = na
    if array.size(openSwingLows) > 0
        for i = 0 to array.size(openSwingLows) - 1
            p = array.get(openSwingLows, i)
            if p < close and (na(liqDn) or p > liqDn)
                liqDn    := p
                liqDnBar := array.get(openSwingLowBars, i)
 
    if showDash
        table.set_position(dash, dashPosition)
        dSize = sizeOf(dashSizeOpt)
 
        float gTop = na
        float gBot = na
        if activeIsBull
            gTop := array.get(bullishFvgTop, actBullIdx)
            gBot := array.get(bullishFvgBottom, actBullIdx)
        else if activeIsBear
            gTop := array.get(bearishFvgTop, actBearIdx)
            gBot := array.get(bearishFvgBottom, actBearIdx)
 
        float gOrigin = na
        if activeIsBull
            gOrigin := array.get(bullishFvgOrigin, actBullIdx)
        else if activeIsBear
            gOrigin := array.get(bearishFvgOrigin, actBearIdx)
 
        float midline = na(gTop) ? na : math.round_to_mintick((gTop + gBot) / 2)
        // Target side follows the gap's own type - structural, not a bias call.
        float liqSide = activeIsBull ? liqUp : activeIsBear ? liqDn : na
 
        // Two measured distances from the midline. Naming them is the trader's job.
        float dSwing = na(midline) or na(gOrigin) ? na : math.abs(midline - gOrigin)
        float dLiq   = na(midline) or na(liqSide) ? na : math.abs(liqSide - midline)
        bool  liqAhead = na(liqSide) or na(midline) ? false : (activeIsBull ? liqSide > midline : liqSide < midline)
        string ratioTxt = na(dSwing) or na(dLiq) or dSwing <= 0 or not liqAhead ? "--" : "1 : " + str.tostring(dLiq / dSwing, "#.##")
 
        table.cell(dash, 0, 0, "STA FVG LOCATOR", text_color=morningHaze, bgcolor=deepOcean, text_size=dSize)
        table.cell(dash, 1, 0, "",                text_color=morningHaze, bgcolor=deepOcean, text_size=dSize)
 
        // label, value, tooltip
        rows = array.from(
             "Gap", na(gTop) ? "--" : (activeIsBull ? "Bullish" : "Bearish"),
             "The nearest unfilled gap to price, by midline distance. This is the gap the rest of the panel describes, and the one drawn with a solid midline on the chart.",
 
             "Size", na(gTop) ? "--" : fmtPts(gTop - gBot) + " pt",
             "Height of the gap, top edge to bottom edge. In ticks: " + (na(gTop) ? "--" : str.tostring(math.round((gTop - gBot) / syminfo.mintick))),
 
             "Mid", fmtPrice(midline),
             "MIDLINE - the middle of the gap, snapped to the tick grid so it is a price an order can rest at. Distance and the ratio are computed from this same snapped value. A reference level; the indicator is not calling it an entry.",
 
             "Distance", na(midline) ? "--" : fmtSigned(close - midline) + " pt",
             "DISTANCE - how far current price sits from the midline, and on which side. Positive = price is ABOVE the midline; negative = price is BELOW it. The only row that moves tick to tick; everything else is a fixed level.",
 
             "Swing", fmtPrice(gOrigin),
             "ORIGIN SWING, drawn on the chart as Gap Swing. The swing that preceded the displacement which created this gap. Bullish gap = the swing low before the move up; bearish gap = the swing high before the move down. Captured when the gap formed and fixed since. Distance from the midline: " + (na(dSwing) ? "--" : fmtPts(dSwing) + " pt"),
 
             "Next Liq", fmtPrice(liqSide),
             "NEXT LIQUIDITY - the nearest untested liquidity on the side this gap's own type implies - below for a bearish gap, above for a bullish one. Structural, not a directional call. Distance from price: " + (na(liqSide) ? "--" : fmtPts(math.abs(liqSide - close)) + " pt") + ".  Drawn on the chart as Next Liquidity. Note the OPPOSITE side is not shown - that is the level a sweep can run, so check it yourself when placing a stop.",
 
             "Swing : Liq", ratioTxt,
             "Ratio of two measured distances, both from the midline: midline-to-origin-swing against midline-to-liquidity on the side this gap's type implies. Arithmetic on two landmarks, NOT a risk:reward claim - what counts as risk is your decision. Shows -- when the liquidity on that side sits behind the midline.")
 
        for r = 0 to 6
            table.cell(dash, 0, r + 1, array.get(rows, r * 3),
                 text_color=paper, bgcolor=deepOcean, text_size=dSize,
                 text_halign=text.align_left, tooltip=array.get(rows, r * 3 + 2))
            table.cell(dash, 1, r + 1, array.get(rows, r * 3 + 1),
                 text_color=r == 6 ? morningHaze : paper, bgcolor=deepOcean, text_size=dSize,
                 text_halign=text.align_right, tooltip=array.get(rows, r * 3 + 2))
    else
        table.clear(dash, 0, 0, 1, 9)
 
    // ---- Gap Swing: the active gap's origin, drawn from where it happened ----
    float oPrice = na
    int   oBar   = na
    if activeIsBull
        oPrice := array.get(bullishFvgOrigin, actBullIdx)
        oBar   := array.get(bullishFvgOriginBar, actBullIdx)
    else if activeIsBear
        oPrice := array.get(bearishFvgOrigin, actBearIdx)
        oBar   := array.get(bearishFvgOriginBar, actBearIdx)
 
    if not na(oPrice) and not na(oBar)
        array.push(originLines, line.new(x1=safeBar(oBar), y1=oPrice, x2=activeLane, y2=oPrice,
             color=color.new(eveningLight, 15), width=1, style=line.style_dashed))
        array.push(originLabels, label.new(x=activeLane, y=oPrice, text="Gap Swing",
             color=color.new(paper, 15), textcolor=eveningLight,
             style=activeIsBull ? label.style_label_up : label.style_label_down,
             size=swingLabelSize))
 
    // ---- Next Liquidity: one line, on the side this gap's own type implies ----
    float nlPrice = activeIsBull ? liqUp    : activeIsBear ? liqDn    : na
    int   nlBar   = activeIsBull ? liqUpBar : activeIsBear ? liqDnBar : na
 
    if not na(nlPrice) and not na(nlBar)
        drawLiq(nlPrice, nlBar, activeLane, "Next Liquidity", activeIsBull, nearestSwingLines, nearestSwingLabels)

← 返回列表