OPEN-SOURCE SCRIPT

Sweep & Reverse | Liquidity Sweep Reversal Strategy

17 531
This strategy trades the liquidity-sweep reversal pattern: price wicks through a prior swing high or low — clearing out the stops resting there — then closes back inside the range, suggesting the move beyond that level was a stop-hunt rather than a genuine breakout.

How it works:
Confirmed swing highs and lows (via pivot detection) are stored as watched levels.
A sweep triggers when a bar wicks past a level but closes back on the other side.
Longs enter on swept lows, shorts on swept highs. The stop sits just beyond the sweeping wick (with an ATR buffer); the target is set from your chosen reward:risk ratio.
Levels expire if left untouched for too long, and new levels too close to an existing one (relative to ATR) are skipped to keep zones from cluttering.

Features:
  • Optional volume-spike filter — only counts sweeps backed by above-average volume
  • Optional rejection-wick filter — requires the sweeping wick to be meaningfully larger than the bar's body, filtering out weak/low-conviction sweeps
  • Optional next-bar confirmation — waits one bar past the sweep and only enters if price actually continues in the reversal direction, reducing whipsaw entries
  • Optional session window filter (defaults to the London/NY overlap, the highest-liquidity window)
  • Adjustable stop distance, minimum stop size, and reward:risk ratio
  • Breakeven stop management once a trade moves partway to target
  • Long/short can be toggled independently
  • Every trade's entry/SL/TP lines persist on the chart after the trade closes (auto-expiring after a configurable number of bars), so past trades stay visible for review
  • Styled performance dashboard: trade count, win rate, net profit, live position state


Warnings:
This is fundamentally a mean-reversion pattern. In strongly trending markets, sweeps frequently continue rather than reverse — no combination of filters here eliminates that risk.
Backtest results are sensitive to pivot length, stop distance, and which filters are enabled. A high win rate on a small number of trades is not statistically meaningful — test across multiple instruments and timeframes, and evaluate profit factor and max drawdown alongside net profit, not net profit alone.

Past performance in a backtest, including this one, does not guarantee future results. This is not financial advice.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.