Backtesting is testing a trading strategy on historical market data to see how it would have performed in the past. The strategy's rules are applied candle by candle or tick by tick to old prices, as if it had been trading back then, and every simulated trade is recorded. The result shows whether a strategy idea has potential before any real money is put at risk.
How does backtesting work?
- Define the rules exactly: entries, exits, position sizing and risk management, with nothing left to interpretation.
- Collect quality data: historical prices at the right resolution (ticks, minutes or daily), including spreads where possible.
- Simulate realistically: include commissions, spreads, slippage, swap or financing costs, and the order types the broker actually supports.
- Analyse the results: not just the profit, but the risk taken to get it.
- Validate out of sample: test on data the strategy was not optimised on, before trading it live.
Key backtest metrics
- Net profit and return: the result after all costs.
- Maximum drawdown: the largest peak-to-trough decline; often more important than the return.
- Sharpe ratio: return relative to volatility.
- Profit factor: gross profit divided by gross loss.
- Number of trades and win rate: enough trades for a statistically meaningful result, and how often the strategy wins.
Common backtesting mistakes
The most common mistake is overfitting: tuning parameters until the strategy fits historical noise perfectly, so it fails on new data. Other pitfalls are look-ahead bias (using information that wasn't available yet at the time of the trade), survivorship bias (testing only on instruments that still exist today), and unrealistic costs (ignoring spreads and slippage, which can turn a profitable short-term strategy into a losing one). Walk-forward analysis, out-of-sample testing and Monte Carlo simulation help reveal whether results are robust.
Backtesting tools
MetaTrader has a built-in Strategy Tester for Expert Advisors, TradingView has a strategy tester for Pine Script, and Python libraries such as backtrader and vectorbt are popular for research. For strategies that need more realistic simulations, larger data sets or multiple markets, a custom backtesting platform is often the better choice. See our custom backtesting platforms, backtesting for algorithmic trading and what is algorithmic trading.
Frequently Asked Questions about Backtesting
Does a good backtest guarantee future profits?
No. A backtest shows how rules would have behaved on past data. Markets change, and a backtest that is overfitted or ignores costs can look much better than live results will be.
How much historical data do I need?
Enough to include different market conditions (trends, ranges, high and low volatility) and enough trades for meaningful statistics. For many strategies, that means several years and at least a few hundred trades.
What is the difference between backtesting and forward testing?
Backtesting uses historical data; forward testing (or paper trading) runs the strategy in real time on a demo or small account. Forward testing reveals execution issues that a backtest can't.
What is walk-forward analysis?
A method in which the strategy is optimised on one period and then tested on the next unseen period, repeated across the data. It gives a more honest picture of how the strategy will behave on new data.