
Short answer. An opening range breakout strategy marks the high and low of the first stretch of a session, then trades the first move that closes or trades beyond that range. To automate one in NinjaTrader you need five written rules: the exact time window that defines the range, what counts as a breakout, where the stop goes, how the trade is exited, and when the strategy stops looking for entries. Most of the work is in the details around the breakout itself, such as time zones, range-size filters, one trade per day and a flat-by time. No opening range setup has a guaranteed outcome, so test it on a simulated account before you rely on it.
What an opening range breakout is
Markets often move fast when a session opens, as overnight orders meet fresh volume and news. The opening range idea turns that burst into a box: you pick a window, say the first 15 or 30 minutes after the New York cash open, and record the highest high and lowest low printed inside it. After the window ends, the box is a pair of reference prices. A break above the high is a potential long, and a break below the low is a potential short.
The appeal for automation is that every part is mechanical. There is no pattern to judge by eye. The range is arithmetic on bar highs and lows, the trigger is a price crossing a number, and the exits can be fixed from the range itself. That makes it a good first project for a trader learning to automate a NinjaTrader strategy, and a good candidate for a clean backtest in the Strategy Analyzer.
The idea is not specific to US index futures. The same structure works on any market with a repeatable session start, including gold at the London open and the Asian session range. Only the clock changes.
Write the rules before you touch the platform
The mistake that ruins most opening range tests is leaving a rule vague. "Trade the breakout" can mean four different strategies. Fill in every line below on paper first.
| Rule | Questions to answer | Example choice |
|---|---|---|
| Range window | What time does it start and end, in which time zone, and on which chart? | 9:30 to 9:45 Eastern, 1-minute bars |
| Breakout trigger | Does a touch count, or must a bar close beyond the level? Is there a buffer in ticks? | A bar closes 1 tick beyond the range |
| Direction | Both ways, or only one side? Does a failed first break allow a reversal trade? | Both sides, first break only |
| Stop | Opposite side of the range, the midpoint, or a fixed number of ticks or points? | Midpoint of the range, capped at a maximum |
| Exit | A fixed target, a multiple of range size, a trailing stop, a time exit, or a mix? | Target at 1x range; flat by 11:30 Eastern |
| Filters | Minimum and maximum range size, trading days, news days, volatility filter? | Skip ranges under 8 points or over 40 points |
| Limits | Trades per day, daily loss limit, latest entry time? | One trade, no entries after 11:00 Eastern |
The example column is only an illustration of how specific a rule should be, not a recommendation. The right numbers depend on the market, the contract and your own tolerance for risk. Your job in testing is to find out how sensitive the strategy is to each choice, not to find the one setting that looked best.
Step 1: define the range window correctly
This is where most opening range bugs live, and nearly all of them are about time.
- Time zone. NinjaTrader timestamps bars in the time zone the platform and the trading hours template use, not necessarily the exchange's. A 9:30 Eastern open is 6:30 on a Pacific computer. Decide which clock your rules use and check the first bar of the day on a chart before you trust any code. See futures trading sessions for the standard opens in each region.
- The trading hours template. If the chart uses a 24-hour template, the session never "starts" at the cash open, so a rule such as "first bar of the session" will point at the wrong bar. Use explicit clock times, or choose a template whose session start matches your range. Trading hours templates explains how they work.
- Bar boundaries. On a 5-minute chart a 9:30 to 9:45 window is exactly three bars. On a 7-minute chart it is not a whole number of bars. Pick a bar size that divides the window evenly.
- The bar that completes the window. The range is only known once the last bar in the window closes. The earliest bar that may trigger an entry is the one after it. Allowing an entry on the last range bar is a quiet form of lookahead.
- Contract rolls and holidays. Early closes and holiday sessions have shorter or odd hours. Decide whether to skip those days or let the strategy handle them.
Step 2: choose how a breakout is confirmed
There are three common ways to define the trigger, and each trades differently.
- Stop order at the range edge. Place a buy stop at the range high and a sell stop at the range low as soon as the window ends. You are filled the instant price trades through the level. This is the fastest entry, and also the one most exposed to wicks and slippage at a fast open.
- Close beyond the level. Wait for a bar to close above the high or below the low, then enter at the next bar's open or with a market order. You skip some brief pokes outside the range but give up part of the move.
- Close beyond a buffer. Require a close a set number of ticks, or a fraction of the range, past the edge. It filters more noise, and also cuts the number of trades.
None of these is better in the abstract. They trade a different balance between getting in early and being tricked by a false break. The right way to choose is to run all three through the same honest backtest, with slippage included, and look at how stable each one is across different years and market conditions.
Step 3: stops, targets and the flat-by time
Because the range is a natural measuring stick, exits are often defined as a share of it.
- Stop at the opposite side. The logic is that a move back through the whole range invalidates the idea. On a wide range this makes the risk per trade large, which is why a maximum range filter or a cap on the stop distance matters.
- Stop at the midpoint. Halves the risk per trade but is hit more often by normal back-and-forth.
- Target as a multiple of the range. A target of one times the range scales automatically with volatility. A fixed-point target does not, so it behaves very differently on a quiet day and a wild one.
- Trailing or break-even logic. Optional, and a frequent source of curve fitting if you tune the trigger distances against the same data.
- A flat-by time. Opening range trades are meant to be early-session trades. If a position is still open late in the morning, the original reason for it is gone. Close it at a set time, and use a session-close exit as a backstop. See exit on session close for how that setting behaves.
Whatever you choose, size the trade from the stop, not from the account balance alone. The position size calculator shows how many contracts fit a given risk amount for a stop distance, and the daily loss limit guide covers a hard stop on the day.
Step 4: filter out the days the idea doesn't suit
The opening range idea assumes the break has somewhere to go. Two simple filters address the situations where it often does not.
- Range too small. A very narrow range means a stop only a few ticks away, which ordinary noise and commission can erase. A minimum size, in points or as a multiple of recent average range, avoids those days.
- Range too large. If most of the day's usual movement already happened in the first 15 minutes, the stop distance is large and the room left is small. A maximum size skips the day or reduces the trade size.
Other possible filters include day of the week, scheduled economic releases, and a higher-timeframe trend condition. Add them one at a time and test each on its own. A strategy with six stacked filters and 40 trades is far more likely to be an accident of the data than an edge.
Step 5: build it in Strategy Builder or NinjaScript
You can build a basic version with the Strategy Builder by combining time conditions and price conditions, but the range itself is simplest in code because it needs a running high and low that reset each day. The sketch below shows the core idea only. It is a teaching outline, not a finished or tested strategy, and it leaves out order management, filters and error handling.
private double rangeHigh, rangeLow;
private bool rangeSet, tradedToday;
protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade) return;
// New day: reset everything
if (Bars.IsFirstBarOfSession)
{
rangeHigh = double.MinValue;
rangeLow = double.MaxValue;
rangeSet = false;
tradedToday = false;
}
int t = ToTime(Time[0]);
// 1) Build the range while the window is open
if (t > 93000 && t <= 94500)
{
rangeHigh = Math.Max(rangeHigh, High[0]);
rangeLow = Math.Min(rangeLow, Low[0]);
if (t == 94500) rangeSet = true;
return;
}
// 2) After the window, look for the first close beyond the range
if (rangeSet && !tradedToday && t < 110000
&& Position.MarketPosition == MarketPosition.Flat)
{
if (Close[0] > rangeHigh) { EnterLong(); tradedToday = true; }
else if (Close[0] < rangeLow) { EnterShort(); tradedToday = true; }
}
// 3) Flat by a set time
if (t >= 113000 && Position.MarketPosition != MarketPosition.Flat)
{
if (Position.MarketPosition == MarketPosition.Long) ExitLong();
else ExitShort();
}
}
Several things in that outline need care before it is usable. The times assume the chart's clock is Eastern and the bars end exactly at 9:45. The first-bar-of-session reset depends on the trading hours template. Stops and targets are missing and should be set with the managed approach methods, and the range window should come from properties you can change rather than numbers typed into the code. If you have not used the NinjaScript Editor before, the automation guide walks through the editor, compiling and the settings that quietly change behaviour.
Step 6: test it the way it will run
Run the strategy through the same four stages used for any automated strategy, in order.
- Look at it on a chart. Apply the strategy and check ten or twenty individual days by eye. Does the range match the box you would draw by hand? Is the first entry where your written rule says it should be?
- Backtest with honest settings. Include commission and slippage, inspect ambiguous intrabar fills, and test across multiple periods rather than relying on a few favorable weeks. Historical fill resolution is a simulation assumption, not proof of the actual order of a stop and target inside a bar. High fill resolution is unavailable with Tick Replay or multi-timeframe/multi-instrument strategies; see the official historical fill documentation. The range edge is exactly where fills are least certain.
- Stress the parameters. Move the window by five minutes, change the buffer by a tick, change the stop rule. A robust idea survives those changes with similar results, while a fragile one only works at one setting.
- Run it in simulation. A simulated account shows how the strategy behaves with live data, connection hiccups and real order handling, and costs nothing to run. Give it a range of sessions, including a fast news open and a slow day.
When reading results, trade count matters more than total profit. An opening range strategy takes at most one or two trades a day, so a year of data may hold only a couple of hundred trades. That is thin enough that a handful of outliers can dominate, which is why the backtesting guide recommends reading drawdown and average trade first.
Common reasons an opening range strategy misbehaves
- It never trades. The window times don't match the data's time zone, or the template has no bar at the hour you chose. See strategy not showing in NinjaTrader and what an automated strategy needs to run.
- It trades on the wrong day or at the wrong time. A daylight saving shift, a holiday session or a 24-hour template moved the first bar. Print the time of the first and last range bar to the log for a few days.
- It enters twice. There is no once-a-day flag, or a stop-out resets the "traded today" state. Decide whether a second attempt is allowed and write the rule down.
- It holds after the exit time. The flat-by rule only runs when a new bar arrives. On a thin market, or with the calculation set to bar close, that can be later than you expect. See strategy start behavior for how an enabled strategy treats existing positions.
- Backtest and live results differ. Fast opens fill away from the level you saw. Test with slippage, and compare simulated fills to the backtest for the same days.
An opening range checklist
- Window start, end, time zone and bar size written down and consistent.
- Entry allowed only after the last range bar has closed.
- Breakout trigger defined: touch, close, or close beyond a buffer.
- Stop defined, with a cap on the maximum risk per trade.
- Exit defined: target, trail, flat-by time, or a combination.
- Minimum and maximum range filters tested on their own.
- One trade per day, or a clear rule for a second attempt.
- Daily loss limit and latest entry time included.
- Backtest includes commission and slippage and spans several years.
- Parameters nudged to check the result is stable, not tuned to one setting.
- Simulated trading before any decision to use it with real money.
Using a ready-made range breakout
If you would rather study a finished strategy than write one, each FuturesBotLab bot publishes its rules and risk settings on its page. Dawn Range (MGC · GC) marks gold's early London range and trades the first clean break out of it, and Bullion Break (MGC · GC) marks gold's overnight Asia range and trades the first London close outside it. You can read how each defines its window and its exits, then run your own Strategy Analyzer tests with your own costs and settings.
Related guides
- How to automate a NinjaTrader strategy: complete guide →
- How to backtest a NinjaTrader strategy: Strategy Analyzer guide →
- Futures trading sessions: Asia, London and New York times →
- NinjaTrader trading hours templates: set up Asia, London and New York sessions →
- Exit on session close: how it works and when to turn it off →
- NinjaTrader daily loss limit and strategy safety settings →
Bots mentioned in this guide
Futures trading involves substantial risk of loss and is not suitable for every investor. Backtests and simulated results are hypothetical, have inherent limitations and don't guarantee future results. This guide is educational, not investment advice. Risk disclosure.