Method and analysis

How to Backtest a Futures Strategy Without Fooling Yourself

A backtest replays a set of rules on past data. Done carelessly, it mostly measures how well the rules were fitted to that data. Here is how to build one that can at least fail honestly.

Published · Updated · 8 min read

Key takeaways

  • A backtest applies fixed, written rules to historical data and records every simulated trade; its value depends on the data, the fill assumptions and how many choices were tuned on that same data.
  • The classic traps are look-ahead bias, data errors, overfitting through optimisation, selection among many variants, and ignoring commissions and slippage.
  • Keep data the rules have never seen: an out-of-sample period, or a walk-forward test that optimises on one window and tests on the next.
  • In NinjaTrader 8 the Strategy Analyzer runs backtests, optimizations and walk-forward optimizations; fills are simulated from bar data, so commission, slippage and fill settings deserve attention.
  • Even a clean backtest is hypothetical: CFTC rules require advisers who show simulated results to warn that they do not represent actual trading.

How to backtest a futures strategy: the short answer

To backtest a futures strategy is to apply a fixed set of rules, written precisely enough for a computer to follow, to historical data, and to record every trade those rules would have taken, with realistic costs. The output is a list of hypothetical trades and the statistics derived from it: net result, drawdown, number of trades, average trade.

The hard part is not running the test; platforms such as NinjaTrader 8 do that quickly. The hard part is making sure the result means something. Most misleading backtests are not dishonest: they come from reasonable-looking choices that leak information from the future, tune the rules to noise or assume fills the market would not have given. The steps below are designed to catch those leaks before they reach a live account.

Step one: rules and data you can trust

Write the rules before looking at any result: entry, exit, stop, target, position size, the sessions traded, and what happens around rollover and scheduled news. A rule that needs judgement, such as entering when the trend looks strong, cannot be backtested until it becomes a measurable condition.

Then check the data, because futures data raises specific questions. A continuous contract stitches successive expiries together, and the way prices are adjusted at each roll changes the past: a back-adjusted series suits rules based on moves in points, not rules based on absolute price levels from years ago. Bad ticks, missing sessions and changes in trading hours create trades that could never have happened. For rules that depend on what happened inside a bar, resolution matters too: a one-minute bar does not say whether its high came before its low.

  • Use data from the same source and session template you will trade with.
  • Inspect outliers: a single bad print can produce the best trade of the whole test.
  • Decide how rollover is handled and check the trades around each expiry.
  • Keep a record of the data period and settings of every test you run, including the ones you discard.

The biases that make backtests look better than reality

Look-ahead bias uses information that was not available at the moment of the decision. Its common forms are subtle: a rule that reads the close of a bar to enter at the open of that same bar, a daily high or low used before the day has finished, an indicator whose past values change as new data arrives, or economic data used at its revised value rather than at its first release.

Overfitting, or curve fitting, comes from tuning too many parameters on the same data. Every extra input and every optimisation run raises the chance that the best result fits the noise of that particular sample. A strategy with many inputs tuned to precise values, whose results collapse when one value moves slightly, has learned the past rather than a market behaviour.

Selection bias is the same problem one level up. Test twenty ideas, keep the one that worked, and its backtest overstates its edge, because luck was part of the selection. The honest count is the number of variants tried, not the number kept.

  • Look-ahead: any value used before it could have been known.
  • Overfitting: parameters tuned to the noise of one sample.
  • Selection: keeping the best of many tests without discounting the search.
  • Survivorship: testing only on markets or contracts chosen because they are popular or still exist today.
  • Optimistic fills: limit orders filled on a touch, market orders filled at the signal price.

Costs, slippage and fills: where short-term edges disappear

A backtest without costs describes price, not trading. Commissions and fees are charged per contract on every round turn, and slippage is paid on market and stop orders. For short-term strategies these costs can exceed the average gross trade and turn an apparently profitable test into a losing one; the arithmetic is shown in what scalping futures really involves.

Fill assumptions deserve the same attention. A limit order resting at a price is not necessarily filled when price touches it, because other orders were ahead of it in the queue. A test that fills every touch is optimistic; requiring price to trade through the limit is more conservative. Market and stop orders should be assumed to fill worse than the signal price, by at least a tick in normal conditions and by more around releases.

Data resolution interacts with fills. If one bar contains both the stop and the target, the bar alone does not say which was hit first. The test must assume an order of events, and a convenient assumption can quietly turn losers into winners.

Out-of-sample and walk-forward testing

The most useful protection against overfitting is data the rules have never seen. Split the history: develop and tune on one part, the in-sample period, then test once on a later part, the out-of-sample period. If performance collapses out of sample, the in-sample result was mostly fit. And if you go back and adjust the rules after seeing the out-of-sample result, that period has become in-sample too.

Walk-forward analysis repeats the idea through time. Parameters are optimised on one window and tested on the window that follows; then both windows move forward and the process starts again, and the test windows are joined into one out-of-sample record. NinjaTrader describes its walk-forward optimization in the same terms: performance is evaluated on the test data, not on the data used in the optimization, with an Optimization period and a Test period set in days.

Two more checks are cheap. Sensitivity: change each parameter a little and see whether results degrade gradually or fall off a cliff. Different conditions: run the same rules, without re-tuning, on another period or a closely related market. A robust idea usually survives both in a weaker form; a fitted one usually does not.

Hypothetical example — Illustrative figures, not market data. A rolling schedule: each step optimises on one window, then tests on the period that follows.
StepOptimization periodTest period
1Months 1 to 12Months 13 to 15
2Months 4 to 15Months 16 to 18
3Months 7 to 18Months 19 to 21

Backtesting in NinjaTrader 8: Strategy Analyzer basics

In NinjaTrader 8, backtests run in the Strategy Analyzer, opened from the New menu of the Control Center. It tests NinjaScript strategies, whether written by hand or generated with the Strategy Builder. The Backtest type setting offers Backtest, Optimization, Walk Forward Optimization and Multi-Objective Optimization; you then choose the strategy, the instrument, the data series, the start and end dates and the trading hours template, and click Run.

Several settings decide how realistic the result is. They are worth checking before every run, because the defaults favour speed rather than caution.

  • Include commission: enables or disables commissions in the performance results; the rates come from a commission template.
  • Slippage: a number of ticks applied to market, stop market and Market-if-touched fills; it defaults to zero and does not apply to limit orders.
  • Order fill resolution: Standard, the default, simulates fills from each bar’s open, high, low and close by splitting the bar into virtual bars; High uses a finer secondary series for fills, at the cost of longer tests.
  • Fill limit orders on touch: when enabled, a limit order counts as filled on a single touch of its price, the optimistic assumption described above.
  • Exit on session close: when enabled, open positions are closed on the last bar of each session.

NinjaTrader’s help guide also explains why backtest and real-time results differ: historical fills are based only on the open, high, low and close of each bar, while real-time fills depend on incoming market data and volume, and during a backtest a strategy is processed at the close of each bar rather than tick by tick. Order fill resolution cannot be combined with Tick Replay, which matters for order flow strategies; the guide to Tick Replay in NinjaTrader 8 explains that setting. Reviewing the Trades and Executions displays, not only the summary, shows whether individual fills look plausible.

Reading the result honestly

A finished test produces a report, and trading statistics explained covers each of its figures. A few habits keep the reading honest. Look at the number of trades before any ratio, because a handful of trades says almost nothing. Look at the maximum drawdown and the longest losing period, and ask whether you would really have kept trading through them. Compare the average trade with your costs per trade: if the margin is thin, small changes in slippage erase it. Check that the result does not depend on a few outsized trades, and size any live use from a per-trade risk, as described in futures trading risk management.

Then treat the result as what it is: hypothetical. Under CFTC advertising rules, commodity trading advisors and pool operators who present simulated or hypothetical performance must warn that such results have inherent limitations, do not represent actual trading, may have under- or over-compensated for market factors such as lack of liquidity, and are generally designed with the benefit of hindsight. The same caution applies to your own tests. The step after a backtest is forward testing in simulation, then small size, with the backtest as a benchmark to compare against rather than a forecast.

Put it into practice

Frequently asked questions

How much data do I need to backtest a futures strategy?

There is no fixed amount. What matters is the number of trades and the variety of conditions they cover: quiet and volatile periods, trends and ranges, and the sessions you intend to trade. A test with few trades, or with a single market regime, cannot separate an edge from luck.

What is the difference between backtesting and forward testing?

A backtest applies the rules to past data. A forward test applies them to new data as it arrives, in simulation or with small size, so nothing can be tuned to it in advance. Forward results take longer to collect but are much harder to fool.

Does a walk-forward test prove that a strategy works?

No. It removes one source of self-deception, tuning and testing on the same data, but the choice of windows, of the optimisation target and of the strategies tested can still be overfitted. It also remains a simulation, with simulated fills.

Can I backtest a strategy that uses order flow?

Only with data that contains every trade and the bid and ask at the moment of each trade. In NinjaTrader that means Tick Replay, which the help guide says cannot be combined with Order fill resolution. Queue position and the history of market depth remain hard to simulate, so treat order flow backtests with extra caution.

Why do my live results differ from the backtest?

Common reasons include fills that bar data could not reproduce, slippage and costs that were missing or underestimated, rules that used information too early, and differences between historical and real-time data. NinjaTrader’s help guide lists several of these discrepancies.

Sources

  1. Strategy Analyzer (NinjaTrader 8) — NinjaTrader Help Guide
  2. Backtest a Strategy (NinjaTrader 8) — NinjaTrader Help Guide
  3. Walk Forward Optimization (NinjaTrader 8) — NinjaTrader Help Guide
  4. Understanding Historical Fill Processing (NinjaTrader 8) — NinjaTrader Help Guide
  5. Discrepancies: Real-Time vs Backtest (NinjaTrader 8) — NinjaTrader Help Guide
  6. 17 CFR § 4.41: Advertising by commodity pool operators, commodity trading advisors, and the principals thereof — Legal Information Institute, Cornell Law School

Read next

All articles in this section : Method and analysis →

Written with the help of AI tools from official sources, then checked (figures, dates, sources) following our methodology. Methodology · Editorial policy · Report an error

Educational content. These indicators are not investment advice and guarantee no result. Futures trading involves a risk of loss that can exceed the initial investment. Terms of use · Disclaimers