NQ fair value gap retest with the VWAP from 18:00
Three 5-minute candles in New York hours leave a gap. A limit order waits 12 bars at its near side, longs only above the VWAP from the futures day's 18:00 open and shorts only below it. The stop sits at the first candle's far side and the target at 2R. Flat by 16:00. Its VWAP filter input switches to Off or From 9:30.
- Trades
- 1,500
- Won
- 35.9%
- Profit factor
- 0.92
- Net
- −18.7%
- Worst drawdown
- −22.9%
- Worst trade
- −$1,386.50
MNQ1! · 5-minute · 4 Nov 2024 → 22 Oct 2026 · $2.50 a contract each side and a tick of slippage · one contract on a $50,000 account
−$8,935 from 4 November 2024 to 23 February 2026, −$393 from 24 February 2026 to 22 October 2026.
//@version=6
// Suggested timeframe: 5-minute
strategy("NQ fair value gap retest with a VWAP filter", 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)
// Inputs: the target, how long a gap waits and the VWAP filter, all on New York's clock
rr = input.float(2.0, "Target (R)", minval=0.5, step=0.5)
maxWait = input.int(12, "Bars a gap waits for price to come back", minval=1)
vwapFrom = input.string("From 18:00", "VWAP filter", options=["Off", "From 18:00", "From 9:30"])
gapOk = not na(time(timeframe.period, "0940-1500", "America/New_York")) and not session.islastbar
lastNY = not na(time(timeframe.period, "1555-1600", "America/New_York"))
// The VWAP the filter reads: from the futures day's 18:00 New York open, or from 9:30 only
var float cumPV = 0.0
var float cumV = 0.0
var float cumPV930 = 0.0
var float cumV930 = 0.0
if session.isfirstbar
cumPV := 0.0
cumV := 0.0
cumPV930 := 0.0
cumV930 := 0.0
cumPV += hlc3 * volume
cumV += volume
if not na(time(timeframe.period, "0930-1600", "America/New_York"))
cumPV930 += hlc3 * volume
cumV930 += volume
vwapDay = cumV > 0 ? cumPV / cumV : na
vwap930 = cumV930 > 0 ? cumPV930 / cumV930 : na
vwapNow = vwapFrom == "From 18:00" ? vwapDay : vwapFrom == "From 9:30" ? vwap930 : na
// Longs only above the VWAP and shorts only below it. With the filter off both sides trade
longOk = vwapFrom == "Off" or (not na(vwapNow) and close > vwapNow)
shortOk = vwapFrom == "Off" or (not na(vwapNow) and close < vwapNow)
// Three candles in New York hours. Bullish: the third candle's low is above the first candle's high.
// Bearish: the third candle's high is below the first candle's low. A limit order waits at the gap's
// near side with the stop at the first candle's far side and the target at rr times the risk
var float zEntry = na
var float zStop = na
var int zDir = 0
var int zBar = 0
flat = strategy.position_size == 0
if flat and gapOk
if low > high[2] and longOk
strategy.cancel_all()
zDir := 1
zEntry := low
zStop := low[2]
zBar := bar_index
strategy.entry("Long", strategy.long, limit=zEntry)
strategy.exit("Long exit", "Long", stop=zStop, limit=zEntry + rr * (zEntry - zStop))
else if high < low[2] and shortOk
strategy.cancel_all()
zDir := -1
zEntry := high
zStop := high[2]
zBar := bar_index
strategy.entry("Short", strategy.short, limit=zEntry)
strategy.exit("Short exit", "Short", stop=zStop, limit=zEntry - rr * (zStop - zEntry))
// A gap price has not come back to within maxWait bars is dropped, and so is any after 15:00
if flat and zDir != 0 and (bar_index - zBar >= maxWait or not gapOk)
strategy.cancel_all()
zDir := 0
// Flat at 16:00, or on the session's last bar when the market closes early (a holiday half day) or
// halts for a long weekend: no order is left to fill when it opens again
if lastNY or session.islastbar
strategy.cancel_all()
strategy.close_all("Close", immediately=true)
plot(vwapNow, "VWAP", color=color.new(#E5A50A, 0), style=plot.style_linebr)
