Black Friday, until December 2: FONDEOREAL gives 30% off the 50K, 20% off the 100K and 10% off the 150K at FTMO Futures. See the offer →

Lab · November 2026 · 3 min read

NinjaTrader 8 Calculate: OnBarClose vs OnEachTick

What OnBarClose, OnEachTick and OnPriceChange do in NinjaTrader 8, the historical data trap and how to choose, based on the official guide.

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.

ModeWhen it runsKeep in mind
OnBarCloseOnce, at the close of the barThis is the default
OnEachTickOn every tickIt can be CPU intensive
OnPriceChangeWhen price changes inside the bar, or when it closesIt can miss volume updates at the same price
On this page
  1. The historical data trap
  2. Watch out for volume
  3. Indicators inside a strategy
  4. How to choose
  5. Source

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

  1. Start with OnBarClose if your signal is decided at the close.
  2. Use OnPriceChange if you need to react to price and don't rely on every volume update.
  3. Keep OnEachTick for logic that truly needs every tick, and watch your CPU.
  4. Only set the value in State.SetDefaults or State.Configure.
  5. 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 AI

Source

Keep reading

Practise an evaluation, freeAll 91 articles →

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 workbook

Get 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, $9

Educational content based on the official NinjaTrader documentation. Not investment advice. Test any change on a simulation account before using it live.