OPEN-SOURCE SCRIPT
Liquidity Sweep Intelligence - ML Post-Sweep [Dots3Red]

█ LIQUIDITY SWEEP INTELLIGENCE — KNN POST-SWEEP [Dots3Red]
Usually, a liquidity indicator shows where the price is likely to go to take liquidity. This one tells you what tends to happen after it gets there.
When price sweeps a swing high or low — triggering the stop orders sitting there — we face the immediate question: does it reverse (a stop hunt, fade the move) or does it continue (a genuine breakout)? The answer depends on context. This script tracks every historical sweep on your chart, records the contextual features at the moment it happened, and uses a KNN (K-Nearest Neighbors) model to find the most similar past sweeps and return their actual measured outcomes.
The probability shown is not derived from a formula. It is counted from real historical sweeps on your chart.
█ HOW IT WORKS
1. Pool Detection
Swing highs and swing lows are detected using two pivot lengths — a primary (default 10 bars each side) and a secondary (default 8 bars each side) — to capture both major and minor liquidity levels. Same-side pivots that form within the Equal-Level Tolerance % of each other are merged into a single stronger pool, marked with the ⊜ symbol. These are equal highs (EQH) or equal lows (EQL) — two peaks or two troughs at nearly the same price — which represent a higher concentration of stop orders than a single pivot.
Unswept pools are shown as lines on the chart: dashed for single pivots, solid for equal-level pools. Pools expire after the configured maximum age (default 50 bars) without generating a sweep record.
2. Sweep Detection
A sweep is registered when the close price exceeds a pool level by more than the Sweep Buffer (default 1.4 × ATR). This buffer filters out minor wicks that barely touch a level and requires a genuine close beyond it.
At the moment of the sweep, the script records:
• The direction (high swept or low swept)
• Whether the pool was an equal-level cluster (EQH/EQL)
• How old the pool was in bars
• The current ATR ratio (current volatility relative to the 50-bar baseline)
• Whether the sweep occurred inside an ICT killzone window
3. Outcome Measurement
After the Outcome Window (default 10 bars), the script measures what price actually did. For a swept high, it calculates how far price retraced downward and how far it continued upward, both expressed in ATR units. For a swept low, the directions are reversed. If the retracement exceeded the Reversal Threshold (default 3.5 × ATR), the sweep is classified as a reversal. Otherwise it is classified as a continuation. The result is stored in the KNN training data.
4. KNN Inference
The K-Nearest Neighbors model uses a 5-feature vector for each sweep:
• sweep_dir — was a high swept (1) or a low swept (0)?
• age_norm — how old was the pool when swept, normalized 0–1
• is_equal — was it an EQH/EQL cluster (1) or single pivot (0)?
• atr_ratio_norm — current ATR divided by 50-bar ATR baseline, capped at 3×
• in_kz — did the sweep occur inside a killzone window (1) or not (0)?
For each active sweep, the model computes the Euclidean distance to every recorded historical sweep in the training window, finds the K nearest matches (default 15), and returns three values averaged across those neighbors:
• Reversal probability — what percentage of matched sweeps reversed
• Average reversal distance — how far the reversal moved in ATR units
• Average continuation distance — how far the continuation moved in ATR units
The KNN runs every third bar per event for performance. Output is displayed only after the minimum training threshold (default 20 samples) has been reached.
5. Killzone Context
Four ICT killzone windows are tracked in New York time and used as a contextual feature in the KNN vector:
• Asia KZ — 20:00 to 00:00
• London Open KZ — 02:00 to 05:00
• NY Open KZ — 07:00 to 10:00
• London Close KZ — 10:00 to 12:00
Sweeps that occur inside a killzone are marked with ⚡ in the label. The active killzone is also shown in the dashboard.
█ READING THE LABEL
Each active sweep displays a label at the right edge of the chart:
▲ HIGH SWEPT ⊜ ⚡
Rev 68% | +1.4 ATR | N=47
▲ HIGH SWEPT — a swing high was swept (sell-side stops triggered)
⊜ — the pool was an equal-high cluster (stronger stop concentration)
⚡ — the sweep occurred inside a killzone window
Rev 68% — 68% of the 47 matched historical sweeps reversed
+1.4 ATR — the average reversal distance among those that reversed
N=47 — 47 historical sweeps matched this context
Label color follows sweep direction: orange-red for a swept high (bearish sweep), cyan for a swept low (bullish sweep).
While training data is still being collected, the label shows: Training… (8/20 needed)
█ LIQUIDITY VOID ZONE
When a sweep candle has a long wick, there is a gap between the wick extreme and where price actually closed. This zone — where price moved through too fast for normal order flow — is drawn as a semi-transparent dashed box. It represents an imbalance that price frequently returns to fill. The void is colored by sweep direction.
█ DASHBOARD
The top-right table shows:
• Session KZ — which killzone is currently active, if any
• ATR Ratio — current ATR relative to the 50-bar baseline (amber above 1.5×)
• KNN Training — progress bar showing recorded sweep outcomes vs maximum
• Overall Rev % — total reversal rate across all recorded sweeps on this chart
• Avg Rev Dist — average reversal move in ATR across all reversals
• Avg Cont Dist — average continuation move in ATR across all continuations
• Active Pools — number of unswept pools tracked, with EQH/EQL count
• Pending Sweeps — sweeps waiting for their outcome window to complete
• Resolved — count of confirmed reversals and continuations
• KNN Features — reminder of the five features used in the model
█ SETTINGS
Pool Detection
• Primary Pivot Length (10) — bars each side to confirm a major swing
• Secondary Pivot Length (8) — bars each side for minor swings; 0 disables
• Max Tracked Pools (60) — cap on active pools; oldest removed when exceeded
• Max Pool Age (50 bars) — pools older than this are expired without recording
• Equal-Level Tolerance % (3.0) — proximity threshold for EQH/EQL merging
Sweep Settings
• Sweep Buffer (1.4 × ATR) — minimum close beyond pool to register a sweep
• Outcome Window (10 bars) — measurement window after each sweep
• Reversal Threshold (3.5 × ATR) — minimum retracement to classify as reversal
• Show Liquidity Void Zones — toggle the wick imbalance boxes
• Max Historical Sweeps Shown — cap on how many past events are displayed
KNN Engine
• K Neighbors (15) — historical sweeps to average; higher = smoother, slower to adapt
• Max Training Samples (400) — rolling window; oldest samples dropped when exceeded
• Min Samples Before Display (20) — KNN output hidden until this threshold is reached
• ATR Baseline Period (50) — period for the baseline ATR used in the volatility feature
█ TIMEFRAME
Works on any intraday timeframe. Most useful at 5-minute through 1-hour where enough sweeps accumulate to build meaningful training data within a single session. On daily charts, the training window fills slowly but the signals tend to be higher quality.
The KNN model relearns continuously as new sweeps are recorded and old ones fall outside the rolling window. It adapts to the instrument and timeframe it is applied to.
█ NOTES
The reversal probability reflects historical behavior on this chart and timeframe. It is not a forward guarantee. A sweep with Rev 70% still continues 30% of the time. Use the N count as a confidence indicator — higher N means more matched examples and a more reliable estimate.
The model requires at least 20 sweep outcomes before displaying predictions. On timeframes with infrequent sweeps, this may take time to accumulate.
█ DISCLAIMER
This script is a visualization and analytical tool. It does not generate trade signals and does not constitute financial advice. Past sweep behavior does not guarantee future outcomes.
Usually, a liquidity indicator shows where the price is likely to go to take liquidity. This one tells you what tends to happen after it gets there.
When price sweeps a swing high or low — triggering the stop orders sitting there — we face the immediate question: does it reverse (a stop hunt, fade the move) or does it continue (a genuine breakout)? The answer depends on context. This script tracks every historical sweep on your chart, records the contextual features at the moment it happened, and uses a KNN (K-Nearest Neighbors) model to find the most similar past sweeps and return their actual measured outcomes.
The probability shown is not derived from a formula. It is counted from real historical sweeps on your chart.
█ HOW IT WORKS
1. Pool Detection
Swing highs and swing lows are detected using two pivot lengths — a primary (default 10 bars each side) and a secondary (default 8 bars each side) — to capture both major and minor liquidity levels. Same-side pivots that form within the Equal-Level Tolerance % of each other are merged into a single stronger pool, marked with the ⊜ symbol. These are equal highs (EQH) or equal lows (EQL) — two peaks or two troughs at nearly the same price — which represent a higher concentration of stop orders than a single pivot.
Unswept pools are shown as lines on the chart: dashed for single pivots, solid for equal-level pools. Pools expire after the configured maximum age (default 50 bars) without generating a sweep record.
2. Sweep Detection
A sweep is registered when the close price exceeds a pool level by more than the Sweep Buffer (default 1.4 × ATR). This buffer filters out minor wicks that barely touch a level and requires a genuine close beyond it.
At the moment of the sweep, the script records:
• The direction (high swept or low swept)
• Whether the pool was an equal-level cluster (EQH/EQL)
• How old the pool was in bars
• The current ATR ratio (current volatility relative to the 50-bar baseline)
• Whether the sweep occurred inside an ICT killzone window
3. Outcome Measurement
After the Outcome Window (default 10 bars), the script measures what price actually did. For a swept high, it calculates how far price retraced downward and how far it continued upward, both expressed in ATR units. For a swept low, the directions are reversed. If the retracement exceeded the Reversal Threshold (default 3.5 × ATR), the sweep is classified as a reversal. Otherwise it is classified as a continuation. The result is stored in the KNN training data.
4. KNN Inference
The K-Nearest Neighbors model uses a 5-feature vector for each sweep:
• sweep_dir — was a high swept (1) or a low swept (0)?
• age_norm — how old was the pool when swept, normalized 0–1
• is_equal — was it an EQH/EQL cluster (1) or single pivot (0)?
• atr_ratio_norm — current ATR divided by 50-bar ATR baseline, capped at 3×
• in_kz — did the sweep occur inside a killzone window (1) or not (0)?
For each active sweep, the model computes the Euclidean distance to every recorded historical sweep in the training window, finds the K nearest matches (default 15), and returns three values averaged across those neighbors:
• Reversal probability — what percentage of matched sweeps reversed
• Average reversal distance — how far the reversal moved in ATR units
• Average continuation distance — how far the continuation moved in ATR units
The KNN runs every third bar per event for performance. Output is displayed only after the minimum training threshold (default 20 samples) has been reached.
5. Killzone Context
Four ICT killzone windows are tracked in New York time and used as a contextual feature in the KNN vector:
• Asia KZ — 20:00 to 00:00
• London Open KZ — 02:00 to 05:00
• NY Open KZ — 07:00 to 10:00
• London Close KZ — 10:00 to 12:00
Sweeps that occur inside a killzone are marked with ⚡ in the label. The active killzone is also shown in the dashboard.
█ READING THE LABEL
Each active sweep displays a label at the right edge of the chart:
▲ HIGH SWEPT ⊜ ⚡
Rev 68% | +1.4 ATR | N=47
▲ HIGH SWEPT — a swing high was swept (sell-side stops triggered)
⊜ — the pool was an equal-high cluster (stronger stop concentration)
⚡ — the sweep occurred inside a killzone window
Rev 68% — 68% of the 47 matched historical sweeps reversed
+1.4 ATR — the average reversal distance among those that reversed
N=47 — 47 historical sweeps matched this context
Label color follows sweep direction: orange-red for a swept high (bearish sweep), cyan for a swept low (bullish sweep).
While training data is still being collected, the label shows: Training… (8/20 needed)
█ LIQUIDITY VOID ZONE
When a sweep candle has a long wick, there is a gap between the wick extreme and where price actually closed. This zone — where price moved through too fast for normal order flow — is drawn as a semi-transparent dashed box. It represents an imbalance that price frequently returns to fill. The void is colored by sweep direction.
█ DASHBOARD
The top-right table shows:
• Session KZ — which killzone is currently active, if any
• ATR Ratio — current ATR relative to the 50-bar baseline (amber above 1.5×)
• KNN Training — progress bar showing recorded sweep outcomes vs maximum
• Overall Rev % — total reversal rate across all recorded sweeps on this chart
• Avg Rev Dist — average reversal move in ATR across all reversals
• Avg Cont Dist — average continuation move in ATR across all continuations
• Active Pools — number of unswept pools tracked, with EQH/EQL count
• Pending Sweeps — sweeps waiting for their outcome window to complete
• Resolved — count of confirmed reversals and continuations
• KNN Features — reminder of the five features used in the model
█ SETTINGS
Pool Detection
• Primary Pivot Length (10) — bars each side to confirm a major swing
• Secondary Pivot Length (8) — bars each side for minor swings; 0 disables
• Max Tracked Pools (60) — cap on active pools; oldest removed when exceeded
• Max Pool Age (50 bars) — pools older than this are expired without recording
• Equal-Level Tolerance % (3.0) — proximity threshold for EQH/EQL merging
Sweep Settings
• Sweep Buffer (1.4 × ATR) — minimum close beyond pool to register a sweep
• Outcome Window (10 bars) — measurement window after each sweep
• Reversal Threshold (3.5 × ATR) — minimum retracement to classify as reversal
• Show Liquidity Void Zones — toggle the wick imbalance boxes
• Max Historical Sweeps Shown — cap on how many past events are displayed
KNN Engine
• K Neighbors (15) — historical sweeps to average; higher = smoother, slower to adapt
• Max Training Samples (400) — rolling window; oldest samples dropped when exceeded
• Min Samples Before Display (20) — KNN output hidden until this threshold is reached
• ATR Baseline Period (50) — period for the baseline ATR used in the volatility feature
█ TIMEFRAME
Works on any intraday timeframe. Most useful at 5-minute through 1-hour where enough sweeps accumulate to build meaningful training data within a single session. On daily charts, the training window fills slowly but the signals tend to be higher quality.
The KNN model relearns continuously as new sweeps are recorded and old ones fall outside the rolling window. It adapts to the instrument and timeframe it is applied to.
█ NOTES
The reversal probability reflects historical behavior on this chart and timeframe. It is not a forward guarantee. A sweep with Rev 70% still continues 30% of the time. Use the N count as a confidence indicator — higher N means more matched examples and a more reliable estimate.
The model requires at least 20 sweep outcomes before displaying predictions. On timeframes with infrequent sweeps, this may take time to accumulate.
█ DISCLAIMER
This script is a visualization and analytical tool. It does not generate trade signals and does not constitute financial advice. Past sweep behavior does not guarantee future outcomes.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Connect the dots to elevate your trading.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Connect the dots to elevate your trading.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.