strategies.ninja
strategies.ninja / guide 02 of 06

Guide 02

How to backtest a strategy properly

A backtest runs your rules over historical data to see what would have happened. Done carelessly it produces a flattering story. Done carefully it is a filter that removes bad ideas cheaply.

HISTORY, OLDEST TO NEWEST IN-SAMPLE: BUILD AND TUNEOUT-OF-SAMPLE LOOK AS MUCH AS YOU LIKELOOK ONCE WALK-FORWARD: SLIDE THE WINDOW, STITCH THE TEST BLOCKS OPTIMISETESTOPTIMISETESTOPTIMISETEST STITCHED OUT-OF-SAMPLE RESULT
FIG. 03: Data split. Build on the in-sample block, then judge on data the strategy has never seen. Walk-forward repeats the process on a sliding window.

01What a backtest can and cannot tell you

A backtest answers one narrow question: did these exact rules, with these exact settings and cost assumptions, make or lose money on this particular stretch of history? It cannot tell you the future. Its best use is rejecting ideas: if a rule cannot survive a careful historical test, there is little reason to risk money on it.

Treat a good result as "not yet disproven", never as proof.

02Split your data: in-sample and out-of-sample

The most important habit is to separate the data you build on from the data you judge on.

If you keep adjusting the strategy after peeking at the out-of-sample result, that data has quietly become in-sample, and the test no longer means much. Decide your acceptance criteria before you look, for example a maximum drawdown you can tolerate and a minimum number of trades.

03Walk-forward analysis

Walk-forward testing automates the in-sample and out-of-sample idea repeatedly. You optimize on one window of history, test the chosen settings on the next window that follows, then slide both windows forward and repeat. Stitching the out-of-sample segments together gives a result that never relied on knowing the future settings.

NinjaTrader's Strategy Analyzer offers walk-forward optimization, so you can run this inside the platform. It is slower than a single backtest and it still cannot rescue a strategy with no real edge, but it is a much stricter test than one optimized run.

04Costs: commissions and slippage

Many backtests look good only because costs are left out. Include them from the first run.

A useful check is to double your slippage assumption and see whether the strategy survives. If a small cost change turns it negative, the edge was thinner than it looked.

05Enough trades to mean something

A handful of winning trades is an anecdote. Small samples are dominated by luck, and a short run of results can look excellent or terrible by chance. There is no single magic number, but more independent trades give you more confidence, and a strategy that only trades a few times a year needs a long history to judge. Also check that results are not concentrated in one lucky period or a few outsized trades.

06Avoid look-ahead bias and other traps

When a backtest looks acceptable, the next step is not real money but forward testing.

Read thisEducational content only, not financial advice. Futures trading involves substantial risk of loss. Backtested and hypothetical results have inherent limitations, and past performance does not guarantee future results.

FAQFrequently asked questions

How many trades do I need in a backtest?

There is no universal number. More trades give more reliable statistics, and results should not depend on a few outsized trades. Strategies that trade rarely need much longer histories.

What is out-of-sample testing?

Testing a finished strategy on data that was not used to build or tune it, ideally only once, to see whether the results hold on unseen history.

Does a good backtest mean the strategy will work live?

No. A backtest is a simulation under assumptions. Past performance does not guarantee future results, and live trading adds slippage, data and execution differences.

Which slippage should I assume?

Use what you have actually experienced in the markets and sessions you trade, then test with a harsher assumption to see how fragile the result is.