//@version=6 indicator("XAUUSD SevenD Visible Marker v2", overlay=true, max_labels_count=500, max_bars_back=1000) // Purpose: visible real-time marker/counter version. Marker-only. No entries, no TP/SL, no webhook. // More permissive than research detector so the chart visibly counts 1+3+10+13 routes. lookback = input.int(18, "作底/作頂 lookback", minval=5, maxval=80) maxAnchorGap = input.int(18, "作底/作頂最多早過1幾多支", minval=0, maxval=80) maxI3Bars = input.int(9, "1到小3最多K數", minval=4, maxval=12) minBarsTo3 = input.int(2, "1到小3最少K數", minval=1, maxval=6) maxPost10Bars = input.int(30, "10到13最多K數", minval=5, maxval=60) minSwingPts = input.float(0.0, "Min swing points (0=show all)", minval=0.0, step=0.5) showAnchor = input.bool(true, "顯示作底/作頂") showSmall12 = input.bool(true, "顯示小1/小2、11/12") showRaw1 = input.bool(true, "顯示 raw 1/-1 候選") ready = bar_index >= lookback + 5 lowOff = int(math.abs(ta.lowestbars(low, lookback))) highOff = int(math.abs(ta.highestbars(high, lookback))) ctxHigh = ta.highest(high, lookback) ctxLow = ta.lowest(low, lookback) f_label(_x, _txt, _isUp, _strong) => c = _isUp ? (_strong ? color.new(color.lime, 0) : color.new(color.green, 55)) : (_strong ? color.new(color.red, 0) : color.new(color.orange, 55)) st = _isUp ? label.style_label_up : label.style_label_down yl = _isUp ? yloc.belowbar : yloc.abovebar label.new(_x, na, _txt, xloc=xloc.bar_index, yloc=yl, style=st, color=c, textcolor=color.white, size=size.tiny) f_max_from_idx(_idx) => float out = high int off = bar_index - _idx int lim = math.min(math.max(off, 0), 120) for k = 0 to 120 if k <= lim and k <= bar_index out := math.max(out, high[k]) out f_min_from_idx(_idx) => float out = low int off = bar_index - _idx int lim = math.min(math.max(off, 0), 120) for k = 0 to 120 if k <= lim and k <= bar_index out := math.min(out, low[k]) out // state var int upState = 0 var int dnState = 0 var int upAnchorIdx = na var int dnAnchorIdx = na var int upBigIdx = na var int dnBigIdx = na var int upI3Idx = na var int dnI3Idx = na var int up10Idx = na var int dn10Idx = na var float upBigClose = na var float dnBigClose = na var float up10Close = na var float dn10Close = na var float upHighFromAnchor = na var float dnLowFromAnchor = na var float upHighFrom10 = na var float dnLowFrom10 = na bool up1Sig=false, dn1Sig=false, up3Sig=false, dn3Sig=false, up10Sig=false, dn10Sig=false, up13Sig=false, dn13Sig=false up1Sig:=false, dn1Sig:=false, up3Sig:=false, dn3Sig:=false, up10Sig:=false, dn10Sig:=false, up13Sig:=false, dn13Sig:=false // candidate 1s: close direction + near recent extreme. Swing filter optional. upSwingOk = minSwingPts <= 0 or (ctxHigh - low[lowOff]) >= minSwingPts dnSwingOk = minSwingPts <= 0 or (high[highOff] - ctxLow) >= minSwingPts upCandidate = ready and barstate.isconfirmed and close > open and lowOff <= maxAnchorGap and upSwingOk dnCandidate = ready and barstate.isconfirmed and close < open and highOff <= maxAnchorGap and dnSwingOk if barstate.isconfirmed and ready // reset opposite route if fresh new candidate appears, real-time counting style if upCandidate and (upState == 0 or close < nz(upBigClose, close + 1)) upState := 1 upAnchorIdx := bar_index - lowOff upBigIdx := bar_index upBigClose := close upI3Idx := na up10Idx := na up10Close := na upHighFromAnchor := f_max_from_idx(upAnchorIdx) upHighFrom10 := na if showAnchor and lowOff > 0 f_label(upAnchorIdx, "作底", true, false) f_label(bar_index, lowOff == 0 ? "作底+1" : "1", true, true) up1Sig := true if dnCandidate and (dnState == 0 or close > nz(dnBigClose, close - 1)) dnState := 1 dnAnchorIdx := bar_index - highOff dnBigIdx := bar_index dnBigClose := close dnI3Idx := na dn10Idx := na dn10Close := na dnLowFromAnchor := f_min_from_idx(dnAnchorIdx) dnLowFrom10 := na if showAnchor and highOff > 0 f_label(dnAnchorIdx, "作頂", false, false) f_label(bar_index, highOff == 0 ? "作頂-1" : "-1", false, true) dn1Sig := true // invalidation before 3 if upState == 1 and close < upBigClose upState := 0 if dnState == 1 and close > dnBigClose dnState := 0 // up 3: close break previous wick high from anchor within 9 bars from big1 if upState == 1 and bar_index > upBigIdx priorH = upHighFromAnchor can3 = bar_index >= upBigIdx + minBarsTo3 and bar_index <= upBigIdx + maxI3Bars - 1 and close > open and close > priorH if can3 if showSmall12 and upBigIdx + 1 < bar_index f_label(upBigIdx + 1, "小1", true, false) if showSmall12 and upBigIdx + 2 < bar_index f_label(upBigIdx + 2, "小2", true, false) f_label(bar_index, "3", true, true) up3Sig := true upI3Idx := bar_index upState := 2 upHighFromAnchor := math.max(upHighFromAnchor, high) else upHighFromAnchor := math.max(upHighFromAnchor, high) if bar_index > upBigIdx + maxI3Bars - 1 upState := 0 // down -3 if dnState == 1 and bar_index > dnBigIdx priorL = dnLowFromAnchor can3 = bar_index >= dnBigIdx + minBarsTo3 and bar_index <= dnBigIdx + maxI3Bars - 1 and close < open and close < priorL if can3 if showSmall12 and dnBigIdx + 1 < bar_index f_label(dnBigIdx + 1, "小-1", false, false) if showSmall12 and dnBigIdx + 2 < bar_index f_label(dnBigIdx + 2, "小-2", false, false) f_label(bar_index, "-3", false, true) dn3Sig := true dnI3Idx := bar_index dnState := 2 dnLowFromAnchor := math.min(dnLowFromAnchor, low) else dnLowFromAnchor := math.min(dnLowFromAnchor, low) if bar_index > dnBigIdx + maxI3Bars - 1 dnState := 0 // 10: counts from 作底/作頂 unless same as big1, close break all prior wick extremes from count start. if upState == 2 and bar_index > upI3Idx countStart = upAnchorIdx == upBigIdx ? upBigIdx : upAnchorIdx priorH10 = f_max_from_idx(countStart) can10 = bar_index >= countStart + 9 and close > open and close > priorH10 if can10 f_label(bar_index, "10", true, true) up10Sig := true up10Idx := bar_index up10Close := close upHighFrom10 := high upState := 3 else upHighFromAnchor := math.max(upHighFromAnchor, high) if dnState == 2 and bar_index > dnI3Idx countStart = dnAnchorIdx == dnBigIdx ? dnBigIdx : dnAnchorIdx priorL10 = f_min_from_idx(countStart) can10 = bar_index >= countStart + 9 and close < open and close < priorL10 if can10 f_label(bar_index, "-10", false, true) dn10Sig := true dn10Idx := bar_index dn10Close := close dnLowFrom10 := low dnState := 3 else dnLowFromAnchor := math.min(dnLowFromAnchor, low) // 11/12/13 after 10. 13 within 30 bars, close break from 10. if upState >= 3 and bar_index > up10Idx if close < up10Close upState := 0 else if upState == 3 and bar_index == up10Idx + 1 if showSmall12 f_label(bar_index, "11", true, false) upHighFrom10 := math.max(upHighFrom10, high) upState := 4 else if upState == 4 and bar_index == up10Idx + 2 if showSmall12 f_label(bar_index, "12", true, false) upHighFrom10 := math.max(upHighFrom10, high) upState := 5 else if upState == 5 priorH13 = upHighFrom10 can13 = bar_index <= up10Idx + maxPost10Bars - 1 and close > open and close > priorH13 if can13 f_label(bar_index, "13", true, true) up13Sig := true upState := 0 else upHighFrom10 := math.max(upHighFrom10, high) if bar_index > up10Idx + maxPost10Bars - 1 upState := 0 if dnState >= 3 and bar_index > dn10Idx if close > dn10Close dnState := 0 else if dnState == 3 and bar_index == dn10Idx + 1 if showSmall12 f_label(bar_index, "-11", false, false) dnLowFrom10 := math.min(dnLowFrom10, low) dnState := 4 else if dnState == 4 and bar_index == dn10Idx + 2 if showSmall12 f_label(bar_index, "-12", false, false) dnLowFrom10 := math.min(dnLowFrom10, low) dnState := 5 else if dnState == 5 priorL13 = dnLowFrom10 can13 = bar_index <= dn10Idx + maxPost10Bars - 1 and close < open and close < priorL13 if can13 f_label(bar_index, "-13", false, true) dn13Sig := true dnState := 0 else dnLowFrom10 := math.min(dnLowFrom10, low) if bar_index > dn10Idx + maxPost10Bars - 1 dnState := 0 // Backup visible shapes plotshape(showRaw1 and upCandidate, title="Raw up 1 candidate", text="1?", style=shape.circle, location=location.belowbar, color=color.new(color.green, 70), textcolor=color.white, size=size.tiny) plotshape(showRaw1 and dnCandidate, title="Raw down -1 candidate", text="-1?", style=shape.circle, location=location.abovebar, color=color.new(color.red, 70), textcolor=color.white, size=size.tiny) plotshape(up1Sig, title="SevenD 1", text="1", style=shape.triangleup, location=location.belowbar, color=color.green, textcolor=color.white, size=size.tiny) plotshape(dn1Sig, title="SevenD -1", text="-1", style=shape.triangledown, location=location.abovebar, color=color.red, textcolor=color.white, size=size.tiny) plotshape(up3Sig, title="SevenD 3", text="3", style=shape.labelup, location=location.belowbar, color=color.lime, textcolor=color.black, size=size.tiny) plotshape(dn3Sig, title="SevenD -3", text="-3", style=shape.labeldown, location=location.abovebar, color=color.orange, textcolor=color.black, size=size.tiny) plotshape(up10Sig, title="SevenD 10", text="10", style=shape.diamond, location=location.belowbar, color=color.teal, textcolor=color.white, size=size.tiny) plotshape(dn10Sig, title="SevenD -10", text="-10", style=shape.diamond, location=location.abovebar, color=color.purple, textcolor=color.white, size=size.tiny) plotshape(up13Sig, title="SevenD 13", text="13", style=shape.flag, location=location.belowbar, color=color.aqua, textcolor=color.black, size=size.tiny) plotshape(dn13Sig, title="SevenD -13", text="-13", style=shape.flag, location=location.abovebar, color=color.fuchsia, textcolor=color.white, size=size.tiny)