本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// Sweep Checklist
// Chart: only FRESH (untouched) HTF key levels are drawn, thin dotted lines. Swept / broken levels disappear from the chart
// but stay in the table (SWEPT, Broken, or Swept -> Broken).
// Levels: PDH/PDL, PWH/PWL, PMH/PML, Asia H/L, London H/L, and the 2 latest unmitigated HTF swing highs / lows.
// SWEPT = wick went through the level but the candle CLOSED back inside.
// BROKEN = a candle CLOSED beyond the level.
// "Candle" = a completed HTF candle (Confirmation timeframe, default 4H) when "Judge on HTF candle close" is ON,
// otherwise the chart bar. HTF judging = fewer, slower, stronger signals (alerts fire when the HTF candle closes).
// HTF zones (all from the HTF input, default 4H, judged on HTF closes):
// FVG = 3-candle imbalance, valid until an HTF close goes through it.
// IFVG = an FVG that an HTF close went through, flipped to the other side (bearish FVG closed above -> bullish IFVG, and vice versa).
// OB = last opposite candle before a displacement candle (body > mult x avg body) that closes beyond that candle's range.
// Checklist after a sweep:
// 1) Sweep of a level
// 2) Price tapped an unmitigated HTF zone (FVG / IFVG / OB) on the same side
// 3) LTF shift: a chart-TF close beyond the last swing (before the sweep) in the opposite direction,
// by a displacement candle (body > mult x avg body) when that option is on
// No sweep = NO TRADE. A setup is INVALIDATED when: the swept level is later BROKEN (a close beyond it),
// price closes beyond the sweep extreme, or it expires after N bars.
// No S&R zones yet. Not financial advice.
indicator("Sweep Checklist", shorttitle="SweepCL", overlay=true, max_lines_count=300, max_labels_count=400, max_boxes_count=100)
// ===== Inputs =====
tz = input.string("America/New_York", "Session timezone", group="Sessions")
asiaSess = input.session("2000-0200", "Asia", group="Sessions")
lonSess = input.session("0200-0500", "London", group="Sessions")
useD = input.bool(true, "Prev Day H/L (PDH/PDL)", group="Levels")
useW = input.bool(true, "Prev Week H/L (PWH/PWL)", group="Levels")
useM = input.bool(true, "Prev Month H/L (PMH/PML)", group="Levels")
useAsia = input.bool(true, "Asia H/L", group="Levels")
useLon = input.bool(true, "London H/L", group="Levels")
useSw = input.bool(true, "HTF swing highs/lows (2 latest fresh each)", group="Levels")
swLen = input.int(3, "HTF swing length", minval=1, group="Levels")
htfTf = input.timeframe("240", "HTF for zones + swings", group="Zones")
useFvg = input.bool(true, "FVG (IFVG needs this on)", group="Zones")
useIfvg = input.bool(true, "IFVG", group="Zones")
useOb = input.bool(true, "Order blocks", group="Zones")
obMult = input.float(1.5, "OB displacement: body > x avg body", minval=0.5, step=0.1, group="Zones")
maxAge = input.int(30, "Setup valid for N bars after sweep", minval=3, group="Checklist")
pivLen = input.int(3, "Swing length for shift (chart TF)", minval=1, group="Checklist")
htfJudge = input.bool(true, "Judge sweeps/breaks on HTF candle close", tooltip="ON: a level is SWEPT only if a completed HTF candle wicked through it and closed back inside, and BROKEN only if a completed HTF candle closed beyond it. Slower (signals at HTF close) but stronger rejection. OFF: judged on every chart bar close.", group="Confirmation")
judgeTf = input.timeframe("240", "Confirmation timeframe", group="Confirmation")
reqDisp = input.bool(true, "LTF shift needs displacement", tooltip="The bar that breaks the swing must be a strong candle in the shift direction: body bigger than (multiplier x average body of the last 20 chart bars).", group="Checklist")
dispMult = input.float(1.2, "Displacement: body > x avg body", minval=0.5, step=0.1, group="Checklist")
onlyFresh = input.bool(true, "Chart: show only fresh levels", group="Display")
showLines = input.bool(true, "Draw level lines", group="Display")
showZones = input.bool(true, "Draw HTF zone boxes", group="Display")
showTable = input.bool(true, "Show checklist table", group="Display")
alSweep = input.bool(true, "Alert: level swept (at bar close)", group="Alerts")
alBreak = input.bool(true, "Alert: level broken (at bar close)", group="Alerts")
alReady = input.bool(true, "Alert: checklist 3/3 ready", group="Alerts")
tblPos = input.string("Top right", "Table position", options=["Top right", "Top left", "Bottom right", "Bottom left"], group="Display")
if timeframe.in_seconds(htfTf) < timeframe.in_seconds(timeframe.period)
runtime.error("HTF must be equal or higher than the chart timeframe")
if htfJudge and timeframe.in_seconds(judgeTf) < timeframe.in_seconds(timeframe.period)
runtime.error("Confirmation timeframe must be equal or higher than the chart timeframe")
pos = switch tblPos
"Top left" => position.top_left
"Bottom right" => position.bottom_right
"Bottom left" => position.bottom_left
=> position.top_right
// ===== Helpers =====
f_sess(string s) =>
var float runHi = na
var float runLo = na
var float dHi = na
var float dLo = na
inS = not na(time(timeframe.period, s, tz))
started = inS and not inS[1]
ended = not inS and inS[1]
if started
runHi := high
runLo := low
else if inS
runHi := math.max(runHi, high)
runLo := math.min(runLo, low)
if ended
dHi := runHi
dLo := runLo
[dHi, dLo]
// last completed HTF bar: FVG, order block, close, time
f_htf(float mult) =>
body = math.abs(close - open)
avg = ta.sma(body, 20)
d1 = body[1]
a2 = avg[2]
fb = high[1] < low[3]
fu = low[1] > high[3]
obU = close[2] < open[2] and close[1] > open[1] and d1 > mult * a2 and close[1] > high[2]
obB = close[2] > open[2] and close[1] < open[1] and d1 > mult * a2 and close[1] < low[2]
[fb ? 1.0 : 0.0, low[3], high[1], fu ? 1.0 : 0.0, low[1], high[3], obB ? 1.0 : 0.0, high[2], low[2], obU ? 1.0 : 0.0, high[2], low[2], close[1], time[1]]
f_piv(int len) =>
a = ta.pivothigh(high, len, len)
b = ta.pivotlow(low, len, len)
[a[1], b[1], time[len + 1]]
cSell(string k) =>
k == "FVG" ? color.new(color.red, 93) : k == "OB" ? color.new(color.maroon, 82) : color.new(color.orange, 90)
cBuy(string k) =>
k == "FVG" ? color.new(color.green, 93) : k == "OB" ? color.new(color.teal, 82) : color.new(color.blue, 90)
f_box(int t, float top, float bot, color c) =>
box b = na
if showZones
b := box.new(t, top, t, bot, xloc=xloc.bar_time, extend=extend.right, border_color=na, bgcolor=c)
b
f_push(array<float> aT, array<float> aB, array<box> aX, array<string> aK, float top, float bot, string kind, int t, color c) =>
aT.push(top)
aB.push(bot)
aX.push(f_box(t, top, bot, c))
aK.push(kind)
if aT.size() > 10
ox = aX.shift()
if not na(ox)
ox.delete()
aT.shift()
aB.shift()
aK.shift()
// ===== Data =====
[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)
[pmH, pmL] = request.security(syminfo.tickerid, "M", [high[1], low[1]], lookahead=barmerge.lookahead_on)
[asH, asL] = f_sess(asiaSess)
[loH, loL] = f_sess(lonSess)
[fb, fbT, fbB, fu, fuT, fuB, obB, obBT, obBB, obU, obUT, obUB, hC, hT] = request.security(syminfo.tickerid, htfTf, f_htf(obMult), lookahead=barmerge.lookahead_on)
[sph, spl, spt] = request.security(syminfo.tickerid, htfTf, f_piv(swLen), lookahead=barmerge.lookahead_on)
[jH, jL, jC, jT] = request.security(syminfo.tickerid, judgeTf, [high[1], low[1], close[1], time[1]], lookahead=barmerge.lookahead_on)
ph = ta.pivothigh(high, pivLen, pivLen)
pl = ta.pivotlow(low, pivLen, pivLen)
var float lastPH = na
var float lastPL = na
if not na(ph)
lastPH := ph
if not na(pl)
lastPL := pl
avgBody = ta.sma(math.abs(close - open), 20)
// ===== State =====
// slots: 0 PDH 1 PDL 2 PWH 3 PWL 4 PMH 5 PML 6 AsiaH 7 AsiaL 8 LonH 9 LonL 10 SwH 11 SwL 12 SwH2 13 SwL2 (even = high side)
var names = array.from("PDH", "PDL", "PWH", "PWL", "PMH", "PML", "Asia H", "Asia L", "London H", "London L", "HTF SwH", "HTF SwL", "HTF SwH2", "HTF SwL2")
var cols = array.from(color.orange, color.orange, color.purple, color.purple, color.fuchsia, color.fuchsia, color.yellow, color.yellow, color.teal, color.teal, color.aqua, color.aqua, color.aqua, color.aqua)
var lv = array.new<float>(14, na)
var st = array.new<int>(14, 0) // 0 fresh, 1 swept, 2 broken, 3 swept then broken
var lns = array.new<line>(14)
var lbs = array.new<label>(14)
// sell-side zones (bearish FVG / OB, IFVG from broken bullish FVG) and buy-side zones
var bearT = array.new<float>()
var bearB = array.new<float>()
var bearX = array.new<box>()
var bearK = array.new<string>()
var bullT = array.new<float>()
var bullB = array.new<float>()
var bullX = array.new<box>()
var bullK = array.new<string>()
var int lastHT = na
var swHi = array.new<float>()
var swLo = array.new<float>()
var int lastPhT = na
var int lastPlT = na
var int lastJT = na
var float plSnap = na
var float phSnap = na
var lvBar = array.new<int>(14, -1)
var bool sellOn = false
var string sellNm = ""
var string sellZk = ""
var float sellExt = na
var int sellBar = 0
var int sellSlot = -1
var bool sellZn = false
var bool sellMss = false
var float sellMssLvl = na
var bool sellRdy = false
var bool buyOn = false
var string buyNm = ""
var string buyZk = ""
var float buyExt = na
var int buyBar = 0
var int buySlot = -1
var bool buyZn = false
var bool buyMss = false
var float buyMssLvl = na
var bool buyRdy = false
// ===== Logic (confirmed bars only) =====
if barstate.isconfirmed
// 0) new HTF swings
if not na(sph) and not na(spt) and (na(lastPhT) or spt != lastPhT)
lastPhT := spt
swHi.push(sph)
if swHi.size() > 6
swHi.shift()
if not na(spl) and not na(spt) and (na(lastPlT) or spt != lastPlT)
lastPlT := spt
swLo.push(spl)
if swLo.size() > 6
swLo.shift()
// 1) level updates (new level -> reset state, redraw)
sh1 = useSw and swHi.size() > 0 ? swHi.get(swHi.size() - 1) : na
sl1 = useSw and swLo.size() > 0 ? swLo.get(swLo.size() - 1) : na
sh2 = useSw and swHi.size() > 1 ? swHi.get(swHi.size() - 2) : na
sl2 = useSw and swLo.size() > 1 ? swLo.get(swLo.size() - 2) : na
newVals = array.from(useD ? pdH : na, useD ? pdL : na, useW ? pwH : na, useW ? pwL : na, useM ? pmH : na, useM ? pmL : na, useAsia ? asH : na, useAsia ? asL : na, useLon ? loH : na, useLon ? loL : na, sh1, sl1, sh2, sl2)
for i = 0 to 13
nv = newVals.get(i)
ov = lv.get(i)
if not na(nv) and (na(ov) or nv != ov)
lv.set(i, nv)
lvBar.set(i, bar_index)
st.set(i, 0)
if showLines
ol = lns.get(i)
if not na(ol)
ol.delete()
ob = lbs.get(i)
if not na(ob)
ob.delete()
lns.set(i, line.new(bar_index, nv, bar_index + 1, nv, extend=extend.right, color=color.new(cols.get(i), 60), style=line.style_dotted, width=1))
lbs.set(i, label.new(bar_index, nv, "", style=label.style_label_left, color=color.new(color.black, 100), textcolor=color.new(cols.get(i), 35), size=size.tiny))
// 2) HTF zones: only on a new completed HTF bar
if not na(hT) and (na(lastHT) or hT != lastHT)
lastHT := hT
// a) mitigate / invert existing zones with this HTF close
if bearT.size() > 0
for j = bearT.size() - 1 to 0
if hC > bearT.get(j)
k = bearK.get(j)
tp = bearT.get(j)
bt = bearB.get(j)
bx = bearX.get(j)
if not na(bx)
bx.delete()
bearT.remove(j)
bearB.remove(j)
bearX.remove(j)
bearK.remove(j)
if k == "FVG" and useIfvg
f_push(bullT, bullB, bullX, bullK, tp, bt, "IFVG", hT, cBuy("IFVG"))
if bullT.size() > 0
for j = bullT.size() - 1 to 0
if hC < bullB.get(j)
k = bullK.get(j)
tp = bullT.get(j)
bt = bullB.get(j)
bx = bullX.get(j)
if not na(bx)
bx.delete()
bullT.remove(j)
bullB.remove(j)
bullX.remove(j)
bullK.remove(j)
if k == "FVG" and useIfvg
f_push(bearT, bearB, bearX, bearK, tp, bt, "IFVG", hT, cSell("IFVG"))
// b) add zones formed by this HTF bar
if useFvg and fb == 1.0
f_push(bearT, bearB, bearX, bearK, fbT, fbB, "FVG", hT, cSell("FVG"))
if useFvg and fu == 1.0
f_push(bullT, bullB, bullX, bullK, fuT, fuB, "FVG", hT, cBuy("FVG"))
if useOb and obB == 1.0
f_push(bearT, bearB, bearX, bearK, obBT, obBB, "OB", hT, cSell("OB"))
if useOb and obU == 1.0
f_push(bullT, bullB, bullX, bullK, obUT, obUB, "OB", hT, cBuy("OB"))
// 3) sweep / break detection (on a completed HTF candle, or on the chart bar if HTF judging is off)
newJ = not na(jT) and (na(lastJT) or jT != lastJT)
evalNow = htfJudge ? newJ : true
eH = htfJudge ? jH : high
eL = htfJudge ? jL : low
eC = htfJudge ? jC : close
for i = 0 to 13
L = lv.get(i)
s = st.get(i)
if evalNow and not na(L) and s < 2 and lvBar.get(i) < bar_index
isH = i % 2 == 0
swept = isH ? (s == 0 and eH > L and eC < L) : (s == 0 and eL < L and eC > L)
broke = isH ? eC > L : eC < L
if swept or broke
if swept
st.set(i, 1)
nm = names.get(i)
if isH
sellOn := true
sellNm := nm
sellSlot := i
sellZk := ""
sellExt := eH
sellBar := bar_index
sellZn := false
sellMss := false
sellMssLvl := htfJudge ? plSnap : lastPL
sellRdy := false
else
buyOn := true
buyNm := nm
buySlot := i
buyZk := ""
buyExt := eL
buyBar := bar_index
buyZn := false
buyMss := false
buyMssLvl := htfJudge ? phSnap : lastPH
buyRdy := false
label.new(bar_index, isH ? eH : eL, "", style=isH ? label.style_label_down : label.style_label_up, color=color.new(color.orange, 30), size=size.tiny)
// HTF judging: the sweep wick itself must have tapped a zone on that side
if htfJudge
if isH and bearT.size() > 0
for j = 0 to bearT.size() - 1
if not sellZn and bearB.get(j) <= eH and bearT.get(j) >= L
sellZn := true
sellZk := bearK.get(j)
if not isH and bullT.size() > 0
for j = 0 to bullT.size() - 1
if not buyZn and bullB.get(j) <= L and bullT.get(j) >= eL
buyZn := true
buyZk := bullK.get(j)
if alSweep
alert(syminfo.tickerid + " " + timeframe.period + ": " + nm + " SWEPT @ " + str.tostring(L, format.mintick) + (isH ? " (sell side)" : " (buy side)"), alert.freq_once_per_bar_close)
else
st.set(i, s == 1 ? 3 : 2)
// swept level got broken -> the sweep failed, price continued: invalidate that setup
bool killed = false
if s == 1 and isH and sellOn and sellSlot == i
sellOn := false
killed := true
if s == 1 and not isH and buyOn and buySlot == i
buyOn := false
killed := true
if alBreak
alert(syminfo.tickerid + " " + timeframe.period + ": " + names.get(i) + " BROKEN @ " + str.tostring(L, format.mintick) + (s == 1 ? " (was swept earlier)" : "") + (killed ? " - " + (isH ? "SELL" : "BUY") + " setup INVALID" : ""), alert.freq_once_per_bar_close)
if onlyFresh
ol = lns.get(i)
if not na(ol)
ol.delete()
lns.set(i, na)
ob = lbs.get(i)
if not na(ob)
ob.delete()
lbs.set(i, na)
if htfJudge and newJ
lastJT := jT
plSnap := lastPL // swing before the next HTF candle starts = reference for the LTF shift
phSnap := lastPH
// 4) sell setup (after a high was swept)
if sellOn
if not sellZn and bearT.size() > 0
for j = 0 to bearT.size() - 1
if not sellZn and high >= bearB.get(j) and low <= bearT.get(j)
sellZn := true
sellZk := bearK.get(j)
if not sellMss and bar_index > sellBar and not na(sellMssLvl) and close < sellMssLvl and (not reqDisp or (close < open and math.abs(close - open) > dispMult * avgBody[1]))
sellMss := true
if bar_index > sellBar and close > sellExt
sellOn := false
if bar_index - sellBar > maxAge
sellOn := false
// 5) buy setup (after a low was swept)
if buyOn
if not buyZn and bullT.size() > 0
for j = 0 to bullT.size() - 1
if not buyZn and high >= bullB.get(j) and low <= bullT.get(j)
buyZn := true
buyZk := bullK.get(j)
if not buyMss and bar_index > buyBar and not na(buyMssLvl) and close > buyMssLvl and (not reqDisp or (close > open and math.abs(close - open) > dispMult * avgBody[1]))
buyMss := true
if bar_index > buyBar and close < buyExt
buyOn := false
if bar_index - buyBar > maxAge
buyOn := false
// 6) HTF swing mitigation (any touch)
if swHi.size() > 0
for j = swHi.size() - 1 to 0
if high > swHi.get(j)
swHi.remove(j)
if swLo.size() > 0
for j = swLo.size() - 1 to 0
if low < swLo.get(j)
swLo.remove(j)
// 7) ready alerts
sellReady = sellOn and sellZn and sellMss
if sellReady != sellRdy
sellRdy := sellReady
if sellReady and alReady
alert(syminfo.tickerid + ": SELL checklist 3/3 (" + sellNm + " swept, " + sellZk + " tapped)", alert.freq_once_per_bar_close)
buyReady = buyOn and buyZn and buyMss
if buyReady != buyRdy
buyRdy := buyReady
if buyReady and alReady
alert(syminfo.tickerid + ": BUY checklist 3/3 (" + buyNm + " swept, " + buyZk + " tapped)", alert.freq_once_per_bar_close)
// ===== Right-side labels + dashboard =====
var table tbl = table.new(pos, 3, 21, bgcolor=color.new(color.black, 15), border_width=1, border_color=color.new(color.gray, 60))
if barstate.islast
for i = 0 to 13
L = lv.get(i)
lb = lbs.get(i)
if showLines and not na(L) and not na(lb)
s = st.get(i)
lb.set_xy(bar_index + 2, L)
lb.set_text(names.get(i) + (s == 1 ? " ✓" : s == 2 ? " ✗" : s == 3 ? " ✓✗" : ""))
if showTable
tbl.clear(0, 0, 2, 20)
tbl.cell(0, 0, "Level", text_color=color.white, text_size=size.small, bgcolor=color.new(color.gray, 60))
tbl.cell(1, 0, "Price", text_color=color.white, text_size=size.small, bgcolor=color.new(color.gray, 60))
tbl.cell(2, 0, "Status", text_color=color.white, text_size=size.small, bgcolor=color.new(color.gray, 60))
int r = 1
for i = 0 to 13
L = lv.get(i)
if not na(L)
s = st.get(i)
sTxt = s == 0 ? "Fresh" : s == 1 ? "SWEPT ✓" : s == 2 ? "Broken ✗" : "Swept → Broken ✗"
sCol = s == 0 ? color.silver : s == 1 ? color.orange : s == 2 ? color.red : color.new(color.red, 20)
tbl.cell(0, r, names.get(i), text_color=cols.get(i), text_size=size.small, text_halign=text.align_left)
tbl.cell(1, r, str.tostring(L, format.mintick), text_color=color.white, text_size=size.small)
tbl.cell(2, r, sTxt, text_color=sCol, text_size=size.small)
r += 1
tbl.cell(0, r, "Checklist", text_color=color.white, text_size=size.small, bgcolor=color.new(color.gray, 60))
tbl.cell(1, r, "SELL (high swept)", text_color=color.white, text_size=size.small, bgcolor=color.new(color.red, 60))
tbl.cell(2, r, "BUY (low swept)", text_color=color.white, text_size=size.small, bgcolor=color.new(color.green, 60))
sSw = sellOn ? "✓ " + sellNm + " (" + str.tostring(bar_index - sellBar) + "b)" : "✗"
bSw = buyOn ? "✓ " + buyNm + " (" + str.tostring(bar_index - buyBar) + "b)" : "✗"
tbl.cell(0, r + 1, "1 Sweep", text_color=color.white, text_size=size.small, text_halign=text.align_left)
tbl.cell(1, r + 1, sSw, text_color=sellOn ? color.lime : color.gray, text_size=size.small)
tbl.cell(2, r + 1, bSw, text_color=buyOn ? color.lime : color.gray, text_size=size.small)
tbl.cell(0, r + 2, "2 HTF zone tap", text_color=color.white, text_size=size.small, text_halign=text.align_left)
tbl.cell(1, r + 2, not sellOn ? "–" : sellZn ? "✓ " + sellZk : "✗", text_color=sellZn ? color.lime : color.gray, text_size=size.small)
tbl.cell(2, r + 2, not buyOn ? "–" : buyZn ? "✓ " + buyZk : "✗", text_color=buyZn ? color.lime : color.gray, text_size=size.small)
tbl.cell(0, r + 3, "3 LTF shift", text_color=color.white, text_size=size.small, text_halign=text.align_left)
tbl.cell(1, r + 3, not sellOn ? "–" : sellMss ? "✓" : "✗", text_color=sellMss ? color.lime : color.gray, text_size=size.small)
tbl.cell(2, r + 3, not buyOn ? "–" : buyMss ? "✓" : "✗", text_color=buyMss ? color.lime : color.gray, text_size=size.small)
sV = not sellOn ? "NO SWEEP = NO TRADE" : (sellZn and sellMss) ? "READY 3/3" : str.tostring(1 + (sellZn ? 1 : 0) + (sellMss ? 1 : 0)) + "/3 wait"
bV = not buyOn ? "NO SWEEP = NO TRADE" : (buyZn and buyMss) ? "READY 3/3" : str.tostring(1 + (buyZn ? 1 : 0) + (buyMss ? 1 : 0)) + "/3 wait"
tbl.cell(0, r + 4, "Verdict", text_color=color.white, text_size=size.small, text_halign=text.align_left)
tbl.cell(1, r + 4, sV, text_color=not sellOn ? color.gray : (sellZn and sellMss) ? color.lime : color.orange, text_size=size.small)
tbl.cell(2, r + 4, bV, text_color=not buyOn ? color.gray : (buyZn and buyMss) ? color.lime : color.orange, text_size=size.small)