Simulation and testing

3 min read

NinjaTrader walk-forward optimization: periods and results

Train parameters on one segment, then test them on later data. Learn which settings control the windows and where each period’s results appear.

Conceptual illustration of teal training windows followed by amber test windows moving forward across three rows of calendar tiles.

Quick answer

NinjaTrader walk-forward optimization selects parameters on an earlier data segment, then evaluates them on the following segment. The windows advance and repeat. Judge the later test results separately from the results used to select parameters.

Set the training and test windows

Open New > Strategy Analyzer from the Control Center. Choose your strategy, instrument, bar interval and historical date range. Data for that range must be available from your provider or local storage.

Set Backtest type to Walk Forward Optimization. The two period fields use days:

SettingRole
Optimization period (days)Earlier, in-sample window used to choose parameters.
Test period (days)Following, out-of-sample window evaluated with those parameters.

Read each test period’s result

The results grid lists each test interval’s dates and selected parameter combination. Right-click a row and choose View Optimization Results to inspect its earlier search. Keep best # results controls how many optimization candidates are retained.

Check strategy code that depends on trade history

NinjaTrader’s optimization documentation says historical Trade-object storage is disabled by default in this context to save memory. Code that reads SystemPerformance.AllTrades.Count therefore needs attention: without retained Trade objects, that count cannot supply the expected history.

When the strategy requires those objects, its developer can enable IncludeTradeHistoryInBacktest in OnStateChange() during State.Configure. Retaining detailed history increases memory use. This setting is separate from the number of top optimization results displayed.

Out-of-sample is still historical testing

The later window still uses historical data and simulated fills. It does not become a live brokerage execution or a Playback session merely because its data was excluded from parameter selection.

NinjaTrader documents different fill processes for historical backtests, simulation with incoming data, and live orders. Check fill assumptions separately; changing the training window does not resolve those differences.

Official sources

Platform monitoring

Keep platform health in view

Ninja Watchdog monitors NinjaTrader and supports recovery after platform interruptions. Email alerts are available today; SMS and WhatsApp alerts are coming soon.

Explore the free trial