MNQ opening range breakout, 15-minute range, 2R
The script every run used, with the 15-minute range and the 2R target. Change the two inputs at the top to run any other row of the table.
- Trades
- 381
- Won
- 46.2%
- Profit factor
- 1.11
- Net
- +18.7%
- Worst drawdown
- −17.1%
- Worst trade
- −$1,063
MNQ1! · 5-minute · 23 October 2024 → 22 October 2026 · 2 years · 517 sessions · $0.75 a contract each side, one tick of slippage, $50,000 account, 1% risk
The Pine Script, if you want to read it (79 lines)
//@version=6
// Suggested timeframe: 5-minute
strategy("MNQ Opening Range Breakout", overlay=true, initial_capital=50000, default_qty_type=strategy.fixed, default_qty_value=1,
commission_type=strategy.commission.cash_per_contract, commission_value=0.75, slippage=1, margin_long=0, margin_short=0)
// Inputs
orSess = input.session("0930-0945", "Opening range (New York)")
tradeSess = input.session("0945-1200", "Entry window (New York)")
riskPct = input.float(1.0, "Risk % per trade", minval=0.1, step=0.1)
rMult = input.float(2.0, "Target (R)", minval=0.5, step=0.5)
maxContracts = input.int(10, "Max contracts", minval=1)
maxTrades = input.int(1, "Max trades per day", minval=1)
// The clock is New York's; a future's day starts at the 18:00 New York reopen
inOR = not na(time(timeframe.period, orSess, "America/New_York"))
inTrade = not na(time(timeframe.period, tradeSess, "America/New_York"))
// The day's state: every level, flag and count the setup keeps, declared here and set back on the day's first bar
var float orHigh = na
var float orLow = na
var int tradesToday = 0
var bool doneToday = false
var float stopLevel = na
var float targetLevel = na
if session.isfirstbar
orHigh := na
orLow := na
tradesToday := 0
doneToday := false
// The setup: the first close outside the 15-minute opening range
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
longStop = orLow
shortStop = orHigh
// Entries: inside the window, flat, under the day's caps; the qty from the risk (a stop too wide skips the
// trade), the stop and target placed with the entry
canTrade = inTrade and strategy.position_size == 0 and tradesToday < maxTrades and not doneToday and barstate.isconfirmed
riskCash = math.max(strategy.equity, 0) * riskPct / 100
if canTrade and longSetup and not na(longStop) and longStop < close
stopPts = close - longStop
qty = math.min(maxContracts, math.floor(riskCash / ((stopPts + 2 * syminfo.mintick) * syminfo.pointvalue)))
if qty >= 1
stopLevel := longStop
targetLevel := close + stopPts * rMult
strategy.entry("Long", strategy.long, qty=qty)
strategy.exit("Long exit", from_entry="Long", stop=stopLevel, limit=targetLevel)
tradesToday := tradesToday + 1
if canTrade and shortSetup and not na(shortStop) and shortStop > close
stopPts = shortStop - close
qty = math.min(maxContracts, math.floor(riskCash / ((stopPts + 2 * syminfo.mintick) * syminfo.pointvalue)))
if qty >= 1
stopLevel := shortStop
targetLevel := close - stopPts * rMult
strategy.entry("Short", strategy.short, qty=qty)
strategy.exit("Short exit", from_entry="Short", stop=stopLevel, limit=targetLevel)
tradesToday := tradesToday + 1
// The same stop and target 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)
// A win ends the day
if strategy.closedtrades > strategy.closedtrades[1] and strategy.closedtrades.profit(strategy.closedtrades - 1) > 0
doneToday := 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)
plotshape(canTrade and longSetup, "Long", style=shape.triangleup, location=location.belowbar, color=color.new(#16A56A, 0), size=size.tiny)
plotshape(canTrade and shortSetup, "Short", style=shape.triangledown, location=location.abovebar, color=color.new(#E5484D, 0), size=size.tiny)