Liquidity sweep reversal with a fair value gap check, 20 candles, 2R
A candle that takes out the last 20 candles' low and closes back above it is a sweep; with the gap check on, the entry waits up to three candles for a fair value gap in the reversal's direction. The stop sits a tick beyond the sweep's wick and the target twice the risk away. Entries 02:00 to 15:30 New York, one trade at a time, flat at 15:55.
- Trades
- 1,478
- Won
- 38.4%
- Profit factor
- 1.00
- Net
- −0.7%
- Worst drawdown
- −19.7%
- Worst trade
- −$636
MNQ1! · 5-minute · 23 October 2024 → 22 October 2026 · 2 years · 517 sessions · $2.50 a contract each side, one tick of slippage, one micro contract a trade
//@version=6
// Suggested timeframe: 5-minute
strategy("Liquidity sweep reversal (20 candles, gap check, 2R)", overlay=true, initial_capital=50000, default_qty_type=strategy.fixed, default_qty_value=1, commission_type=strategy.commission.cash_per_contract, commission_value=2.5, slippage=1, margin_long=0, margin_short=0)
// A candle that takes out the last N candles' low and closes back above it is a sweep of the sell
// side; its mirror takes out their high and closes back below. With the gap check on, the entry
// waits for a fair value gap in the reversal's direction within three candles. The entry is the
// next open, the stop a tick beyond the sweep's wick and the target a fixed multiple of the risk.
// Entries from 02:00 to 15:30 New York, one trade at a time; a trade still open is closed at 15:55.
tradeHours = input.session("0200-1530", "Entries (New York)")
look = input.int(20, "Liquidity: the last N candles' high or low", minval=2)
needGap = input.bool(true, "Wait for a fair value gap after the sweep")
rr = input.float(2.0, "Target, times the risk", minval=0.5, step=0.5)
nyMins = hour(time, "America/New_York") * 60 + minute(time, "America/New_York")
inHours = not na(time(timeframe.period, tradeHours, "America/New_York"))
lo = ta.lowest(low, look)[1]
hi = ta.highest(high, look)[1]
sweepLow = low < lo and close > lo
sweepHigh = high > hi and close < hi
// the last sweep's wick and how many candles ago it printed
var float longWick = na
var float shortWick = na
var int longAge = 99
var int shortAge = 99
longAge += 1
shortAge += 1
if sweepLow
longWick := low
longAge := 0
if sweepHigh
shortWick := high
shortAge := 0
bullGap = low > high[2]
bearGap = high < low[2]
goLong = needGap ? (bullGap and longAge >= 1 and longAge <= 3) : sweepLow
goShort = needGap ? (bearGap and shortAge >= 1 and shortAge <= 3) : sweepHigh
if strategy.position_size == 0 and inHours
if goLong and not na(longWick)
stp = longWick - syminfo.mintick
strategy.entry("Long", strategy.long)
strategy.exit("Long exit", "Long", stop=stp, limit=close + rr * (close - stp))
longAge := 99
else if goShort and not na(shortWick)
stp = shortWick + syminfo.mintick
strategy.entry("Short", strategy.short)
strategy.exit("Short exit", "Short", stop=stp, limit=close - rr * (stp - close))
shortAge := 99
if strategy.position_size != 0 and nyMins >= 955 and nyMins < 965
strategy.close_all(comment="Flat by the close")
plotshape(sweepLow, "Sell-side sweep", shape.triangleup, location.belowbar, color.new(#16A56A, 0), size=size.tiny)
plotshape(sweepHigh, "Buy-side sweep", shape.triangledown, location.abovebar, color.new(#E5484D, 0), size=size.tiny)

