Wyckoff Accumulation & Distribution, Spring, UTAD, SOS [LunqFX]

LunqFX · study · 616 行 · 点赞 894 · TradingView 原页

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

Pine Script

//@version=6
// ============================================================================
//  Wyckoff Accumulation & Distribution, Spring, UTAD, SOS [LunqFX]
// ----------------------------------------------------------------------------
//  Builds the Wyckoff schematic on the chart event by event: the climax that
//  stops the trend (SC / BC), the automatic rally or reaction that sets the
//  trading range (AR), the secondary test (ST), the spring or upthrust that
//  tests the range (Spring / UTAD), the sign of strength or weakness that
//  leaves it (SOS / SOW) and the last point of support or supply (LPS / LPSY).
//  Phases A–E are marked on the range, the path is drawn through the events,
//  the range height is projected as two targets, and every finished range on
//  this symbol goes into a track record.
//
//  NON-REPAINTING: every event is decided on a closed bar. Swings are
//  confirmed pivots. No request.security, no lookahead.
// ============================================================================
indicator("Wyckoff Accumulation & Distribution, Spring, UTAD, SOS [LunqFX]", "Wyckoff [LunqFX]",
     overlay = true, max_lines_count = 300, max_labels_count = 400, max_boxes_count = 60, max_polylines_count = 60)
 
// ─────────────────────────────────────────────────────────────────────────
//  INPUTS
// ─────────────────────────────────────────────────────────────────────────
gM = "Schematic"
side     = input.string("Both", "Schematics", options = ["Both", "Accumulation", "Distribution"], group = gM)
trendLen = input.int(50, "Climax lookback (bars)", minval = 10, maxval = 300, group = gM,
     tooltip = "A selling climax must print the lowest low of this many bars, a buying climax the highest high.")
climRng  = input.float(1.2, "Climax bar range (× ATR)", minval = 0.5, maxval = 5.0, step = 0.1, group = gM)
climVol  = input.float(1.5, "Climax volume (× 20-bar average)", minval = 1.0, maxval = 6.0, step = 0.1, group = gM,
     tooltip = "Ignored on symbols that publish no volume.")
pivLen   = input.int(3, "Swing strength", minval = 2, maxval = 10, group = gM, tooltip = "Bars on each side that confirm a swing high or low.")
arMin    = input.float(2.0, "Min. automatic rally / reaction (× ATR)", minval = 0.5, maxval = 10.0, step = 0.1, group = gM)
maxH     = input.float(10.0, "Max. range height (× ATR)", minval = 3.0, maxval = 30.0, step = 0.5, group = gM)
minRange = input.int(15, "Min. range length (bars)", minval = 5, maxval = 200, group = gM,
     tooltip = "If price leaves the range sooner than this, it was a V-turn, not a Wyckoff range, and the model is dropped.")
stTol    = input.float(0.35, "Secondary test zone (part of range)", minval = 0.1, maxval = 0.6, step = 0.05, group = gM)
sprBars  = input.int(3, "Spring / UTAD max. bars outside", minval = 1, maxval = 10, group = gM,
     tooltip = "A spring (or UTAD) is a break of the climax side that closes back inside the range within this many bars.")
failDep  = input.float(0.30, "Break depth (part of range)", minval = 0.1, maxval = 1.0, step = 0.05, group = gM,
     tooltip = "A close this far beyond the climax side breaks the range, and the schematic fails.")
maxRng   = input.int(300, "Range expiry (bars)", minval = 50, maxval = 2000, group = gM)
maxLeg   = input.int(300, "Markup / markdown expiry (bars)", minval = 50, maxval = 2000, group = gM)
 
gD = "Drawing"
showPath = input.bool(true, "Draw the schematic path", group = gD)
showPh   = input.bool(true, "Phase letters A–E", group = gD)
showTgt  = input.bool(true, "Targets and invalidation", group = gD)
keepN    = input.int(3, "Ranges drawn", minval = 1, maxval = 20, group = gD, tooltip = "Finished ranges older than this are removed from the chart. The track record keeps all of them.")
lblSize  = input.string("Normal", "Label size", options = ["Small", "Normal", "Large"], group = gD)
 
gP = "Panel"
showTbl  = input.bool(true, "Show panel", group = gP)
tblPos   = input.string("Top Right", "Position", options = ["Top Right", "Bottom Right", "Top Left", "Bottom Left"], group = gP)
tblSize  = input.string("Normal", "Text size", options = ["Small", "Normal", "Large"], group = gP)
 
gA = "Alerts"
alRange  = input.bool(true, "Alert: climax and trading range", group = gA)
alTest   = input.bool(true, "Alert: spring / UTAD", group = gA)
alSos    = input.bool(true, "Alert: SOS / SOW and LPS / LPSY", group = gA)
alTgt    = input.bool(true, "Alert: target hit / complete / failed", group = gA)
 
candOn_  = input.bool(true, "Neon candles", group = "Visuals")
candGlw  = input.bool(true, "Glow candles", group = "Visuals", tooltip = "Each body is drawn in four bands that brighten towards the close, so the candle reads in the direction it moved. Off = flat translucent bodies.")
 
// ─────────────────────────────────────────────────────────────────────────
//  THEME
// ─────────────────────────────────────────────────────────────────────────
bgLum   = 0.2126 * color.r(chart.bg_color) + 0.7152 * color.g(chart.bg_color) + 0.0722 * color.b(chart.bg_color)
isLight = bgLum > 128
UP      = isLight ? #4E9A06 : #B4FF39   // acid lime: accumulation, rising candles
DN      = isLight ? #D9480F : #FF6B2C   // ember: distribution, falling candles
ACC     = isLight ? #3F4BD9 : #7C8CFF   // electric indigo: trading range and phases
ACCX    = isLight ? #2F38A8 : #B4BDFF   // light indigo for text
GREY    = isLight ? #8A8F9C : #5A6070
TXT     = isLight ? #1A1D24 : #ECEEF4
MUTE    = isLight ? #5E6472 : #969CAB
PANEL   = isLight ? #FFFFFF : #0A0C12
ROW     = isLight ? #F0F2F8 : #13161F
INK     = #0A0C12
NONE    = color.new(color.black, 100)
 
lSize = lblSize == "Small" ? size.small : lblSize == "Large" ? size.large : size.normal
tSize = tblSize == "Small" ? size.small : tblSize == "Large" ? size.large : size.normal
 
px(float v) =>
    str.tostring(v, format.mintick)
 
pct(int a, int b) =>
    b > 0 ? str.tostring(a * 100.0 / b, "0") + "%" : "—"
 
// ─────────────────────────────────────────────────────────────────────────
//  SERIES (computed on every bar)
// ─────────────────────────────────────────────────────────────────────────
atr    = ta.atr(50)
avgV   = ta.sma(nz(volume), 20)
hasVol = avgV > 0
rngOk  = not na(atr) and high - low >= climRng * atr
volOk  = not hasVol or nz(volume) >= climVol * avgV
newLo  = low <= ta.lowest(low, trendLen)
newHi  = high >= ta.highest(high, trendLen)
ph     = ta.pivothigh(high, pivLen, pivLen)
pl     = ta.pivotlow(low, pivLen, pivLen)
pBar   = bar_index - pivLen
 
// ─────────────────────────────────────────────────────────────────────────
//  STATE
//  stage 0 searching · 1 phase A (climax, waiting for AR) · 2 phase B (range)
//  stage 3 phase C (spring / UTAD confirmed) · 4 phase D (SOS / SOW)
//  stage 5 phase E (LPS / LPSY confirmed, markup or markdown)
//  dir  1 = accumulation (SC low, AR high, spring below, SOS up)
//  dir -1 = distribution (BC high, AR low, UTAD above, SOW down)
// ─────────────────────────────────────────────────────────────────────────
var int   stage  = 0
var int   dir    = 0
var int   startBar = na
var float ext    = na      // climax extreme
var int   extBar = na
var float arP    = na
var int   arBar  = na
var float trTop  = na
var float trBot  = na
var float trMid  = na
var float rngH   = na
var float cs     = na      // climax side of the range (support in accumulation)
var float bs     = na      // breakout side: the creek in accumulation, the ice in distribution
var bool  stOn   = false
var bool  sprOn  = false
var float sprExt = na
var int   sprBar = na
var bool  pend   = false
var int   pendN  = 0
var float pendExt = na
var int   pendExtBar = na
var int   sosBar = na
var bool  lpsOn  = false
var float t1     = na
var float t2     = na
var float inv    = na
var int   hitMax = 0
 
var array<chart.point> pts = array.new<chart.point>()
 
var box      trBox  = na
var line     bsLn   = na
var label    bsLb   = na
var label    climLb = na
var polyline schPl  = na
var line     t1Ln = na
var line     t2Ln = na
var line     invLn = na
var label    t1Lb = na
var label    t2Lb = na
var label    invLb = na
 
// record: index 0 = accumulation, 1 = distribution
var array<int> rN    = array.new_int(2, 0)
var array<int> rSpr  = array.new_int(2, 0)
var array<int> rSos  = array.new_int(2, 0)
var array<int> rT1   = array.new_int(2, 0)
var array<int> rT2   = array.new_int(2, 0)
var array<int> rFail = array.new_int(2, 0)
var array<int> rLen  = array.new_int(2, 0)
 
evClim  = false
evRange = false
evSpr   = false
evSos   = false
evLps   = false
evHit   = 0
evFrom  = 0
evDone  = false
evFail  = false
evExp   = false
evDrop  = false
evEnd   = false
 
bump(array<int> a, int i, int add) =>
    array.set(a, i, array.get(a, i) + add)
 
// ── drawing registry: every object of a model is filed under its id,
//    so only the last "Ranges drawn" models stay on the chart
var int mId = 0
var array<line>     gLn  = array.new<line>()
var array<int>      gLnI = array.new_int()
var array<label>    gLb  = array.new<label>()
var array<int>      gLbI = array.new_int()
var array<box>      gBx  = array.new<box>()
var array<int>      gBxI = array.new_int()
var array<polyline> gPl  = array.new<polyline>()
var array<int>      gPlI = array.new_int()
 
regLn(line o) =>
    array.push(gLn, o)
    array.push(gLnI, mId)
regLb(label o) =>
    array.push(gLb, o)
    array.push(gLbI, mId)
regBx(box o) =>
    array.push(gBx, o)
    array.push(gBxI, mId)
regPl(polyline o) =>
    array.push(gPl, o)
    array.push(gPlI, mId)
 
prune(int upTo) =>
    while array.size(gLnI) > 0 and array.get(gLnI, 0) <= upTo
        line.delete(array.shift(gLn))
        array.shift(gLnI)
    while array.size(gLbI) > 0 and array.get(gLbI, 0) <= upTo
        label.delete(array.shift(gLb))
        array.shift(gLbI)
    while array.size(gBxI) > 0 and array.get(gBxI, 0) <= upTo
        box.delete(array.shift(gBx))
        array.shift(gBxI)
    while array.size(gPlI) > 0 and array.get(gPlI, 0) <= upTo
        polyline.delete(array.shift(gPl))
        array.shift(gPlI)
 
// removes the drawings of a model that turned out not to be a range
dropTail(int id) =>
    while array.size(gLnI) > 0 and array.last(gLnI) == id
        line.delete(array.pop(gLn))
        array.pop(gLnI)
    while array.size(gLbI) > 0 and array.last(gLbI) == id
        label.delete(array.pop(gLb))
        array.pop(gLbI)
    while array.size(gBxI) > 0 and array.last(gBxI) == id
        box.delete(array.pop(gBx))
        array.pop(gBxI)
    while array.size(gPlI) > 0 and array.last(gPlI) == id
        polyline.delete(array.pop(gPl))
        array.pop(gPlI)
 
// event label: below the bar for lows, above it for highs
evLb(int x, float y, string t, bool below, color bg, color fg) =>
    lb = label.new(x, y, t, style = below ? label.style_label_up : label.style_label_down, color = bg, textcolor = fg, size = lSize)
    regLb(lb)
    lb
 
phLb(int x, string t) =>
    if showPh
        regLb(label.new(x, trTop, t, style = label.style_label_down, color = NONE, textcolor = ACCX, size = lSize))
 
redraw(polyline old, color c) =>
    polyline.delete(old)
    polyline p = na
    if showPath and array.size(pts) > 1
        p := polyline.new(pts, curved = true, line_color = color.new(c, 25), line_width = 2, line_style = line.style_solid)
        regPl(p)
    p
 
tgtLn(float y, color c, int w, string st) =>
    l = line.new(sosBar, y, bar_index + 3, y, color = c, width = w, style = st)
    regLn(l)
    l
 
tgtLb(float y, string t, color c) =>
    l = label.new(bar_index + 3, y, t, style = label.style_label_left, color = INK, textcolor = c, size = lSize)
    regLb(l)
    l
 
// ─────────────────────────────────────────────────────────────────────────
//  STATE MACHINE — closed bars only
// ─────────────────────────────────────────────────────────────────────────
if barstate.isconfirmed and not na(atr)
    age    = bar_index - startBar
    early  = age < minRange
    wickC  = dir == 1 ? low : high       // the wick on the climax side
    fav    = dir == 1 ? high : low       // the wick on the breakout side
    dc     = dir == 1 ? UP : DN
 
    // ── D · E: targets, invalidation, LPS / LPSY
    if stage >= 4
        prevHit = hitMax
        if (fav - t2) * dir >= 0
            hitMax := 2
        else if hitMax < 1 and (fav - t1) * dir >= 0
            hitMax := 1
        if hitMax > prevHit
            evHit  := hitMax
            evFrom := prevHit
        if hitMax == 2
            evDone := true
        else if (inv - close) * dir > 0
            evFail := true
        else if bar_index - sosBar > maxLeg
            evExp := true
        if stage == 4 and not evDone and not evFail
            pv = dir == 1 ? pl : ph
            if not na(pv) and pBar > sosBar and (pv - trMid) * dir > 0
                stage := 5
                lpsOn := true
                evLps := true
                evLb(pBar, pv, dir == 1 ? "LPS" : "LPSY", dir == 1, dc, INK)
                phLb(pBar, "E")
                array.push(pts, chart.point.from_index(pBar, pv))
                schPl := redraw(schPl, dc)
 
    // ── B · C: secondary test, spring / UTAD, SOS / SOW
    else if stage == 2 or stage == 3
        if stage == 2 and not pend and not stOn
            pv = dir == 1 ? pl : ph
            if not na(pv) and pBar > arBar and (pv - cs) * dir >= 0 and (pv - cs) * dir <= stTol * rngH
                stOn := true
                evLb(pBar, pv, "ST", dir == 1, GREY, color.white)
                phLb(pBar, "B")
                array.push(pts, chart.point.from_index(pBar, pv))
                schPl := redraw(schPl, dc)
        if (close - bs) * dir > 0
            if early
                evDrop := true
            else
                stage  := 4
                sosBar := bar_index
                evSos  := true
                t1  := bs + dir * rngH
                t2  := bs + dir * 2 * rngH
                inv := sprOn ? sprExt : cs
                evLb(bar_index, fav, dir == 1 ? "SOS" : "SOW", dir == -1, dc, INK)
                phLb(bar_index, "D")
                array.push(pts, chart.point.from_index(bar_index, fav))
                schPl := redraw(schPl, dc)
                box.set_right(trBox, bar_index)
                line.set_x2(bsLn, bar_index)
                label.set_x(bsLb, bar_index)
                if showTgt
                    t1Ln  := tgtLn(t1, color.new(dc, 10), 2, line.style_solid)
                    t2Ln  := tgtLn(t2, color.new(dc, 10), 2, line.style_dashed)
                    invLn := tgtLn(inv, color.new(GREY, 10), 1, line.style_dotted)
                    t1Lb  := tgtLb(t1, "T1 · 1× range  " + px(t1), dc)
                    t2Lb  := tgtLb(t2, "T2 · 2× range  " + px(t2), dc)
                    invLb := tgtLb(inv, "INVALID  " + px(inv), MUTE)
        else if stage == 2
            if pend
                pendN += 1
                if (pendExt - wickC) * dir > 0
                    pendExt    := wickC
                    pendExtBar := bar_index
                if (close - cs) * dir >= 0
                    pend := false
                    if not early
                        sprOn  := true
                        sprExt := pendExt
                        sprBar := pendExtBar
                else if (cs - close) * dir > failDep * rngH or pendN > sprBars
                    if early
                        evDrop := true
                    else
                        evFail := true
            else if (cs - wickC) * dir > 0
                if (close - cs) * dir >= 0
                    if not early
                        sprOn  := true
                        sprExt := wickC
                        sprBar := bar_index
                else if (cs - close) * dir > failDep * rngH
                    if early
                        evDrop := true
                    else
                        evFail := true
                else
                    pend       := true
                    pendN      := 1
                    pendExt    := wickC
                    pendExtBar := bar_index
            if sprOn
                stage := 3
                evSpr := true
                evLb(sprBar, sprExt, dir == 1 ? "SPRING" : "UTAD", dir == 1, ACC, color.white)
                phLb(sprBar, "C")
                array.push(pts, chart.point.from_index(sprBar, sprExt))
                schPl := redraw(schPl, dc)
            else if age > maxRng and not evFail and not evDrop
                evExp := true
        else
            if (sprExt - close) * dir > 0
                evFail := true
            else if bar_index - sprBar > maxRng
                evExp := true
 
    // ── A: the climax extends until the automatic rally / reaction forms
    else if stage == 1
        if (ext - wickC) * dir > 0
            ext    := wickC
            extBar := bar_index
            label.set_xy(climLb, extBar, ext)
        pv = dir == 1 ? ph : pl
        if not na(pv) and pBar > extBar and (pv - ext) * dir >= arMin * atr
            if math.abs(pv - ext) > maxH * atr
                evDrop := true
            else
                stage := 2
                evRange := true
                arP   := pv
                arBar := pBar
                trTop := math.max(ext, arP)
                trBot := math.min(ext, arP)
                trMid := (trTop + trBot) / 2
                rngH  := trTop - trBot
                cs    := ext
                bs    := arP
                trBox := box.new(extBar, trTop, bar_index, trBot, border_color = color.new(ACC, 40), border_width = 2, bgcolor = color.new(ACC, 91),
                     text = dir == 1 ? "ACCUMULATION RANGE" : "DISTRIBUTION RANGE", text_color = ACCX, text_size = size.small,
                     text_halign = text.align_left, text_valign = dir == 1 ? text.align_bottom : text.align_top)
                regBx(trBox)
                bsLn := line.new(arBar, bs, bar_index, bs, color = color.new(dc, 15), width = 2, style = line.style_dashed)
                regLn(bsLn)
                bsLb := label.new(bar_index, bs, dir == 1 ? "CREEK" : "ICE", style = label.style_label_left, color = NONE, textcolor = dc, size = size.small)
                regLb(bsLb)
                evLb(arBar, arP, "AR", dir == -1, GREY, color.white)
                phLb(extBar, "A")
                array.push(pts, chart.point.from_index(extBar, ext))
                array.push(pts, chart.point.from_index(arBar, arP))
                schPl := redraw(schPl, dc)
        else if bar_index - extBar > trendLen
            evDrop := true
 
    // ── searching for a climax
    if stage == 0
        sc = side != "Distribution" and newLo and rngOk and volOk
        bc = side != "Accumulation" and newHi and rngOk and volOk
        if sc or bc
            mId    += 1
            dir    := sc and (not bc or close < open) ? 1 : -1
            stage  := 1
            ext    := dir == 1 ? low : high
            extBar := bar_index
            startBar := bar_index
            stOn   := false
            sprOn  := false
            pend   := false
            pendN  := 0
            sosBar := na
            lpsOn  := false
            hitMax := 0
            schPl  := na
            array.clear(pts)
            evClim := true
            climLb := evLb(bar_index, ext, dir == 1 ? "SC" : "BC", dir == 1, GREY, color.white)
 
    // ── endings
    if evDrop
        dropTail(mId)
        stage := 0
    if (evFail or evDone or evExp) and stage >= 2
        d = dir == 1 ? 0 : 1
        bump(rN, d, 1)
        bump(rSpr, d, sprOn ? 1 : 0)
        bump(rSos, d, na(sosBar) ? 0 : 1)
        bump(rT1, d, hitMax >= 1 ? 1 : 0)
        bump(rT2, d, hitMax >= 2 ? 1 : 0)
        bump(rFail, d, evFail ? 1 : 0)
        if not na(sosBar)
            bump(rLen, d, sosBar - startBar)
        if na(sosBar)
            box.set_right(trBox, bar_index)
            line.set_x2(bsLn, bar_index)
            label.set_x(bsLb, bar_index)
        if evFail
            evLb(bar_index, dir == 1 ? low : high, "FAILED", dir == 1, color.new(GREY, 20), color.white)
        evEnd := true
        stage := 0
        prune(mId - keepN)
 
// running drawings follow the current bar
if stage == 2 or stage == 3
    box.set_right(trBox, bar_index)
    line.set_x2(bsLn, bar_index)
    label.set_x(bsLb, bar_index)
if stage >= 4 and showTgt
    line.set_x2(t1Ln, bar_index + 3)
    line.set_x2(t2Ln, bar_index + 3)
    line.set_x2(invLn, bar_index + 3)
    label.set_x(t1Lb, bar_index + 3)
    label.set_x(t2Lb, bar_index + 3)
    label.set_x(invLb, bar_index + 3)
if evHit > 0 and showTgt
    for k = evFrom + 1 to evHit
        lb = k == 1 ? t1Lb : t2Lb
        label.set_text(lb, "✓ " + label.get_text(lb))
if evEnd and showTgt and not na(sosBar)
    line.set_x2(t1Ln, bar_index)
    line.set_x2(t2Ln, bar_index)
    line.set_x2(invLn, bar_index)
    label.set_x(t1Lb, bar_index + 1)
    label.set_x(t2Lb, bar_index + 1)
    label.set_x(invLb, bar_index + 1)
 
// ─────────────────────────────────────────────────────────────────────────
//  PANEL — phase ladder
// ─────────────────────────────────────────────────────────────────────────
pos = tblPos == "Top Right" ? position.top_right : tblPos == "Bottom Right" ? position.bottom_right : tblPos == "Top Left" ? position.top_left : position.bottom_left
var table tb = na
 
cell(int c, int r, string t, color fg, color bg, string al = text.align_left) =>
    table.cell(tb, c, r, t, text_color = fg, bgcolor = bg, text_size = tSize, text_halign = al)
 
tick(bool b) =>
    b ? " ✓" : ""
 
if barstate.islast and showTbl
    table.delete(tb)   // rebuilt each time: merged cells cannot be merged twice
    tb := table.new(pos, 5, 15, bgcolor = PANEL, border_color = PANEL, border_width = 2, frame_color = color.new(ACC, 25), frame_width = 2)
    acc = dir == 1
    mc  = stage == 0 ? GREY : acc ? UP : DN
    cell(0, 0, "WYCKOFF", ACCX, PANEL)
    table.merge_cells(tb, 0, 0, 1, 0)
    cell(2, 0, stage == 0 ? "SEARCHING" : acc ? "ACCUMULATION ▲" : "DISTRIBUTION ▼", stage == 0 ? TXT : INK, stage == 0 ? ROW : mc, text.align_center)
    table.merge_cells(tb, 2, 0, 4, 0)
    rngTxt = stage >= 2 ? px(trBot) + " – " + px(trTop) + "  ·  " + str.tostring(rngH / atr, "0.0") + "× ATR  ·  " + str.tostring(bar_index - startBar) + " bars" :
         stage == 1 ? (acc ? "SC printed · waiting for AR" : "BC printed · waiting for AR") : "waiting for a climax"
    cell(0, 1, rngTxt, MUTE, PANEL)
    table.merge_cells(tb, 0, 1, 4, 1)
    // phase ladder: A..E, current phase highlighted
    cur = stage == 0 ? 0 : stage
    for k = 1 to 5
        done = k < cur
        now  = k == cur
        ltr  = k == 1 ? "A" : k == 2 ? "B" : k == 3 ? "C" : k == 4 ? "D" : "E"
        ttl  = k == 1 ? "Stopping action" : k == 2 ? "Building the cause" : k == 3 ? (acc ? "Test of supply" : "Test of demand") : k == 4 ? (acc ? "Sign of strength" : "Sign of weakness") : (acc ? "Markup" : "Markdown")
        evs = k == 1 ? (stage == 0 ? "SC · AR" : (acc ? "SC" : "BC") + " ✓  AR" + tick(stage >= 2)) :
             k == 2 ? "ST" + tick(stOn) :
             k == 3 ? (acc ? "SPRING" : "UTAD") + (sprOn ? " ✓" : stage >= 4 ? " —" : "") :
             k == 4 ? (acc ? "SOS" : "SOW") + tick(stage >= 4) :
             (acc ? "LPS" : "LPSY") + tick(lpsOn) + "  T1" + tick(hitMax >= 1) + "  T2" + tick(hitMax >= 2)
        rb = now ? color.new(ACC, isLight ? 85 : 78) : ROW
        cell(0, 1 + k, ltr, done or now ? INK : MUTE, done ? mc : now ? ACC : ROW, text.align_center)
        cell(1, 1 + k, ttl, now ? TXT : done ? TXT : MUTE, rb)
        cell(2, 1 + k, evs, done or now ? TXT : MUTE, rb)
        table.merge_cells(tb, 2, 1 + k, 3, 1 + k)
        cell(4, 1 + k, done ? "●" : now ? "◉" : "○", done ? mc : now ? ACCX : MUTE, rb, text.align_center)
    // price inside the range
    posIn = stage >= 2 ? math.max(0.0, math.min(1.0, (close - trBot) / rngH)) : na
    nFill = na(posIn) ? 0 : int(math.round(posIn * 10))
    meter = ""
    for k = 1 to 10
        meter += k <= nFill ? "▰" : "▱"
    cell(0, 7, "Price in range", MUTE, PANEL)
    table.merge_cells(tb, 0, 7, 1, 7)
    cell(2, 7, na(posIn) ? "—" : meter + "  " + str.tostring(posIn * 100, "0") + "%", na(posIn) ? MUTE : ACCX, PANEL)
    table.merge_cells(tb, 2, 7, 4, 7)
    cell(0, 8, "Targets", MUTE, PANEL)
    table.merge_cells(tb, 0, 8, 1, 8)
    cell(2, 8, stage >= 4 ? "T1 " + px(t1) + "  ·  T2 " + px(t2) + "  ·  invalid " + px(inv) : "after " + (acc ? "SOS" : "SOW"), stage >= 4 ? mc : MUTE, PANEL)
    table.merge_cells(tb, 2, 8, 4, 8)
 
    // track record
    cell(0, 9, "THIS SYMBOL · " + str.tostring(array.sum(rN)) + " RANGES", ACCX, PANEL)
    table.merge_cells(tb, 0, 9, 4, 9)
    cell(0, 10, "", MUTE, PANEL)
    cell(1, 10, "Spring/UTAD", MUTE, PANEL, text.align_center)
    cell(2, 10, "SOS/SOW", MUTE, PANEL, text.align_center)
    cell(3, 10, "T2 hit", MUTE, PANEL, text.align_center)
    cell(4, 10, "Failed", MUTE, PANEL, text.align_center)
    for d = 0 to 1
        n = array.get(rN, d)
        cell(0, 11 + d, d == 0 ? "▲ Accum. " + str.tostring(n) : "▼ Distr. " + str.tostring(n), d == 0 ? UP : DN, ROW)
        cell(1, 11 + d, pct(array.get(rSpr, d), n), TXT, ROW, text.align_center)
        cell(2, 11 + d, pct(array.get(rSos, d), n), TXT, ROW, text.align_center)
        cell(3, 11 + d, pct(array.get(rT2, d), n), d == 0 ? UP : DN, ROW, text.align_center)
        cell(4, 11 + d, pct(array.get(rFail, d), n), MUTE, ROW, text.align_center)
    sosN = array.sum(rSos)
    avgL = sosN > 0 ? array.sum(rLen) * 1.0 / sosN : na
    cell(0, 13, "Avg range before the break: " + (na(avgL) ? "—" : str.tostring(avgL, "0") + " bars"), MUTE, PANEL)
    table.merge_cells(tb, 0, 13, 4, 13)
 
// ─────────────────────────────────────────────────────────────────────────
//  ALERTS
// ─────────────────────────────────────────────────────────────────────────
if alRange and evClim
    alert(syminfo.ticker + " Wyckoff " + (dir == 1 ? "selling climax (SC) — accumulation possible" : "buying climax (BC) — distribution possible"), alert.freq_once_per_bar_close)
if alRange and evRange
    alert(syminfo.ticker + " Wyckoff trading range set: " + px(trBot) + " – " + px(trTop) + (dir == 1 ? " · accumulation" : " · distribution"), alert.freq_once_per_bar_close)
if alTest and evSpr
    alert(syminfo.ticker + " Wyckoff " + (dir == 1 ? "spring" : "UTAD") + " confirmed at " + px(sprExt), alert.freq_once_per_bar_close)
if alSos and evSos
    alert(syminfo.ticker + " Wyckoff " + (dir == 1 ? "sign of strength (SOS) — range left upward" : "sign of weakness (SOW) — range left downward") + " · T1 " + px(t1) + " · T2 " + px(t2) + " · invalid beyond " + px(inv), alert.freq_once_per_bar_close)
if alSos and evLps
    alert(syminfo.ticker + " Wyckoff " + (dir == 1 ? "last point of support (LPS)" : "last point of supply (LPSY)") + " confirmed", alert.freq_once_per_bar_close)
if alTgt and evHit > 0 and not evDone
    alert(syminfo.ticker + " Wyckoff target T" + str.tostring(evHit) + " hit", alert.freq_once_per_bar_close)
if alTgt and evDone
    alert(syminfo.ticker + " Wyckoff schematic complete: T2 reached", alert.freq_once_per_bar_close)
if alTgt and evFail
    alert(syminfo.ticker + " Wyckoff schematic failed", alert.freq_once_per_bar_close)
 
alertcondition(evSpr and dir == 1, "Wyckoff spring", "{{ticker}} Wyckoff spring confirmed")
alertcondition(evSpr and dir == -1, "Wyckoff UTAD", "{{ticker}} Wyckoff UTAD confirmed")
alertcondition(evSos and dir == 1, "Wyckoff SOS", "{{ticker}} Wyckoff sign of strength")
alertcondition(evSos and dir == -1, "Wyckoff SOW", "{{ticker}} Wyckoff sign of weakness")
alertcondition(evLps, "Wyckoff LPS / LPSY", "{{ticker}} Wyckoff LPS / LPSY confirmed")
alertcondition(evHit > 0, "Wyckoff target hit", "{{ticker}} Wyckoff target hit")
alertcondition(evFail, "Wyckoff schematic failed", "{{ticker}} Wyckoff schematic failed")
 
// ─────────────────────────────────────────────────────────────────────────
//  GLOW CANDLES (LunqFX house style)
// ─────────────────────────────────────────────────────────────────────────
GLOW_UP_DARK  = #B4FF39
GLOW_DN_DARK  = #FF6B2C
GLOW_UP_LIGHT = #4E9A06
GLOW_DN_LIGHT = #D9480F
 
glowUp   = isLight ? GLOW_UP_LIGHT : GLOW_UP_DARK
glowDn   = isLight ? GLOW_DN_LIGHT : GLOW_DN_DARK
glowEdge = close >= open ? glowUp : glowDn
glowOn   = candOn_ and candGlw
GLOW_NONE = color.new(color.black, 100)
 
plotcandle(candOn_ and not glowOn ? open : na, high, low, close, "Candles", color = color.new(glowEdge, 24), wickcolor = color.new(glowEdge, 18), bordercolor = glowEdge, display = display.pane)
 
gQ = (close - open) / 4.0
plotcandle(glowOn ? open : na, glowOn ? math.max(open, close) : na, glowOn ? math.min(open, close) : na, glowOn ? close : na, "Glow mask", color = chart.bg_color, wickcolor = GLOW_NONE, bordercolor = chart.bg_color, display = display.pane)
plotcandle(glowOn ? open : na, glowOn ? math.max(open, open + gQ) : na, glowOn ? math.min(open, open + gQ) : na, glowOn ? open + gQ : na, "Glow band 1", color = color.new(glowEdge, 78), wickcolor = GLOW_NONE, bordercolor = GLOW_NONE, display = display.pane)
plotcandle(glowOn ? open + gQ : na, glowOn ? math.max(open + gQ, open + 2 * gQ) : na, glowOn ? math.min(open + gQ, open + 2 * gQ) : na, glowOn ? open + 2 * gQ : na, "Glow band 2", color = color.new(glowEdge, 58), wickcolor = GLOW_NONE, bordercolor = GLOW_NONE, display = display.pane)
plotcandle(glowOn ? open + 2 * gQ : na, glowOn ? math.max(open + 2 * gQ, open + 3 * gQ) : na, glowOn ? math.min(open + 2 * gQ, open + 3 * gQ) : na, glowOn ? open + 3 * gQ : na, "Glow band 3", color = color.new(glowEdge, 36), wickcolor = GLOW_NONE, bordercolor = GLOW_NONE, display = display.pane)
plotcandle(glowOn ? open + 3 * gQ : na, glowOn ? math.max(open + 3 * gQ, close) : na, glowOn ? math.min(open + 3 * gQ, close) : na, glowOn ? close : na, "Glow band 4", color = color.new(glowEdge, 8), wickcolor = GLOW_NONE, bordercolor = GLOW_NONE, display = display.pane)
plotcandle(glowOn ? open : na, glowOn ? high : na, glowOn ? low : na, glowOn ? close : na, "Glow wick", color = GLOW_NONE, wickcolor = color.new(glowEdge, 10), bordercolor = color.new(glowEdge, 30), display = display.pane)

← 返回列表