Liquidity Sweep Quality Score [TradeDots]Liquidity Sweep Quality Score
Summary
This indicator detects liquidity-sweep events on the chart timeframe and assigns each event a 0 to 100 composite quality score with an A+, A, B, C, D, or Weak letter grade. A liquidity sweep here is defined precisely: the current bar prints beyond a confirmed swing pivot (below a prior swing low for a bullish sweep, or above a prior swing high for a bearish sweep) and closes back inside the prior range. The composite score is built from six independent factors that quantify how decisively the rejection occurred and how supportive the surrounding context is. The grade label is drawn on the bar immediately after the sweep so that the score includes the first piece of follow-through evidence.
What is original here
Detecting liquidity sweeps from pivot geometry is straightforward and is already common across public scripts. Where most scripts stop at binary detection ("a sweep happened"), this script adds a multi-factor quality layer on top. The originality is in the scoring methodology: six measurable factors, each normalized to a 0 to 100 scale so that raw units do not dominate, combined as a weighted average with a regime-aware penalty applied at the end. All weights and thresholds are exposed as inputs so that the model is auditable and tunable. The contribution is not the detection but the explicit, transparent scoring layer that lets traders rank sweeps rather than treat them as uniformly meaningful.
How it works
Pivots are tracked with the standard pivot-high and pivot-low primitives using a user-configurable symmetric left/right lookback. The most recently confirmed swing high and swing low are held in memory.
A bullish sweep registers when the current bar's low prints below the most recent swing low and the current close finishes above it. A bearish sweep is the symmetric case. A wick-to-body ratio gate filters trivial events where the rejection wick is too small relative to the candle body. Signal evaluation is gated by barstate.isconfirmed, so signals only finalize at bar close.
When a sweep is detected, the six factors below are computed.
1. Wick rejection strength. The size of the rejection wick on the sweep candle relative to the candle body. A larger wick relative to body indicates a more decisive intrabar rejection of the swept level. Scaled by the user's minimum acceptable wick-to-body ratio.
2. Relative volume. The rolling percentile rank of the sweep bar's volume within a configurable lookback (default 100 bars). Sweeps occurring on volume in the upper percentiles score higher than sweeps on quiet bars.
3. Failed-break decisiveness. The distance between the swept pivot and the close, expressed in ATR units. A close that recovers a full ATR back inside the prior range scores higher than a marginal recovery.
4. Higher-timeframe level proximity. The distance between the close and the nearest of the prior higher-timeframe bar's high or low, expressed in ATR units. Sweeps near a major higher-timeframe level score higher than sweeps at intra-range pivots.
5. Follow-through confirmation. The bar immediately after the sweep is inspected. A directionally consistent follow-through (a green bar after a bullish sweep, a red bar after a bearish sweep) earns full credit. Because this factor requires the next bar, the composite is finalized one bar after the sweep candle and the grade label is drawn on the follow-through bar, not on the sweep bar itself. This is documented behaviour, not a defect.
6. Regime penalty. Computed from ADX and the EMA-50 / EMA-200 alignment. When a sweep occurs against the direction of a strongly trending market (ADX above the user threshold and the sweep direction conflicts with the EMA alignment), a fixed user-configurable penalty is subtracted from the composite. A bullish sweep in a strong downtrend is structurally the same pattern as a bullish sweep in a balanced range, but the prior probability of follow-through differs. The penalty makes that difference visible in the score.
The composite is the weighted average of factors 1 through 5, with factor 6 applied as a post-weighting deduction. Tier mapping:
A+ : score 90 or higher
A : score 80 to 89
B : score 70 to 79
C : score 60 to 69
D : score 50 to 59
Weak : below 50
Repainting and data integrity
All sweep detection, scoring, label placement, and alert triggers are gated by barstate.isconfirmed. Signals do not appear or change intrabar.
The higher-timeframe level is fetched with request.security() using the prior-bar source (high and low ) together with the barmerge.lookahead_on flag. This combination is the established non-repainting form for higher-timeframe reads: the index requests the value from the prior higher-timeframe bar, and the lookahead flag ensures that value is returned consistently in both historical and real-time evaluation. This pattern does not access future data. It returns the last confirmed higher-timeframe bar's extremes, which are already history at the moment they are read.
How to read the chart
A small triangle is plotted at the sweep bar itself: below the bar for bullish sweeps, above the bar for bearish sweeps. This marks the detection event.
A directional grade label is drawn on the next bar (the follow-through bar), with text showing the letter grade and the numeric composite score. The label color shifts on a red-to-green gradient based on the score.
A configurable dashboard panel shows the most recent sweep's direction, each of the six sub-factor scores with gradient cells, the regime-penalty status, the composite score, and the letter grade.
All sub-scores are also output as hidden plots so that they are accessible from the Data Window and may be referenced in alert messages.
Inputs
Inputs are grouped into five sections.
Core Settings : swing pivot lookback, minimum wick-to-body ratio, ATR length, volume percentile lookback.
Filters : higher-timeframe reference, ADX length and threshold for the regime check, regime-penalty enable toggle.
Score Tuning : a 0 to 1 weight for each of the five positive factors and the regime-penalty magnitude in points.
Visual Settings : panel position, panel size, label cap, marker and label toggles.
Any Alert() function call conditions : per-signal boolean toggles to enable individual alerts.
Alerts
Six alert conditions are provided: A+ Setup, A Setup, B Setup, Bullish Sweep with quality at or above 70, Bearish Sweep with quality at or above 70, and Any Sweep with score at or above 80. Each alert is declared via alertcondition() for native TradingView alert configuration and is also fired programmatically through alert() when its corresponding input toggle is enabled. All programmatic alerts use alert.freq_once_per_bar_close to prevent intrabar re-triggers. The alertcondition() message templates include {{ticker}}, {{interval}}, and {{close}} placeholders for webhook integrations.
How to use this script
This script is a quality filter for reversal-style entries. It is not a complete trading system.
Identify a discretionary or systematic reversal context — a higher-timeframe level retest, a range extreme, a divergence, or any structure already in your plan.
Wait for a sweep marker to print.
Read the dashboard at bar close on the follow-through bar. Treat B-grade or better as candidate setups. Treat C and Weak as information only.
If the regime-penalty row indicates the sweep is fighting a strong trend, weight the signal toward "pullback rejection inside a continuing trend" rather than "trend reversal."
Position sizing, stop placement, and target selection remain entirely the user's responsibility.
Limitations and honest caveats
The composite score is a heuristic evidence weighting. It is not a statistically calibrated probability. An A grade means a sweep has more of the listed evidence factors than a C grade. It does not imply a specific likelihood of follow-through.
Pivot detection has inherent right-bar confirmation lag. A swing pivot is only confirmed after the configured right lookback has elapsed.
The higher-timeframe proximity factor uses only the prior higher-timeframe bar's high and low. Other structurally relevant levels — anchored VWAPs, weekly opens, user-marked supply or demand, prior session highs and lows — are not part of this factor.
The regime penalty uses ADX, which is a lagging measure of trend strength and will not flag fast regime shifts immediately.
The grade label is drawn one bar after the sweep bar by design (see factor 5 above). Traders who require the label on the sweep bar itself should be aware that this would mean publishing a score before the follow-through evidence exists.
The script is an indicator, not a strategy. It does not size positions, manage stops, or backtest entries.
Disclaimer
This script is published for informational and educational purposes. It is not investment advice and is not a recommendation to buy or sell any instrument. Past appearance of any pattern, including high-grade sweep setups, does not guarantee future behaviour. Users are solely responsible for their own trading decisions and risk management.
อินดิเคเตอร์ Pine Script®






















