Skip to main content
All posts
Blog

NinjaTrader Opening Range Breakout Strategy: Why It Enters at the Bar Close

Your 5 minute ORB strategy fills at the bar close, not the breakout. Why a NinjaTrader 8 backtest enters late, and how stop orders fix it.

Wizdough8 min read

A trader posted a 5 minute opening range breakout strategy on the NinjaTrader forum and asked why the entries were wrong. The rules were simple. Track the opening range. Wait for the first bar that closes outside it. Then buy a break of that bar's high, or sell a break of its low. The strategy was set to calculate on each tick, yet the entries seemed to land at the close of the 5 minute bar, not at the break.

Two things cause it, and a third shows up once you fix them. A backtest gives your code one look per bar. A market order sent at that look fills after the bar, not at your level. And once you move to stop orders on both sides of the bar, the managed order methods can drop one of them.

Why the entry lands on the close

The Calculate page in the NinjaScript help guide says it plainly: historical data processes OnBarUpdate() only on the close of each historical bar, even if Calculate is set to OnEachTick or OnPriceChange. The same page names the two ways to get intrabar data: Tick Replay, or a multi time frame script with a smaller added series. Without one of them, a backtest has no ticks inside your 5 minute bar for the code to see. It sees the bar once, when the bar is done.

So the strategy checks "did price break the signal bar high?" only at a close. By the time the answer is yes, the bar that broke the level has already finished, and an order sent now can only fill later. Our post on On Bar Close vs On Each Tick covers the three Calculate modes in more detail.

The fill itself comes from the bar data too. The help guide page on discrepancies between real time and backtest says a backtest decides fills from 4 data points, the open, high, low and close of a bar, because that is all it knows.

Two versions of the same 5 minute setup. A shaded box marks the opening range, and the signal bar closes above it. Top: the strategy code runs once at the signal bar close, so a market order it sends fills on the next bar, near the close and below the signal bar high. Bottom: a buy stop order at the signal bar high plus 1 tick waits at that price and fills, at the level or past it, only when a later bar trades up to it.

Put the order at the level before price gets there

The fix is to stop waiting for price to reach the level and leave an order there instead. When the signal bar closes outside the range, send a buy stop at its high plus 1 tick (EnterLongStopMarket) and a sell stop at its low minus 1 tick (EnterShortStopMarket). The order now sits at the breakout price. In a backtest, the fill algorithm fills it when a later bar trades through that price. Live, it triggers when price gets there and then fills as a market order, at the level or past it.

One detail on those methods. The Managed Approach page says entry orders cancel automatically at the end of a bar if they are not sent again. The longest signature has an isLiveUntilCancelled parameter. Set it to true and the order stays live until you cancel it with CancelOrder() or its time in force ends. For an opening range setup that is usually what you want, plus a rule that cancels the order when your entry window closes.

A stop market order is still a market order once it triggers. The page on historical fill processing says NinjaTrader applies backtest slippage only to market, stop market and market if touched orders. If you set slippage in the Strategy Analyzer, it applies to these entries.

Stops on both sides: one gets ignored

The Managed Approach page lists the internal order handling rules, and says they apply per unique signal name. One of them: an entry method is ignored when the strategy position is flat and an order from an enter method is active and would open a position in the opposite direction. Different signal names did not get around it in a case reported on the forum. In a January 2026 thread, a strategy sent a buy stop named NewsBuy and a sell stop named NewsSell, both with isLiveUntilCancelled set to true. The buy stop worked and the sell stop was ignored. The Log tab in the Control Center reports the first order that breaks a rule. Later ones are not reported.

You have two ways around it.

  1. Trade one side. If your rule only buys when the signal bar closes above the range and only sells when it closes below, you only ever need one stop. This is the simple version, and it stays inside the managed approach.
  2. Use the Unmanaged Approach. Set IsUnmanaged to true in OnStateChange(), and the signal tracking and internal order handling rules no longer apply. You then send both stops with SubmitOrderUnmanaged and give them the same OCO string, so they are linked. The help guide asks for a new OCO string for each group. You cannot mix managed and unmanaged order methods in one strategy.
// Unmanaged: both stops in one OCO group, live until cancelled.
// buyStop and sellStop are Order fields. Run this once per signal
// (guard it with a bool), not on every tick.
string oco = "orb-" + CurrentBar;
buyStop  = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.StopMarket, 1, 0, High[0] + TickSize, oco, "ORB long");
sellStop = SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.StopMarket, 1, 0, Low[0] - TickSize, oco, "ORB short");

The unmanaged route takes more code than one flag. The page says unmanaged orders are live until cancelled, so your code cancels them at the end of the entry window with CancelOrder(). It also has to keep the Order objects, because there is no signal tracking. The SubmitOrderUnmanaged page assigns them in OnOrderUpdate() so the assignment happens when expected. And it warns about overfills: entries that bracket the market in both directions can both fill instead of one being cancelled. By default NinjaTrader protects against an overfill by halting the strategy.

Two entry stops on both sides of the range. Top, managed Enter methods with a flat position: the buy stop works and the sell stop is ignored, because an entry order in the opposite direction is already working, and the Log tab shows an order handling error. Bottom, unmanaged: both stops are sent with SubmitOrderUnmanaged and share one OCO string, both work, and when one fills the other is cancelled.

Test it on finer data

Even with stop orders, a 5 minute backtest fills from 5 minute bars. In the Strategy Analyzer, set Order fill resolution to High and pick a finer series, down to 1 tick, as the price data for fills. The historical fill page says this makes the fill simulation more accurate and the backtest slower. It also says Order fill resolution cannot be used with multi time frame or multi instrument strategies, or with Tick Replay on.

Tick Replay is not the answer for backtests either. The Tick Replay page says it is not designed for NinjaScript strategy backtests and does not give the same results as running live with Tick Replay on. For a check closer to live than a backtest, run the strategy on the Playback connection. It is still not live: the discrepancies page says Playback fills from incoming market data and volume, and a broker fills by market dynamics. Our post on Playback with historical data explains what data Playback needs.

The opening range itself

NinjaTrader 8 has no opening range indicator in its built in list, so a strategy has to compute the range itself: the high and low of the bars inside your opening window, by the session times of the trading hours template on the chart. Our key levels guide shows which levels NinjaTrader draws for free and which it does not.

If you trade the opening range by hand rather than through a strategy, SweepScope draws the opening range lines for you (the first 30 minutes by default) along with the prior day and overnight levels. Our post on liquidity sweeps and runs covers what price does at those lines.

A short checklist

  1. In a backtest without Tick Replay or a smaller added series, expect OnBarUpdate() once per bar, at the close, whatever Calculate says.
  2. Leave a stop order at the breakout price instead of sending a market order after the break.
  3. Keep managed entries live with isLiveUntilCancelled, and cancel them when your entry window ends.
  4. For stops on both sides, trade one side per signal, or move to the unmanaged approach with one OCO string per pair.
  5. Backtest with Order fill resolution set to High, then check on Playback before you go live.

Futures trading involves substantial risk of loss and is not appropriate for all investors. Backtest and Playback results are simulated and do not predict live results.

Share
Email updates

Get the trading tool updates.

New releases, setup guides, and the occasional NinjaTrader tip. About once a week.

We keep your address in our own database and send from team@news.wizdough.com. Replies go to support@wizdough.com. Read how we handle your data in our Privacy Policy.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Mentioned in this post

SweepScope

See where price sweeps liquidity. $25/mo · 7-day free trial.

View product