OPEN-SOURCE SCRIPT
Institutional Reload Zones

//version=5
indicator("MSS Institutional Reload Zones (HTF + Sweep + Displacement) [Stable]", overlay=true, max_boxes_count=20, max_labels_count=50)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Inputs
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
pivotLeft = input.int(3, "Pivot Left", minval=1)
pivotRight = input.int(3, "Pivot Right", minval=1)
htfTf = input.timeframe("60", "HTF Timeframe (60=1H, 240=4H)")
emaFastLen = input.int(50, "HTF EMA Fast", minval=1)
emaSlowLen = input.int(200, "HTF EMA Slow", minval=1)
atrLen = input.int(14, "ATR Length", minval=1)
dispMult = input.float(1.2, "Displacement ATR Mult", minval=0.5, step=0.1)
closeTopPct = input.float(0.25, "Close within top %", minval=0.05, maxval=0.5, step=0.05)
sweepLookbackBars = input.int(60, "Sweep lookback (bars)", minval=10, maxval=500)
sweepValidBars = input.int(30, "Sweep active for N bars", minval=5, maxval=200)
cooldownBars = input.int(30, "Signal cooldown (bars)", minval=0, maxval=300)
extendBars = input.int(200, "Extend zones (bars)", minval=20)
showOB = input.bool(true, "Show Pullback OB zone")
showFib = input.bool(true, "Show 50-61.8% zone")
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// HTF trend filter
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
htfClose = request.security(syminfo.tickerid, htfTf, close)
htfEmaFast = request.security(syminfo.tickerid, htfTf, ta.ema(close, emaFastLen))
htfEmaSlow = request.security(syminfo.tickerid, htfTf, ta.ema(close, emaSlowLen))
htfBull = (htfEmaFast > htfEmaSlow) and (htfClose >= htfEmaFast)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// LTF structure pivots
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
atr = ta.atr(atrLen)
ph = ta.pivothigh(high, pivotLeft, pivotRight)
pl = ta.pivotlow(low, pivotLeft, pivotRight)
var float lastSwingHigh = na
var float lastSwingLow = na
if not na(ph)
lastSwingHigh := ph
if not na(pl)
lastSwingLow := pl
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Sweep filter (simple + robust)
// “sweep” = breaks below lowest low of last N bars and reclaims (close back above that level)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
sweepLevel = ta.lowest(low, sweepLookbackBars)[1]
sweepNow = (low < sweepLevel) and (close > sweepLevel)
var int sweepUntil = na
if sweepNow
sweepUntil := bar_index + sweepValidBars
sweepActive = not na(sweepUntil) and (bar_index <= sweepUntil)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Displacement filter
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
cRange = high - low
closeTopOk = close >= (high - cRange * closeTopPct)
dispOk = (cRange >= atr * dispMult) and closeTopOk and (close > open)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// MSS bullish (filtered)
// base MSS: close crosses above last swing high
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
baseMssBull = (not na(lastSwingHigh)) and ta.crossover(close, lastSwingHigh)
var int lastSignalBar = na
cooldownOk = na(lastSignalBar) ? true : (bar_index - lastSignalBar >= cooldownBars)
mssBull = baseMssBull and htfBull and sweepActive and dispOk and cooldownOk
if mssBull
lastSignalBar := bar_index
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Find last bearish candle before MSS for OB zone
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
f_lastBearish(_lookback) =>
float obH = na
float obL = na
int found = 0
for i = 1 to _lookback
if found == 0 and close < open
obH := high
obL := low
found := 1
[obH, obL]
[obHigh, obLow] = f_lastBearish(30)
// Impulse anchors for fib zone (use lastSwingLow to current high on MSS bar)
impLow = lastSwingLow
impHigh = high
fib50 = (not na(impLow)) ? (impLow + (impHigh - impLow) * 0.50) : na
fib618 = (not na(impLow)) ? (impLow + (impHigh - impLow) * 0.618) : na
fibTop = (not na(fib50) and not na(fib618)) ? math.max(fib50, fib618) : na
fibBot = (not na(fib50) and not na(fib618)) ? math.min(fib50, fib618) : na
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Boxes (delete previous, draw new) — SINGLE LINE calls only
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var box obBox = na
var box fibBox = na
if mssBull
if showOB and not na(obHigh) and not na(obLow)
if not na(obBox)
box.delete(obBox)
obBox := box.new(left=bar_index, top=obHigh, right=bar_index + extendBars, bottom=obLow, bgcolor=color.new(color.gray, 82), border_color=color.new(color.gray, 30))
if showFib and not na(fibTop) and not na(fibBot)
if not na(fibBox)
box.delete(fibBox)
fibBox := box.new(left=bar_index, top=fibTop, right=bar_index + extendBars, bottom=fibBot, bgcolor=color.new(color.teal, 85), border_color=color.new(color.teal, 35))
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Visuals
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
plotshape(mssBull, title="MSS Bull (Filtered)", style=shape.labelup, text="MSS✔", size=size.tiny, color=color.new(color.green, 0), textcolor=color.white, location=location.belowbar)
plot(htfEmaFast, title="HTF EMA Fast", color=color.new(color.orange, 80))
plot(htfEmaSlow, title="HTF EMA Slow", color=color.new(color.purple, 80))
indicator("MSS Institutional Reload Zones (HTF + Sweep + Displacement) [Stable]", overlay=true, max_boxes_count=20, max_labels_count=50)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Inputs
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
pivotLeft = input.int(3, "Pivot Left", minval=1)
pivotRight = input.int(3, "Pivot Right", minval=1)
htfTf = input.timeframe("60", "HTF Timeframe (60=1H, 240=4H)")
emaFastLen = input.int(50, "HTF EMA Fast", minval=1)
emaSlowLen = input.int(200, "HTF EMA Slow", minval=1)
atrLen = input.int(14, "ATR Length", minval=1)
dispMult = input.float(1.2, "Displacement ATR Mult", minval=0.5, step=0.1)
closeTopPct = input.float(0.25, "Close within top %", minval=0.05, maxval=0.5, step=0.05)
sweepLookbackBars = input.int(60, "Sweep lookback (bars)", minval=10, maxval=500)
sweepValidBars = input.int(30, "Sweep active for N bars", minval=5, maxval=200)
cooldownBars = input.int(30, "Signal cooldown (bars)", minval=0, maxval=300)
extendBars = input.int(200, "Extend zones (bars)", minval=20)
showOB = input.bool(true, "Show Pullback OB zone")
showFib = input.bool(true, "Show 50-61.8% zone")
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// HTF trend filter
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
htfClose = request.security(syminfo.tickerid, htfTf, close)
htfEmaFast = request.security(syminfo.tickerid, htfTf, ta.ema(close, emaFastLen))
htfEmaSlow = request.security(syminfo.tickerid, htfTf, ta.ema(close, emaSlowLen))
htfBull = (htfEmaFast > htfEmaSlow) and (htfClose >= htfEmaFast)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// LTF structure pivots
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
atr = ta.atr(atrLen)
ph = ta.pivothigh(high, pivotLeft, pivotRight)
pl = ta.pivotlow(low, pivotLeft, pivotRight)
var float lastSwingHigh = na
var float lastSwingLow = na
if not na(ph)
lastSwingHigh := ph
if not na(pl)
lastSwingLow := pl
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Sweep filter (simple + robust)
// “sweep” = breaks below lowest low of last N bars and reclaims (close back above that level)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
sweepLevel = ta.lowest(low, sweepLookbackBars)[1]
sweepNow = (low < sweepLevel) and (close > sweepLevel)
var int sweepUntil = na
if sweepNow
sweepUntil := bar_index + sweepValidBars
sweepActive = not na(sweepUntil) and (bar_index <= sweepUntil)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Displacement filter
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
cRange = high - low
closeTopOk = close >= (high - cRange * closeTopPct)
dispOk = (cRange >= atr * dispMult) and closeTopOk and (close > open)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// MSS bullish (filtered)
// base MSS: close crosses above last swing high
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
baseMssBull = (not na(lastSwingHigh)) and ta.crossover(close, lastSwingHigh)
var int lastSignalBar = na
cooldownOk = na(lastSignalBar) ? true : (bar_index - lastSignalBar >= cooldownBars)
mssBull = baseMssBull and htfBull and sweepActive and dispOk and cooldownOk
if mssBull
lastSignalBar := bar_index
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Find last bearish candle before MSS for OB zone
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
f_lastBearish(_lookback) =>
float obH = na
float obL = na
int found = 0
for i = 1 to _lookback
if found == 0 and close < open
obH := high
obL := low
found := 1
[obH, obL]
[obHigh, obLow] = f_lastBearish(30)
// Impulse anchors for fib zone (use lastSwingLow to current high on MSS bar)
impLow = lastSwingLow
impHigh = high
fib50 = (not na(impLow)) ? (impLow + (impHigh - impLow) * 0.50) : na
fib618 = (not na(impLow)) ? (impLow + (impHigh - impLow) * 0.618) : na
fibTop = (not na(fib50) and not na(fib618)) ? math.max(fib50, fib618) : na
fibBot = (not na(fib50) and not na(fib618)) ? math.min(fib50, fib618) : na
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Boxes (delete previous, draw new) — SINGLE LINE calls only
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var box obBox = na
var box fibBox = na
if mssBull
if showOB and not na(obHigh) and not na(obLow)
if not na(obBox)
box.delete(obBox)
obBox := box.new(left=bar_index, top=obHigh, right=bar_index + extendBars, bottom=obLow, bgcolor=color.new(color.gray, 82), border_color=color.new(color.gray, 30))
if showFib and not na(fibTop) and not na(fibBot)
if not na(fibBox)
box.delete(fibBox)
fibBox := box.new(left=bar_index, top=fibTop, right=bar_index + extendBars, bottom=fibBot, bgcolor=color.new(color.teal, 85), border_color=color.new(color.teal, 35))
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Visuals
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
plotshape(mssBull, title="MSS Bull (Filtered)", style=shape.labelup, text="MSS✔", size=size.tiny, color=color.new(color.green, 0), textcolor=color.white, location=location.belowbar)
plot(htfEmaFast, title="HTF EMA Fast", color=color.new(color.orange, 80))
plot(htfEmaSlow, title="HTF EMA Slow", color=color.new(color.purple, 80))
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.