NinjaTrader

Backtesting in NinjaTrader

Run your first backtest in the Strategy Analyzer

NinjaTrader's Strategy Analyzer is its built-in backtester — the NinjaTrader equivalent of the MT5 Strategy Tester. This guide shows how to point it at a compiled NinjaScript strategy, set the instrument and date range, run the test, and read the results.

Backtesting works on strategies, not indicators. Make sure HorizonAI generated a strategy (a class deriving from Strategy, with entry/exit calls) and that it compiled cleanly in the NinjaScript Editor first. See Using the NinjaScript Editor.

NinjaScript has no in-app backtest in HorizonAI — the app's Backtest tab is for MQL5, Python, and (soon) Pine Script only. For NinjaScript, the Strategy Analyzer below is where you backtest.

1) Open the Strategy Analyzer

From the Control Center, go to New → Strategy Analyzer. The Strategy Analyzer window opens.

2) Select your strategy

  1. In the left-hand panel, make sure the mode is set to Backtest (rather than Optimization or Walk Forward).
  2. Under the strategy selector, choose your compiled strategy by name from the list.
  3. Click the Parameters (…) control if you want to adjust the strategy's inputs (lot/contract size, indicator lengths, and so on).

If your strategy isn't in the list, it either didn't compile or wasn't created as a Strategy. Recompile in the NinjaScript Editor (F5) and confirm the class derives from Strategy.

3) Set the instrument and data series

In the Data Series section:

  • Instrument — pick the market you want to test (for futures, choose the specific contract, e.g. ES 03-26, or a continuous @ES series for tests spanning expirations).
  • Type / Value — set the bar type and size for your data series (for example a 5-minute or daily series).
  • Start date / End date — set the historical period to test over.
  • Trading hours — apply a session template if your strategy is session-sensitive.

4) Set capital, commission, and slippage

For realistic results, adjust the account and cost settings before running:

  • Starting capital — set it to something like your intended account size.
  • Commission — NinjaTrader defaults to $0; set it to your broker's real commission.
  • Slippage — add a tick or two of slippage, especially for strategies that use market orders.

Leaving commission at $0 and slippage at 0 makes almost any strategy look better than it is. Set them to realistic values before trusting the numbers.

5) Run the backtest

Click Run. When it finishes, review the result tabs:

  • Overview / Performance — summary stats: net profit, profit factor, max drawdown, win rate.
  • Trades — every trade the strategy took.
  • Chart — the equity curve and trades over the test period.

No trades after a run? Widen the date range, try a different instrument or timeframe, and double-check that your entry conditions can actually trigger. If the logic looks wrong, describe what you expected back in HorizonAI and ask it to adjust the strategy.

Next steps

  • Iterate the strategy's inputs and re-run to compare reports.
  • Once you're happy, apply the strategy to a chart on your simulation account to watch it trade in real time (see Using the NinjaScript Editor).

Understanding your results

Related Guides