Liquidity Sweep Detector
Institutional order flow often involves sweeping through prior support and resistance levels to trigger stops before reversing direction. This indicator identifies instances where price breaks past a recent high or low (the "sweep"), then recovers back through that same level (the "reclaim"), a pattern associated with liquidity capture and potential trend reversals. Traders use sweep-reclaim patterns to anticipate reaction zones and confirm conviction in directional moves.
//@version=6
indicator("Liquidity Sweep Detector", overlay=true)
// Inputs
lookbackPeriod = input.int(20, "Lookback Period (bars)", minval=5, maxval=200)
minSweepmeasure = input.float(0.001, "Min Sweep %", minval=0, step=0.001)
reclaimConfirm = input.int(5, "Reclaim Confirmation Bars", minval=1, maxval=50)
// Compute recent highs and lows
recentHigh = ta.highest(high, lookbackPeriod)
recentLow = ta.lowest(low, lookbackPeriod)
// Track whether we're currently swept above recent high or below recent low
sweptAboveHigh = high > recentHigh[1] and close[1] <= recentHigh[1]
sweptBelowLow = low < recentLow[1] and close[1] >= recentLow[1]
// Track if we've begun reclaiming (crossing back through the swept level)
sweepHighLevel = ta.valuewhen(sweptAboveHigh, recentHigh[1], 0)
sweepLowLevel = ta.valuewhen(sweptBelowLow, recentLow[1], 0)
reclaimingFromHigh = high > sweepHighLevel and sweptAboveHigh[1] and close < sweepHighLevel
reclaimingFromLow = low < sweepLowLevel and sweptBelowLow[1] and close > sweepLowLevel
// Confirm reclaim completion over N bars
barsReclaimedHigh = ta.barssince(reclaimingFromHigh)
barsReclaimedLow = ta.barssince(reclaimingFromLow)
reclaimCompleteHigh = barsReclaimedHigh <= reclaimConfirm and barsReclaimedHigh >= 0
reclaimCompleteLow = barsReclaimedLow <= reclaimConfirm and barsReclaimedLow >= 0
// Plot sweep levels
plot(sweepHighLevel, "Sweep High Level", color=color.new(color.red, 50), linewidth=1, style=plot.style_linebr)
plot(sweepLowLevel, "Sweep Low Level", color=color.new(color.blue, 50), linewidth=1, style=plot.style_linebr)
// Alert on sweep events
plotshape(sweptAboveHigh, "Swept Above High", shape.triangledown, location.abovebar, color.red, 0, "↓")
plotshape(sweptBelowLow, "Swept Below Low", shape.triangleup, location.belowbar, color.blue, 0, "↑")
// Alert on reclaim completion
plotshape(reclaimCompleteHigh, "Reclaim Above High", shape.circle, location.abovebar, color.new(color.red, 0), size=size.small, title="Reclaim High")
plotshape(reclaimCompleteLow, "Reclaim Below Low", shape.circle, location.belowbar, color.new(color.blue, 0), size=size.small, title="Reclaim Low")
// Background shading during sweep phase
bgcolor(sweptAboveHigh[1] and not reclaimCompleteHigh ? color.new(color.red, 90) : na)
bgcolor(sweptBelowLow[1] and not reclaimCompleteLow ? color.new(color.blue, 90) : na)
alertcondition(sweptAboveHigh, "Sweep Above High", "Price swept above prior high")
alertcondition(sweptBelowLow, "Sweep Below Low", "Price swept below prior low")
alertcondition(reclaimCompleteHigh, "Reclaim Complete High", "Price reclaimed above prior high")
alertcondition(reclaimCompleteLow, "Reclaim Complete Low", "Price reclaimed below prior low")
How the code works
The script establishes a lookback period (default 20 bars) to identify the recent high and low using ta.highest() and ta.lowest(). A "sweep" event triggers when price breaks into new territory: sweptAboveHigh fires when today's high exceeds yesterday's recent high and yesterday's close was at or below it, signalling a clean breakout. Conversely, sweptBelowLow triggers on a downside penetration.
Once a sweep is detected, the level is captured using ta.valuewhen(), which stores the exact high or low that was swept. The reclaim logic then watches for price to cross back through that stored level: reclaimingFromHigh and reclaimingFromLow detect a reversal close that moves back into the prior zone.
To avoid false signals from quick taps, the reclaim is confirmed over a user-defined number of bars (default 5). The ta.barssince() function counts how long ago the reclaim began, and reclaimCompleteHigh / reclaimCompleteLow only fire if that count is within the confirmation window. Background shading highlights the "sweep phase", the period between the sweep event and confirmed reclaim, to visually isolate liquidity zones.
Reading it on a chart
Downside sweep (red triangle down): Price breaks below the recent 20-bar high and closes below it. This often represents a stop hunt or initial momentum break. Watch the red shaded background that follows, it marks the active sweep zone.
Upside sweep (blue triangle up): Price breaks above the recent 20-bar low and closes above it. This can signal panic liquidation or an initial capitulation.
Reclaim signal (solid circles): When price then closes back through the swept level within the confirmation bars, a filled circle prints. This is the key event: the sweep has been rejected and price is reclaiming the zone. Many traders interpret a reclaim as proof that the initial sweep was a liquidity grab, not a trend reversal.
Practical use: A trader might set a tight stop-loss on a reclaim signal in the direction of the reclaim, betting on continuation. Alternatively, a reclaim can warn of a failed breakout, suggesting reversion to the mean or a deeper pullback.
Limitations
Lookback bias and curve-fitting: The 20-bar default window is arbitrary. Shorter lookbacks (5-10 bars) generate frequent signals with higher noise; longer periods (30-50 bars) miss local liquidity events. There is no universally optimal setting; the user must tune to their timeframe and asset.
No volatility adjustment: The indicator treats a 0.5% sweep the same as a 2% sweep. In choppy, high-volatility regimes, numerous false sweeps can occur without institutional intent. Adding ATR-based filters is common in practice but is not built in.
Repainting risk from confirmation: The reclaimConfirm bars parameter creates a subtle repainting effect: a reclaim signal may disappear if price trades back below the level within the confirmation window, changing the indicator's historical appearance. Traders should only alert on the first confirmation bar, not retrospectively.
No volume or order flow context: Sweeps accompanied by high volume are more reliable than thin-market taps. This indicator is price-only and cannot distinguish between conviction and noise. Combining with volume analysis or micro-structure tools is advised.
Regime dependency: Sweep-reclaim patterns are more meaningful during periods of defined support and resistance (ranging or structured markets) than in strongly trending environments where prior highs and lows are simply broken decisively. In sustained uptrends or downtrends, reclaims may be uncommon and late.
Timing lag: By definition, a reclaim signal fires after the reversal has already begun. It is a confirmation tool, not a leading indicator. Entry and exit timing based solely on this signal is reactive.
Key definitions
Liquidity sweep: Price movement that breaks past a prior support or resistance level, often interpreted as a triggered stop-loss order or institutional accumulation/distribution move.
Reclaim: The subsequent price action that closes back through the swept level, suggesting rejection of the breakout and reversal of the sweep.
Lookback period: The number of bars examined to establish the recent high and low baseline against which sweeps are measured.
Stop hunt: A rapid price excursion designed to trigger stop-loss orders clustered near support or resistance, followed by reversal. Sweep-reclaim patterns are associated with this mechanic.
Confirmation bars: The number of bars allowed after a reclaim begins before the signal is considered confirmed, used to filter out quick reversals that may not persist.
References
-
CME Group, "Commonly Used Exchange Definitions and Trade Execution Terms," CME Education (stable resource). URL: https://www.cmegroup.com/tools-information/education.html
-
Investopedia, "Order Flow," Investopedia (2024). URL: https://www.investopedia.com/terms/o/order-flow.asp
-
TradingView, "Pine Script Reference Manual v6," TradingView Documentation. URL: https://www.tradingview.com/pine-script-docs/
-
FINRA, "Market Structure and Regulation," Investor Education. URL: https://www.finra.org/investors/learn-to-invest
-
Victor Sperandeo, "Trader Vic: Methods of a Wall Street Master," John Wiley & Sons (1991). Referenced for sweep-and-reclaim pattern taxonomy in institutional trading contexts.
Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard.
Last reviewed by the PropLedger research pipeline: 2026-10-11. Educational research on historical data, not financial advice.
Keep reading
Spread Tracker: Two Futures Contracts
Free open-source Pine Script indicator: spread tracker between two related futures contracts. Full code and a plain-English walkthrough.
New High / New Low Breadth
Free open-source Pine Script indicator: new high/new low breadth proxy for a symbol basket. Full code and a plain-English walkthrough.
Floor vs Camarilla Pivot Points
Free open-source Pine Script indicator: pivot points: floor trader vs Camarilla comparison. Full code and a plain-English walkthrough.