本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// ============================================================================
// ICT Silver Bullet Killzone, Time Window & FVG Entry [DNA]
// ----------------------------------------------------------------------------
// Watches the three ICT Silver Bullet New York windows (03:00-04:00,
// 10:00-11:00, 14:00-15:00). A window only "arms" once a liquidity sweep of
// the pre-window high/low is followed by a fair value gap in the opposite
// direction. That FVG is the entry zone; fill vs. invalidation is tracked
// bar by bar and a live, symmetric hit-rate is kept per window and overall.
//
// NON-REPAINTING: everything is decided on closed bars from confirmed pivots.
// No higher-timeframe requests, no lookahead.
// ============================================================================
indicator("ICT Silver Bullet Killzone, Time Window & FVG Entry [DNA]", "Silver Bullet [DNA]", overlay = true, max_lines_count = 300, max_labels_count = 300, max_boxes_count = 200)
// ─────────────────────────────────────────────────────────────────────────
// INPUTS
// ─────────────────────────────────────────────────────────────────────────
gL = "Logic/Swings"
tzInput = input.string("America/New_York", "Session timezone", group = gL, tooltip = "Timezone used to detect the three fixed New York kill zones.")
useKZ1 = input.bool(true, "03:00-04:00 NY", group = gL)
useKZ2 = input.bool(true, "10:00-11:00 NY", group = gL)
useKZ3 = input.bool(true, "14:00-15:00 NY", group = gL, tooltip = "Classic Silver Bullet works on 5-15m charts. Up to 1h is allowed: on 1h the FVG may form using the 'FVG wait' bars right after the window opens.")
lookback = input.int(20, "Liquidity lookback (bars)", minval = 5, maxval = 100, group = gL, tooltip = "High/low of the N bars before a window becomes the level watched for a sweep.")
minFvgATR = input.float(0.25, "Min. FVG size (× ATR)", minval = 0.05, maxval = 3.0, step = 0.05, group = gL, tooltip = "The 3-candle imbalance must be at least this many ATR to count as a tradeable entry zone.")
targetR = input.float(1.0, "Target (× R)", minval = 0.25, maxval = 5.0, step = 0.25, group = gL, tooltip = "Target distance in multiples of risk (entry→stop). Kept symmetric so the hit-rate is measured fairly.")
fvgWaitBars = input.int(6, "FVG wait (bars)", minval = 1, maxval = 30, group = gL, tooltip = "Bars after the window opens that sweep+FVG detection stays active. Lets the pattern form on the bar after the window on higher timeframes.")
fillWaitBars = input.int(10, "Fill wait (bars)", minval = 1, maxval = 50, group = gL, tooltip = "Bars allowed, after the FVG arms, for price to trade back into it. No return in time = 'no fill', excluded from the hit-rate.")
gD = "Drawing"
keepLast = input.int(8, "Items kept on the chart", minval = 1, maxval = 30, group = gD, tooltip = "Older finished patterns are removed from the chart. The counters keep all of them. Window boxes/levels keep up to 3× this many.")
showNoSetup = input.bool(false, "Show windows without a setup", group = gD, tooltip = "Off by default to keep the chart clean. When off, a window that never swept keeps only its faint box — no BSL/SSL lines, no 'no sweep' / 'no FVG' pill.")
labelSz = input.string("Small", "Label size", options = ["Small", "Normal", "Large"], group = gD, tooltip = "Small = tiny text, Normal = small text, Large = normal text. Kept compact by default so pills don't crowd the candles.")
gT = "Panel"
showPanel = input.bool(false, "Show the panel", group = gT, tooltip = "Off by default. Turn on to see the live counters.")
panelPos = input.string("Bottom centre", "Position", options = ["Bottom centre", "Bottom left", "Bottom right", "Top centre", "Top right"], group = gT)
panelSz = input.string("Normal", "Text size", options = ["Small", "Normal", "Large"], group = gT)
gA = "Alerts"
alOn = input.bool(true, "Alerts with full messages (alert() calls)", group = gA)
gV = "Visuals"
brandCandles = input.bool(true, "Brand candles", group = gV, tooltip = "Gold for rising candles, periwinkle for falling. Off = your own chart candles.")
glowCandles = input.bool(true, "Glow candles", group = gV, tooltip = "Each body is drawn in three bands that brighten towards the close. Off = flat bodies.")
// ─────────────────────────────────────────────────────────────────────────
// THEME (adapts to a light or dark chart)
// ─────────────────────────────────────────────────────────────────────────
chartBg = chart.bg_color
isLight = (color.r(chartBg) + color.g(chartBg) + color.b(chartBg)) / 3.0 > 140
UP = isLight ? #B07D0A : #F7C948 // gold: bullish, rising candles
DN = isLight ? #5546C8 : #8E7CFF // periwinkle: bearish, falling candles
ACC = isLight ? #0E8F7E : #5EEAD4 // mint: the zone / the level that matters
WARN = isLight ? #C2410C : #FF8A5B // failed / broken
TXT = isLight ? #12151C : #F2F3F7
MUTE = isLight ? #646B7D : #8E95A8
PANEL = isLight ? #FBFBFD : #0D1017
ROW = isLight ? #ECEEF4 : #171B26
INK = #0D1017
NONE = color.new(#000000, 100)
lSize = switch labelSz
"Small" => size.tiny
"Large" => size.normal
=> size.small
tSize = switch panelSz
"Small" => size.small
"Large" => size.large
=> size.normal
fmtPrice(float v) =>
str.tostring(v, format.mintick)
pct(int a, int b) =>
b > 0 ? str.tostring(math.round(100.0 * a / b)) + "%" : "—"
// ─────────────────────────────────────────────────────────────────────────
// CORE (per-killzone state machine: sweep → FVG → fill vs. invalidation)
// ─────────────────────────────────────────────────────────────────────────
// ta.* values used by every killzone are computed ONCE, unconditionally, at
// global scope, every bar. They are then passed into f_update as plain
// floats — f_update and every conditional block only ever read them, they
// never call ta.* themselves. Calling ta.highest/ta.lowest from inside an
// `if` (as the previous version did) desyncs their internal history series:
// on bars where the call is skipped the function's own [1] offset points at
// the wrong bar, which eventually hands a stale/na price into a box or line
// and breaks the whole price scale.
atr = ta.atr(14)
hiLB = ta.highest(high, lookback)[1]
loLB = ta.lowest(low, lookback)[1]
// Sessions: time(timeframe.period, sessionString, tzInput) evaluated at
// global scope, unconditionally, every bar — never inside a function or an
// `if`. na on bars outside the window, a timestamp on bars inside it.
in1 = useKZ1 and not na(time(timeframe.period, "0300-0400", tzInput))
in2 = useKZ2 and not na(time(timeframe.period, "1000-1100", tzInput))
in3 = useKZ3 and not na(time(timeframe.period, "1400-1500", tzInput))
type KZ
string stage
bool wasInSession
float preHi
float preLo
bool sweptHi
bool sweptLo
float sweepExtreme
int dirBias
int barsSinceOpen
int fillBarsElapsed
float fvgTop
float fvgBot
int fvgBarIdx
float entryPx
float stopPx
float targetPx
int entryBarIdx
float winHi
float winLo
int winStartBar
box winBox
line hiLine
line loLine
label tagLbl
label hiLbl
label loLbl
box zoneBox
box riskBox
box rewardBox
label resLbl
int nSweeps
int nSetups
int nEntered
int nReached1R
int nStopped
string tag
string rangeTxt
type Totals
int nSweeps
int nSetups
int nEntered
int nReached1R
int nStopped
bool evSweep
bool evArmed
bool evEntered
bool evReached
bool evStopped
var KZ kz1 = KZ.new(stage = "waiting for window", wasInSession = false, dirBias = 0, barsSinceOpen = 0, fillBarsElapsed = 0, nSweeps = 0, nSetups = 0, nEntered = 0, nReached1R = 0, nStopped = 0, tag = "03:00", rangeTxt = "03:00-04:00")
var KZ kz2 = KZ.new(stage = "waiting for window", wasInSession = false, dirBias = 0, barsSinceOpen = 0, fillBarsElapsed = 0, nSweeps = 0, nSetups = 0, nEntered = 0, nReached1R = 0, nStopped = 0, tag = "10:00", rangeTxt = "10:00-11:00")
var KZ kz3 = KZ.new(stage = "waiting for window", wasInSession = false, dirBias = 0, barsSinceOpen = 0, fillBarsElapsed = 0, nSweeps = 0, nSetups = 0, nEntered = 0, nReached1R = 0, nStopped = 0, tag = "14:00", rangeTxt = "14:00-15:00")
var Totals tot = Totals.new(nSweeps = 0, nSetups = 0, nEntered = 0, nReached1R = 0, nStopped = 0, evSweep = false, evArmed = false, evEntered = false, evReached = false, evStopped = false)
// Finished setups (FVG zone + risk/reward zones + result pill) — last `keepLast`.
var array<box> aZone = array.new<box>()
var array<box> aRisk = array.new<box>()
var array<box> aReward = array.new<box>()
var array<label> aLabel = array.new<label>()
// Session windows + pre-window liquidity levels — kept up to keepLast × 3,
// never deleted just because a new window opened.
var array<box> aWinBox = array.new<box>()
var array<label> aWinTag = array.new<label>()
var array<line> aHiLine = array.new<line>()
var array<line> aLoLine = array.new<line>()
var array<label> aHiTag = array.new<label>()
var array<label> aLoTag = array.new<label>()
var array<label> aSweptPill = array.new<label>()
var array<label> aOutcomePill = array.new<label>()
f_trimBoxArr(arr, maxN) =>
if array.size(arr) > maxN
o = array.shift(arr)
if not na(o)
box.delete(o)
f_trimLineArr(arr, maxN) =>
if array.size(arr) > maxN
o = array.shift(arr)
if not na(o)
line.delete(o)
f_trimLabelArr(arr, maxN) =>
if array.size(arr) > maxN
o = array.shift(arr)
if not na(o)
label.delete(o)
f_pushGroup(kz, keepLast, aZone, aRisk, aReward, aLabel) =>
array.push(aZone, kz.zoneBox)
array.push(aRisk, kz.riskBox)
array.push(aReward, kz.rewardBox)
array.push(aLabel, kz.resLbl)
if array.size(aLabel) > keepLast
oZ = array.shift(aZone)
oR = array.shift(aRisk)
oW = array.shift(aReward)
oL = array.shift(aLabel)
if not na(oZ)
box.delete(oZ)
if not na(oR)
box.delete(oR)
if not na(oW)
box.delete(oW)
if not na(oL)
label.delete(oL)
f_update(kz, tot, inSession, hiLB, loLB, lookbackBars, minFvgATR, targetR, fvgWaitBars, fillWaitBars, keepLast, showNoSetup,
aZone, aRisk, aReward, aLabel,
aWinBox, aWinTag, aHiLine, aLoLine, aHiTag, aLoTag, aSweptPill, aOutcomePill,
accCol, upCol, dnCol, warnCol, muteCol, lblSizeVal, atrVal) =>
if inSession and not kz.wasInSession
if kz.stage != "waiting for window" and not na(kz.zoneBox)
f_pushGroup(kz, keepLast, aZone, aRisk, aReward, aLabel) // orphaned pattern from the previous day, closed out as-is
kz.preHi := hiLB
kz.preLo := loLB
kz.sweptHi := false
kz.sweptLo := false
kz.dirBias := 0
kz.barsSinceOpen := 0
kz.fillBarsElapsed := 0
kz.entryBarIdx := na
kz.winHi := high
kz.winLo := low
kz.winStartBar := bar_index
kz.stage := "window open: watching sweep"
// Window box: never deleted on open — only ever trimmed by count.
if not na(high) and not na(low)
kz.winBox := box.new(bar_index, high, bar_index, low, border_color = color.new(accCol, 60), border_width = 1, bgcolor = color.new(accCol, 86))
array.push(aWinBox, kz.winBox)
f_trimBoxArr(aWinBox, keepLast * 3)
// Window tag: tiny, no background, pinned at the box's top-left
// corner just above it — never on the box's right edge, where it
// would crowd the live candles as the window extends.
kz.tagLbl := label.new(bar_index, high + atrVal * 0.2, "SB " + kz.tag, style = label.style_none, color = color.new(accCol, 100), textcolor = color.new(accCol, 20), size = size.tiny)
array.push(aWinTag, kz.tagLbl)
f_trimLabelArr(aWinTag, keepLast * 3)
// Pre-window liquidity levels: thin dotted lines, tiny BSL/SSL tags.
// Created for every window (it is "currently active" while watched);
// removed on close without a sweep further down when showNoSetup is off.
if not na(kz.preHi)
kz.hiLine := line.new(kz.winStartBar - lookbackBars, kz.preHi, bar_index, kz.preHi, color = color.new(muteCol, 25), style = line.style_dotted, width = 1)
array.push(aHiLine, kz.hiLine)
f_trimLineArr(aHiLine, keepLast * 3)
kz.hiLbl := label.new(bar_index, kz.preHi, "BSL", style = label.style_none, color = color.new(muteCol, 100), textcolor = muteCol, size = size.tiny)
array.push(aHiTag, kz.hiLbl)
f_trimLabelArr(aHiTag, keepLast * 3)
if not na(kz.preLo)
kz.loLine := line.new(kz.winStartBar - lookbackBars, kz.preLo, bar_index, kz.preLo, color = color.new(muteCol, 25), style = line.style_dotted, width = 1)
array.push(aLoLine, kz.loLine)
f_trimLineArr(aLoLine, keepLast * 3)
kz.loLbl := label.new(bar_index, kz.preLo, "SSL", style = label.style_none, color = color.new(muteCol, 100), textcolor = muteCol, size = size.tiny)
array.push(aLoTag, kz.loLbl)
f_trimLabelArr(aLoTag, keepLast * 3)
if kz.stage != "waiting for window"
kz.barsSinceOpen += 1
if inSession
kz.winHi := math.max(kz.winHi, high)
kz.winLo := math.min(kz.winLo, low)
if not na(kz.winBox)
box.set_top(kz.winBox, kz.winHi)
box.set_bottom(kz.winBox, kz.winLo)
box.set_right(kz.winBox, bar_index)
if not na(kz.tagLbl)
label.set_y(kz.tagLbl, kz.winHi + atrVal * 0.2)
if not na(kz.hiLine)
line.set_x2(kz.hiLine, bar_index)
if not na(kz.loLine)
line.set_x2(kz.loLine, bar_index)
if not na(kz.hiLbl)
label.set_x(kz.hiLbl, bar_index)
if not na(kz.loLbl)
label.set_x(kz.loLbl, bar_index)
monitoring = inSession or kz.barsSinceOpen <= fvgWaitBars
if kz.stage == "window open: watching sweep"
if monitoring
if not kz.sweptHi and not kz.sweptLo
if not na(kz.preHi) and high > kz.preHi
kz.sweptHi := true
kz.sweepExtreme := high
kz.dirBias := -1
kz.nSweeps += 1
tot.nSweeps += 1
tot.evSweep := true
if not na(kz.hiLine)
line.set_style(kz.hiLine, line.style_solid)
line.set_color(kz.hiLine, color.new(accCol, 25))
// Pill anchored at the sweep bar's wick tip (its own high),
// not at the window tag's position, so the two never stack.
pillHi = label.new(bar_index, high, "✕ swept", style = label.style_label_down, color = color.new(accCol, 25), textcolor = accCol, size = size.tiny)
array.push(aSweptPill, pillHi)
f_trimLabelArr(aSweptPill, keepLast * 3)
else if not na(kz.preLo) and low < kz.preLo
kz.sweptLo := true
kz.sweepExtreme := low
kz.dirBias := 1
kz.nSweeps += 1
tot.nSweeps += 1
tot.evSweep := true
if not na(kz.loLine)
line.set_style(kz.loLine, line.style_solid)
line.set_color(kz.loLine, color.new(accCol, 25))
pillLo = label.new(bar_index, low, "✕ swept", style = label.style_label_up, color = color.new(accCol, 25), textcolor = accCol, size = size.tiny)
array.push(aSweptPill, pillLo)
f_trimLabelArr(aSweptPill, keepLast * 3)
else
if kz.dirBias == 1 and low > high[2] and (low - high[2]) >= minFvgATR * atrVal
fvgTopV = low
fvgBotV = high[2]
if not na(fvgTopV) and not na(fvgBotV)
kz.fvgBot := fvgBotV
kz.fvgTop := fvgTopV
kz.fvgBarIdx := bar_index
kz.zoneBox := box.new(bar_index - 2, kz.fvgTop, bar_index, kz.fvgBot, border_color = accCol, border_width = 1, bgcolor = color.new(accCol, 80))
kz.fillBarsElapsed := 0
kz.entryBarIdx := na
kz.stage := "FVG formed: armed"
kz.nSetups += 1
tot.nSetups += 1
tot.evArmed := true
else if kz.dirBias == -1 and high < low[2] and (low[2] - high) >= minFvgATR * atrVal
fvgTopV = low[2]
fvgBotV = high
if not na(fvgTopV) and not na(fvgBotV)
kz.fvgTop := fvgTopV
kz.fvgBot := fvgBotV
kz.fvgBarIdx := bar_index
kz.zoneBox := box.new(bar_index - 2, kz.fvgTop, bar_index, kz.fvgBot, border_color = accCol, border_width = 1, bgcolor = color.new(accCol, 80))
kz.fillBarsElapsed := 0
kz.entryBarIdx := na
kz.stage := "FVG formed: armed"
kz.nSetups += 1
tot.nSetups += 1
tot.evArmed := true
else
// Window (plus grace period) closed without ever reaching the FVG
// stage. Only announce the outcome, and only keep BSL/SSL lines,
// when the user opted in via showNoSetup; otherwise a sweepless
// window fades to just its box, and a swept-but-no-FVG window
// simply stays quiet (its lines stay since it DID produce a sweep).
hadSweep = kz.sweptHi or kz.sweptLo
if showNoSetup
outcomeTxt = (not hadSweep) ? "· no sweep" : "· no FVG"
outcomeAnchor = kz.sweptHi ? kz.preHi : kz.sweptLo ? kz.preLo : kz.winHi
if not na(outcomeAnchor)
pillOut = label.new(bar_index, outcomeAnchor, outcomeTxt, style = label.style_label_down, color = color.new(muteCol, 70), textcolor = muteCol, size = size.tiny)
array.push(aOutcomePill, pillOut)
f_trimLabelArr(aOutcomePill, keepLast * 3)
else
if not hadSweep
if not na(kz.hiLine)
line.delete(kz.hiLine)
if not na(kz.loLine)
line.delete(kz.loLine)
if not na(kz.hiLbl)
label.delete(kz.hiLbl)
if not na(kz.loLbl)
label.delete(kz.loLbl)
if not na(kz.winBox)
box.set_bgcolor(kz.winBox, color.new(accCol, 92))
kz.stage := "waiting for window"
else if kz.stage == "FVG formed: armed"
if not na(kz.zoneBox)
box.set_right(kz.zoneBox, math.min(bar_index, kz.fvgBarIdx + 60))
if na(kz.entryBarIdx)
if kz.fillBarsElapsed >= 1 and low <= kz.fvgTop and high >= kz.fvgBot
trigPx = kz.dirBias == 1 ? low : high
entryPxV = math.abs(trigPx - kz.fvgTop) < math.abs(trigPx - kz.fvgBot) ? kz.fvgTop : kz.fvgBot
stopPxV = kz.sweepExtreme
if not na(entryPxV) and not na(stopPxV)
kz.entryPx := entryPxV
kz.stopPx := stopPxV
riskDist = math.abs(kz.entryPx - kz.stopPx)
kz.targetPx := kz.dirBias == 1 ? kz.entryPx + targetR * riskDist : kz.entryPx - targetR * riskDist
kz.entryBarIdx := bar_index
kz.nEntered += 1
tot.nEntered += 1
tot.evEntered := true
topR = kz.dirBias == 1 ? kz.entryPx : kz.stopPx
botR = kz.dirBias == 1 ? kz.stopPx : kz.entryPx
topW = kz.dirBias == 1 ? kz.targetPx : kz.entryPx
botW = kz.dirBias == 1 ? kz.entryPx : kz.targetPx
if not na(topR) and not na(botR)
kz.riskBox := box.new(bar_index, topR, bar_index, botR, border_color = color.new(warnCol, 40), border_width = 1, bgcolor = color.new(warnCol, 82))
if not na(topW) and not na(botW)
kz.rewardBox := box.new(bar_index, topW, bar_index, botW, border_color = color.new(kz.dirBias == 1 ? upCol : dnCol, 35), border_width = 1, bgcolor = color.new(kz.dirBias == 1 ? upCol : dnCol, 78))
else
kz.fillBarsElapsed += 1
if kz.fillBarsElapsed > fillWaitBars
if not na(kz.zoneBox)
box.set_right(kz.zoneBox, bar_index)
box.set_bgcolor(kz.zoneBox, color.new(muteCol, 90))
midPx = (kz.fvgTop + kz.fvgBot) / 2.0
if not na(midPx)
kz.resLbl := label.new(bar_index, midPx, "· no fill", style = label.style_label_left, color = color.new(muteCol, 35), textcolor = muteCol, size = lblSizeVal)
f_pushGroup(kz, keepLast, aZone, aRisk, aReward, aLabel)
kz.stage := "waiting for window"
kz.dirBias := 0
else
if not na(kz.riskBox)
box.set_right(kz.riskBox, bar_index)
if not na(kz.rewardBox)
box.set_right(kz.rewardBox, bar_index)
// stop is always checked before target: a bar touching both counts as a loss
stoppedNow = kz.dirBias == 1 ? low <= kz.stopPx : high >= kz.stopPx
reachedNow = kz.dirBias == 1 ? high >= kz.targetPx : low <= kz.targetPx
if stoppedNow
// Reward/risk zones always span at least 4 bars so they stay
// readable even when the setup resolves almost immediately;
// the result pill sits at the right edge, mid-height of the
// reward zone, instead of jumping down to the stop price.
finalRight = math.max(bar_index, kz.entryBarIdx + 4)
float rewardMid = na
if not na(kz.rewardBox)
rewardMid := (box.get_top(kz.rewardBox) + box.get_bottom(kz.rewardBox)) / 2.0
box.set_right(kz.rewardBox, finalRight)
box.set_bgcolor(kz.rewardBox, color.new(muteCol, 90))
if not na(kz.riskBox)
box.set_right(kz.riskBox, finalRight)
box.set_bgcolor(kz.riskBox, color.new(warnCol, 70))
if not na(kz.zoneBox)
box.set_right(kz.zoneBox, bar_index)
if not na(kz.stopPx) and not na(rewardMid)
kz.resLbl := label.new(finalRight, rewardMid, "✕ stop " + fmtPrice(kz.stopPx), style = label.style_label_left, color = color.new(warnCol, 15), textcolor = color.white, size = lblSizeVal)
kz.nStopped += 1
tot.nStopped += 1
tot.evStopped := true
f_pushGroup(kz, keepLast, aZone, aRisk, aReward, aLabel)
kz.stage := "invalidated ✕"
kz.dirBias := 0
else if reachedNow
finalRight = math.max(bar_index, kz.entryBarIdx + 4)
float rewardMid = na
if not na(kz.rewardBox)
rewardMid := (box.get_top(kz.rewardBox) + box.get_bottom(kz.rewardBox)) / 2.0
box.set_right(kz.rewardBox, finalRight)
box.set_bgcolor(kz.rewardBox, color.new(kz.dirBias == 1 ? upCol : dnCol, 55))
if not na(kz.riskBox)
box.set_right(kz.riskBox, finalRight)
box.set_bgcolor(kz.riskBox, color.new(muteCol, 90))
if not na(kz.zoneBox)
box.set_right(kz.zoneBox, bar_index)
if not na(kz.targetPx) and not na(rewardMid)
kz.resLbl := label.new(finalRight, rewardMid, "✓ " + str.tostring(targetR, "#.##") + "R " + fmtPrice(kz.targetPx), style = label.style_label_left, color = color.new(kz.dirBias == 1 ? upCol : dnCol, 15), textcolor = color.white, size = lblSizeVal)
kz.nReached1R += 1
tot.nReached1R += 1
tot.evReached := true
f_pushGroup(kz, keepLast, aZone, aRisk, aReward, aLabel)
kz.stage := "filled ✓"
kz.dirBias := 0
kz.wasInSession := inSession
// ─────────────────────────────────────────────────────────────────────────
// DRAWING (closed-bar decisions only; cosmetic extension happens inside)
// ─────────────────────────────────────────────────────────────────────────
if barstate.isconfirmed
tot.evSweep := false
tot.evArmed := false
tot.evEntered := false
tot.evReached := false
tot.evStopped := false
f_update(kz1, tot, in1, hiLB, loLB, lookback, minFvgATR, targetR, fvgWaitBars, fillWaitBars, keepLast, showNoSetup,
aZone, aRisk, aReward, aLabel,
aWinBox, aWinTag, aHiLine, aLoLine, aHiTag, aLoTag, aSweptPill, aOutcomePill,
ACC, UP, DN, WARN, MUTE, lSize, atr)
f_update(kz2, tot, in2, hiLB, loLB, lookback, minFvgATR, targetR, fvgWaitBars, fillWaitBars, keepLast, showNoSetup,
aZone, aRisk, aReward, aLabel,
aWinBox, aWinTag, aHiLine, aLoLine, aHiTag, aLoTag, aSweptPill, aOutcomePill,
ACC, UP, DN, WARN, MUTE, lSize, atr)
f_update(kz3, tot, in3, hiLB, loLB, lookback, minFvgATR, targetR, fvgWaitBars, fillWaitBars, keepLast, showNoSetup,
aZone, aRisk, aReward, aLabel,
aWinBox, aWinTag, aHiLine, aLoLine, aHiTag, aLoTag, aSweptPill, aOutcomePill,
ACC, UP, DN, WARN, MUTE, lSize, atr)
// ─────────────────────────────────────────────────────────────────────────
// PANEL (one strip of tiles: caption row + value row)
// ─────────────────────────────────────────────────────────────────────────
tile(table t, int c, string cap, string val, color vc) =>
table.cell(t, c, 0, cap, text_color = MUTE, text_size = size.small, bgcolor = PANEL)
table.cell(t, c, 1, val, text_color = vc, text_size = tSize, bgcolor = PANEL)
pos = switch panelPos
"Bottom left" => position.bottom_left
"Bottom right" => position.bottom_right
"Top centre" => position.top_center
"Top right" => position.top_right
=> position.bottom_center
var table tb = table.new(pos, 6, 2, bgcolor = NONE, border_width = 6, border_color = NONE, frame_width = 0)
if showPanel and barstate.islast
activeTag = in1 ? kz1.rangeTxt : in2 ? kz2.rangeTxt : in3 ? kz3.rangeTxt : "waiting"
activeStage = in1 ? kz1.stage : in2 ? kz2.stage : in3 ? kz3.stage : (kz1.stage != "waiting for window" ? kz1.stage : kz2.stage != "waiting for window" ? kz2.stage : kz3.stage)
resolved = tot.nReached1R + tot.nStopped
tile(tb, 0, "STAGE", activeStage, TXT)
tile(tb, 1, "WINDOW", activeTag, ACC)
tile(tb, 2, "SWEPT", str.tostring(tot.nSweeps), MUTE)
tile(tb, 3, "ENTERED", str.tostring(tot.nEntered), TXT)
tile(tb, 4, "REACHED 1R · " + str.tostring(resolved), pct(tot.nReached1R, resolved), ACC)
tile(tb, 5, "STOPPED", str.tostring(tot.nStopped), WARN)
// ─────────────────────────────────────────────────────────────────────────
// ALERTS (closed bars only)
// ─────────────────────────────────────────────────────────────────────────
if alOn and tot.evSweep
alert("Silver Bullet: liquidity sweep detected", alert.freq_once_per_bar_close)
if alOn and tot.evArmed
alert("Silver Bullet: FVG armed, entry zone formed", alert.freq_once_per_bar_close)
if alOn and tot.evEntered
alert("Silver Bullet: price traded into the entry zone", alert.freq_once_per_bar_close)
if alOn and tot.evReached
alert("Silver Bullet: target reached", alert.freq_once_per_bar_close)
if alOn and tot.evStopped
alert("Silver Bullet: setup invalidated by stop", alert.freq_once_per_bar_close)
alertcondition(tot.evSweep, "Liquidity sweep", "Silver Bullet: sweep of the pre-window level detected")
alertcondition(tot.evArmed, "FVG armed", "Silver Bullet: FVG entry zone formed inside the window")
alertcondition(tot.evEntered, "Entered FVG", "Silver Bullet: price traded back into the entry zone")
alertcondition(tot.evReached, "Target reached", "Silver Bullet: target reached")
alertcondition(tot.evStopped, "Stopped", "Silver Bullet: setup invalidated by stop")
// ─────────────────────────────────────────────────────────────────────────
// BRAND CANDLES (keep this block as it is)
// ─────────────────────────────────────────────────────────────────────────
edge = close >= open ? UP : DN
flat = brandCandles and not glowCandles
glow = brandCandles and glowCandles
third = (close - open) / 3.0
b1 = open + third
b2 = open + 2.0 * third
plotcandle(flat ? open : na, high, low, close, "Candles", color = color.new(edge, 25), wickcolor = color.new(edge, 15), bordercolor = edge, display = display.pane)
plotcandle(glow ? open : na, glow ? math.max(open, close) : na, glow ? math.min(open, close) : na, glow ? close : na, "Glow mask", color = chart.bg_color, wickcolor = NONE, bordercolor = chart.bg_color, display = display.pane)
plotcandle(glow ? open : na, glow ? math.max(open, b1) : na, glow ? math.min(open, b1) : na, glow ? b1 : na, "Glow band 1", color = color.new(edge, 72), wickcolor = NONE, bordercolor = NONE, display = display.pane)
plotcandle(glow ? b1 : na, glow ? math.max(b1, b2) : na, glow ? math.min(b1, b2) : na, glow ? b2 : na, "Glow band 2", color = color.new(edge, 44), wickcolor = NONE, bordercolor = NONE, display = display.pane)
plotcandle(glow ? b2 : na, glow ? math.max(b2, close) : na, glow ? math.min(b2, close) : na, glow ? close : na, "Glow band 3", color = color.new(edge, 8), wickcolor = NONE, bordercolor = NONE, display = display.pane)
plotcandle(glow ? open : na, glow ? high : na, glow ? low : na, glow ? close : na, "Glow wick", color = NONE, wickcolor = color.new(edge, 12), bordercolor = color.new(edge, 30), display = display.pane)