Calculate decides how often OnBarUpdate() runs. The default is OnBarClose, once at the close of each bar. If your logic doesn't need to act inside the bar, that's usually the simplest place to start. The trap is that historical data is processed at the close whichever mode you choose.
| Mode | When it runs | Keep in mind |
|---|---|---|
OnBarClose | Once, at the close of the bar | This is the default |
OnEachTick | On every tick | It can be CPU intensive |
OnPriceChange | When price changes inside the bar, or when it closes | It can miss volume updates at the same price |
On this page
The historical data trap
On historical data, NinjaTrader only knows each bar's open, high, low, close, volume and time, not every tick. So historically, OnBarUpdate() only runs at the close, even if you chose OnEachTick or OnPriceChange. Your strategy can behave differently live, and that's a common reason a backtest doesn't match live trading. The guide points to Tick Replay or a multi-time frame script for intrabar data.
Watch out for volume
If your script relies on volume updates, the guide warns against OnPriceChange. Two ticks in a row at the same price don't trigger a new call, so some of those updates can be missed.
Indicators inside a strategy
An embedded script shouldn't use a different Calculate: the calling strategy's setting governs it. That's why the guide says to set the strategy to the highest value its indicators need. If only part of the logic must run on each tick, NinjaTrader has a sample that separates it from the logic that runs at the close.
How to choose
- Start with OnBarClose if your signal is decided at the close.
- Use OnPriceChange if you need to react to price and don't rely on every volume update.
- Keep OnEachTick for logic that truly needs every tick, and watch your CPU.
- Only set the value in
State.SetDefaultsorState.Configure. - If you change mode, compare live with Playback or Tick Replay before trusting the backtest.
On a prop firm account, an extra entry counts too. A condition that's true for a moment inside a bar can open a trade your backtest never showed. Check it in simulation before you enable the strategy.
Want someone to review it? We check whether your NinjaScript strategy behaves the same on historical data and live.
Review from $90 Analyze NinjaTrader with AISource
Keep reading
Free: The Other Half Workbook. Nine templates for trading with a cool head: your one-page plan, the pre-session checklist, the twelve-patterns test, your size and the bill for your mistakes.
Get the free workbookGet ready for 2027: the Trader Planner. Each day's US releases in New York time, your pre-market routine and a log for every session.
Paperback on Amazon, $16.99 Get the PDF, $9Educational content based on the official NinjaTrader documentation. Not investment advice. Test any change on a simulation account before using it live.