MGC 30-minute opening range from 9:30 at 2R
The range is 9:30 to 10:00 New York. Until 12:00 the first 5-minute close outside it enters. The stop sits at the range's other side and the target at 2R. There is one trade a day. Its inputs set the start, the length in minutes and the target.
- Trades
- 465
- Won
- 46.7%
- Profit factor
- 1.12
- Net
- +9.8%
- Worst drawdown
- −6.1%
- Worst trade
- −$891
MGC1! · 5-minute · 4 Nov 2024 → 2 Nov 2026 · $2.50 a contract each side and a tick of slippage · one contract on a $50,000 account
+$2,902 from 4 November 2024 to 23 February 2026, +$2,021 from 24 February 2026 to 2 November 2026.
//@version=6
// Suggested timeframe: 5-minute (the chart's bars must be no longer than the range)
strategy("Opening range breakout for any session", 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)
// The range: its start on a clock you name and its length in minutes. Name the clock: with no zone,
// hour() and minute() read the exchange's clock (Chicago on CME's NQ and ES, New York on COMEX and NYMEX)
startHour = input.int(9, "Range start: hour", minval=0, maxval=23)
startMin = input.int(30, "Range start: minute", minval=0, maxval=59)
rangeLen = input.int(30, "Range length (minutes)", minval=1, maxval=720)
tz = input.string("America/New_York", "Clock (a time zone name)")
entryLen = input.int(120, "Entries for (minutes after the range)", minval=1, maxval=1440)
rMult = input.float(2.0, "Target (R)", minval=0.5, step=0.5)
if timeframe.in_seconds() > rangeLen * 60
runtime.error("The chart's bars are longer than the range. Use a chart of " + str.tostring(rangeLen) + " minutes or less.")
// Minutes since the range's start on that clock (0 to 1439): a range may cross midnight
since = (hour(time, tz) * 60 + minute(time, tz) - (startHour * 60 + startMin) + 1440) % 1440
inRange = since < rangeLen
inEntry = since >= rangeLen and since < rangeLen + entryLen
// The range's high and low start on its first bar. They are set once its last bar has closed
// and cleared when the next futures day opens (18:00 New York)
var float orHigh = na
var float orLow = na
var bool isSet = false
var int tradesToday = 0
if session.isfirstbar
isSet := false
tradesToday := 0
if inRange
orHigh := inRange[1] ? math.max(orHigh, high) : high
orLow := inRange[1] ? math.min(orLow, low) : low
isSet := false
else if inRange[1]
isSet := true
// The breakout: the first close outside the set range and one trade a day. The stop sits at the
// range's other side and the target at rMult times the risk. The trade closes on the day's last bar
var float stopLevel = na
var float targetLevel = na
canTrade = isSet and inEntry and strategy.position_size == 0 and tradesToday < 1
if canTrade and close > orHigh and close[1] <= orHigh
stopLevel := orLow
targetLevel := close + (close - orLow) * rMult
strategy.entry("Long", strategy.long)
strategy.exit("Long exit", from_entry="Long", stop=stopLevel, limit=targetLevel)
tradesToday += 1
if canTrade and close < orLow and close[1] >= orLow
stopLevel := orHigh
targetLevel := close - (orHigh - close) * rMult
strategy.entry("Short", strategy.short)
strategy.exit("Short exit", from_entry="Short", stop=stopLevel, limit=targetLevel)
tradesToday += 1
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(isSet ? orHigh : na, "Range high", color=color.new(#16A56A, 0), style=plot.style_linebr)
plot(isSet ? orLow : na, "Range low", color=color.new(#E5484D, 0), style=plot.style_linebr)
