Guide · 7 min read

How to Backtest a Trading Bot

How to run a meaningful backtest in MetaTrader 5's Strategy Tester — modeling realistic costs, avoiding overfitting, and reading the results correctly.

A backtest is only as useful as the assumptions behind it. Running one incorrectly — ignoring spread, testing too short a period, or over-optimizing to fit the data — produces numbers that look great and mean very little. Here's how to run one that actually tells you something.

1. Use tick data, not just OHLC bars

MT5's Strategy Tester offers several modeling modes. 'Every tick based on real ticks' is the most accurate — it simulates price movement within each bar rather than assuming a straight line between open and close, which matters enormously for strategies with tight stops or intrabar logic.

2. Model realistic spread, commission, and slippage

The Strategy Tester lets you set a fixed or dynamic spread and broker commission. Always test with values close to what your actual broker charges — a backtest run with zero spread will overstate performance, sometimes dramatically, for strategies that trade frequently.

3. Test across a long enough period, and multiple regimes

A few months of data isn't enough to draw conclusions — favor several years covering trending, ranging, and high-volatility periods. A strategy that only performs well in one type of market regime will tell you that clearly if the test period is long enough to include several.

4. Watch for overfitting during optimization

MT5's built-in optimizer can test thousands of parameter combinations and will always find one that looks great on the historical data it was given — that's not the same as a robust strategy. A parameter set that performs only slightly better than its neighbors is more trustworthy than one that's a dramatic outlier; a cliff-edge optimum is a red flag for overfitting.

5. Reserve out-of-sample data

Split the historical data: optimize parameters on one period (in-sample), then run the exact same, unchanged settings on a separate later period the optimizer never saw (out-of-sample). A strategy that holds up out-of-sample is far more credible than one only validated on the data it was tuned against.

Frequently asked questions

How many trades do I need in a backtest to trust the results?

There's no exact threshold, but a few dozen trades is not enough to draw reliable conclusions. Favor backtests with several hundred trades or more, spread across different market conditions.

Does a great backtest guarantee good live performance?

No. A rigorous backtest with realistic costs and out-of-sample validation is the best available evidence before going live, but markets evolve and past performance — backtested or real — never guarantees future results.

Related terms

Related guides

See Backtested Algorithms on the Marketplace