PROTECTED SOURCE SCRIPT
Liquidity Sweep Pro (HTF + Confirmation) — patched

How it works (in brief)
Bearish Sweep: High > (PDH/PWH + tolerance) and close < level, plus the selected confirmation.
Bullish Sweep: Low < (PDL/PWL − tolerance) and close > level, plus the selected confirmation.
Confirmation:
ATR: Candlestick range ≥ atrMult × ATR and candlestick direction matching.
MSS: Micro-structure shift: Bear → close below the most recent mini-low, Bull → close above the most recent mini-high.
ATR+MSS (default): both conditions must be met.
Optional session filter: Signals are only generated within the selected time period (exchange time period).
No repainting - no Lookahead: request.security(..., lookahead=barmerge.lookahead_off)[1]
No repainting - no intrabar flutter: Signals only at candle close via barstate.isconfirmed (own _close signals for plot & alerts)
Use Previous Day High/Low
Activates PDH/PDL (previous day's high/low) as external liquidity levels.
These values come from the previous day's completed candlestick (no lookahead).
Use Previous Week High/Low
Activates PWH/PWL (previous week's high/low) as additional, "heavier" liquidity levels.
Also from the previous week's completed candlestick (no lookahead).
Sweep Tolerance (Ticks)
"Safety margin" in ticks around one level to filter out micro-wicks/spread noise.
Internal: tickSize = syminfo.mintick * tickTol.
Guidelines:
FX (majors, H1–H4): 1–5 ticks
Indices (M5–H1): 1–3 ticks
CFDs/volatile/smaller TFs: 5–10 ticks
Crypto: 5–50 ticks depending on the symbol
Larger = stricter (fewer, cleaner sweeps).
ATR Length
Period for ATR (volatility measure). The standard 14 is acceptable; 10–20 depends on the instrument.
Displacement Factor
Minimum "power" of the sweep candle relative to the current ATR.
Internal: rangeRatio = (High–Low)/ATR and we check rangeRatio > atrMult.
Guidelines:
0.6–0.8 → sensitive (more signals)
0.9–1.2 → stricter (only strong candles)
Micro-Structure Shift Lookback
Depth for the MSS check (structural break in the sweep direction):
Bear sweep: close < lowest(low, mssLen)[1]
Bull sweep: close > highest(high, mssLen)[1]
This [1] ensures that we use the completed micro-structure as a reference (stable).
Guidelines: 3–8 (shorter = more, longer = stricter).
Confirmation Mode
None – only sweep at the level (wick back through the level + close).
ATR – sweep + candle must be "large enough" (rangeRatio > atrMult) and close appropriately (bearish/bullish).
MSS – Sweep + small structural break (MSS) in sweep direction.
ATR+MSS (recommended) – both conditions; very clean, but fewer signals.
Only trigger in session
Signals only within the specified session window.
Session Time (Exchange TZ)
Time window in the symbol's exchange time zone, not your local time.
FX/Indices: e.g., 8:00–17:00 (London/NY core time).
Crypto: often deactivated, as it operates 24/7.
Plot HTF Levels
Displays PDH/PDL/PWH/PWL as lines (for visual orientation).
Color Settings
PDH/PDL Color – Color of the daily levels.
PWH/PWL Color – Color of the weekly levels.
Bull/Bear Sweep Marker – Color of the sweep markers (shapes).
Best Practice Recommendations
Backtest setting: Alerts set to "Once per bar close" – your script will ultimately only generate bar close signals → 1:1 consistency.
Filter more strictly: Increase atrMult (e.g., 1.0–1.2) and mssLen 6–8.
More signals: atrMult 0.6–0.7, mssLen 3–4, but don't leave the tick tolerance too small (false sweeps!).
Instrument-specific:
FX H4/Session trading: Session on, tickTol 1–5, atrMult 0.8–1.0, mssLen 5–6.
Crypto: Session off, atrMult slightly higher (0.9–1.1), tickTol higher depending on the symbol.
Indices: Session on, tickTol 1–3, atrMult 0.8–1.0.
The additional filters
Min Body % / Max Wick %
filter out "pin candles" with a mini body and a large wick. These sweeps are often noise-oriented (stop clears without a real shift) → fewer false positives.
Min Close Distance from Level
requires that the closing price noticeably returns to the range. A close "close" to the level is often indecisive → even fewer false signals.
Bearish Sweep: High > (PDH/PWH + tolerance) and close < level, plus the selected confirmation.
Bullish Sweep: Low < (PDL/PWL − tolerance) and close > level, plus the selected confirmation.
Confirmation:
ATR: Candlestick range ≥ atrMult × ATR and candlestick direction matching.
MSS: Micro-structure shift: Bear → close below the most recent mini-low, Bull → close above the most recent mini-high.
ATR+MSS (default): both conditions must be met.
Optional session filter: Signals are only generated within the selected time period (exchange time period).
No repainting - no Lookahead: request.security(..., lookahead=barmerge.lookahead_off)[1]
No repainting - no intrabar flutter: Signals only at candle close via barstate.isconfirmed (own _close signals for plot & alerts)
Use Previous Day High/Low
Activates PDH/PDL (previous day's high/low) as external liquidity levels.
These values come from the previous day's completed candlestick (no lookahead).
Use Previous Week High/Low
Activates PWH/PWL (previous week's high/low) as additional, "heavier" liquidity levels.
Also from the previous week's completed candlestick (no lookahead).
Sweep Tolerance (Ticks)
"Safety margin" in ticks around one level to filter out micro-wicks/spread noise.
Internal: tickSize = syminfo.mintick * tickTol.
Guidelines:
FX (majors, H1–H4): 1–5 ticks
Indices (M5–H1): 1–3 ticks
CFDs/volatile/smaller TFs: 5–10 ticks
Crypto: 5–50 ticks depending on the symbol
Larger = stricter (fewer, cleaner sweeps).
ATR Length
Period for ATR (volatility measure). The standard 14 is acceptable; 10–20 depends on the instrument.
Displacement Factor
Minimum "power" of the sweep candle relative to the current ATR.
Internal: rangeRatio = (High–Low)/ATR and we check rangeRatio > atrMult.
Guidelines:
0.6–0.8 → sensitive (more signals)
0.9–1.2 → stricter (only strong candles)
Micro-Structure Shift Lookback
Depth for the MSS check (structural break in the sweep direction):
Bear sweep: close < lowest(low, mssLen)[1]
Bull sweep: close > highest(high, mssLen)[1]
This [1] ensures that we use the completed micro-structure as a reference (stable).
Guidelines: 3–8 (shorter = more, longer = stricter).
Confirmation Mode
None – only sweep at the level (wick back through the level + close).
ATR – sweep + candle must be "large enough" (rangeRatio > atrMult) and close appropriately (bearish/bullish).
MSS – Sweep + small structural break (MSS) in sweep direction.
ATR+MSS (recommended) – both conditions; very clean, but fewer signals.
Only trigger in session
Signals only within the specified session window.
Session Time (Exchange TZ)
Time window in the symbol's exchange time zone, not your local time.
FX/Indices: e.g., 8:00–17:00 (London/NY core time).
Crypto: often deactivated, as it operates 24/7.
Plot HTF Levels
Displays PDH/PDL/PWH/PWL as lines (for visual orientation).
Color Settings
PDH/PDL Color – Color of the daily levels.
PWH/PWL Color – Color of the weekly levels.
Bull/Bear Sweep Marker – Color of the sweep markers (shapes).
Best Practice Recommendations
Backtest setting: Alerts set to "Once per bar close" – your script will ultimately only generate bar close signals → 1:1 consistency.
Filter more strictly: Increase atrMult (e.g., 1.0–1.2) and mssLen 6–8.
More signals: atrMult 0.6–0.7, mssLen 3–4, but don't leave the tick tolerance too small (false sweeps!).
Instrument-specific:
FX H4/Session trading: Session on, tickTol 1–5, atrMult 0.8–1.0, mssLen 5–6.
Crypto: Session off, atrMult slightly higher (0.9–1.1), tickTol higher depending on the symbol.
Indices: Session on, tickTol 1–3, atrMult 0.8–1.0.
The additional filters
Min Body % / Max Wick %
filter out "pin candles" with a mini body and a large wick. These sweeps are often noise-oriented (stop clears without a real shift) → fewer false positives.
Min Close Distance from Level
requires that the closing price noticeably returns to the range. A close "close" to the level is often indecisive → even fewer false signals.
Script protetto
Questo script è pubblicato come codice protetto. Tuttavia, è possibile utilizzarlo liberamente e senza alcuna limitazione – per saperne di più clicca qui.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Script protetto
Questo script è pubblicato come codice protetto. Tuttavia, è possibile utilizzarlo liberamente e senza alcuna limitazione – per saperne di più clicca qui.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.