NQ 15-minute opening range with a 1R trailing stop
The range is 9:30 to 9:45 New York. From 9:45 to 12:00 the first 5-minute close outside it enters. The stop starts at the range's other side. At each 5-minute close it moves to the best price since entry less the trade's risk and never moves back. There is no target; one trade a day. Its Exit input switches to Target or Trail by ATR.
- Trades
- 500
- Won
- 39.8%
- Profit factor
- 0.99
- Net
- −1.4%
- Worst drawdown
- −10.6%
- Worst trade
- −$537
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
+$2,397 from 4 November 2024 to 23 February 2026, −$3,091.50 from 24 February 2026 to 22 October 2026.
//@version=6
// Suggested timeframe: 5-minute
strategy("NQ Opening Range: fixed target or trailing stop", 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 opening range, the entry window and how the trade exits, all on New York's clock
orSess = input.session("0930-0945", "Opening range (New York)")
tradeSess = input.session("0945-1200", "Entry window (New York)")
exitMode = input.string("Trail by R", "Exit", options=["Target", "Trail by R", "Trail by ATR"])
rMult = input.float(2.0, "Target (R)", minval=0.5, step=0.5)
trailR = input.float(1.0, "Trail (R)", minval=0.25, step=0.25)
trailAtr = input.float(2.0, "Trail (ATR multiple)", minval=0.5, step=0.5)
atrLen = input.int(14, "ATR length", minval=1)
inOR = not na(time(timeframe.period, orSess, "America/New_York"))
inTrade = not na(time(timeframe.period, tradeSess, "America/New_York"))
atr = ta.atr(atrLen)
// The day's state, set back on the futures day's first bar (18:00 New York)
var float orHigh = na
var float orLow = na
var int tradesToday = 0
var float stopLevel = na
var float targetLevel = na
var float riskPts = na
var float bestPrice = na
if session.isfirstbar
orHigh := na
orLow := na
tradesToday := 0
// The setup: the first close outside the opening range; the stop at the range's other side
if inOR
orHigh := na(orHigh) ? high : math.max(orHigh, high)
orLow := na(orLow) ? low : math.min(orLow, low)
rangeSet = not inOR and not na(orHigh)
longSetup = rangeSet and close > orHigh and close[1] <= orHigh
shortSetup = rangeSet and close < orLow and close[1] >= orLow
// One trade a day, one micro contract, inside the window, flat
canTrade = inTrade and strategy.position_size == 0 and tradesToday < 1 and barstate.isconfirmed
if canTrade and longSetup and orLow < close
stopLevel := orLow
riskPts := close - orLow
targetLevel := exitMode == "Target" ? close + riskPts * rMult : na
bestPrice := close
strategy.entry("Long", strategy.long)
strategy.exit("Long exit", from_entry="Long", stop=stopLevel, limit=targetLevel)
tradesToday := tradesToday + 1
if canTrade and shortSetup and orHigh > close
stopLevel := orHigh
riskPts := orHigh - close
targetLevel := exitMode == "Target" ? close - riskPts * rMult : na
bestPrice := close
strategy.entry("Short", strategy.short)
strategy.exit("Short exit", from_entry="Short", stop=stopLevel, limit=targetLevel)
tradesToday := tradesToday + 1
// A trailing exit moves the stop at each bar's close and never back: the best price since entry, less
// the trail (the trade's risk times Trail (R), or the ATR times its multiple)
trailDist = exitMode == "Trail by R" ? riskPts * trailR : exitMode == "Trail by ATR" ? atr * trailAtr : na
if strategy.position_size > 0 and exitMode != "Target"
bestPrice := math.max(bestPrice, high)
stopLevel := math.max(stopLevel, bestPrice - trailDist)
if strategy.position_size < 0 and exitMode != "Target"
bestPrice := math.min(bestPrice, low)
stopLevel := math.min(stopLevel, bestPrice + trailDist)
// The stop, and the target when there is one, on every bar of the trade; flat on the session's last bar
if strategy.position_size > 0
strategy.exit("Long exit", from_entry="Long", stop=stopLevel, limit=targetLevel)
if strategy.position_size < 0
strategy.exit("Short exit", from_entry="Short", stop=stopLevel, limit=targetLevel)
if session.islastbar
strategy.close_all("Session end", immediately=true)
plot(rangeSet ? orHigh : na, "Range high", color=color.new(#16A56A, 0), style=plot.style_linebr)
plot(rangeSet ? orLow : na, "Range low", color=color.new(#E5484D, 0), style=plot.style_linebr)
plot(strategy.position_size != 0 ? stopLevel : na, "Stop", color=color.new(#3D69A8, 0), style=plot.style_linebr)
