How to Backtest a Trading Strategy Properly
TL;DR: A backtest is only as honest as the assumptions behind it. Skipping realistic costs, using poor-quality data, or testing on the same data you optimised on will produce results that look great on screen and fail in live trading. This guide walks through every variable that matters.**
Why Most Backtests Lie to You
Running a backtest feels productive. Numbers come back, the equity curve climbs, and confidence builds. The problem is that nearly every shortcut you take during testing adds invisible optimism to the result. By the time you go live, that optimism compounds into drawdowns you never expected.
The goal of a proper backtest is not to prove a strategy works. It is to find out whether it might work, under conditions that resemble actual trading as closely as possible. That distinction changes how you approach every step.
Setting Up Realistic Trading Costs
Spread
Spread is the most commonly underestimated cost in retail forex backtests. Many traders set a fixed spread of one or two pips and move on. In practice, spread varies by session, by volatility, and by broker. During the London open or around major news events, a normally tight pair can widen considerably.
If you are testing a scalping strategy on EUR/USD, a fixed one-pip spread may be defensible during peak hours. But if that same strategy fires trades at 3 a.m. or around NFP, you need to model wider spreads for those periods. At minimum, use a spread value that reflects off-peak conditions rather than the tightest quote your broker occasionally offers.
In MetaTrader's Strategy Tester, you can set a custom spread under the "Spread" field in points. Use your broker's average spread as a floor, not as the typical value.
Slippage
Slippage is the difference between the price you expect to fill at and the price you actually get. It affects market orders more than limit orders, and it scales with order size and liquidity. For retail forex traders running small lots, slippage is usually minor but not zero.
A conservative approach is to add two to five points of slippage to every market order entry and exit. MetaTrader's Strategy Tester has a slippage field precisely for this. If you never use it, your fills are simulated as perfect, which they are not.
Commission
If your broker charges a round-turn commission, include it. This sounds obvious, but traders running backtests on demo accounts or using broker data sometimes forget that live accounts carry commissions that demo accounts may not reflect accurately. A strategy trading ten times per day with a $7 round-turn commission on a $10,000 account is paying roughly $70 per day in fixed costs before a single pip of profit.
Model commissions as close to your actual account as possible. If you plan to trade on a raw-spread ECN account, use those commission figures. If you plan to use a dealing-desk account with wider spreads and no commission, model that instead. Mixing the two produces a result that matches neither.
Tick Data vs OHLC: Why It Matters
What OHLC Data Misses
Standard MetaTrader backtests on M1 or higher timeframes use OHLC bars. Each bar gives you four price points: open, high, low, and close. The problem is that a bar tells you two of those happened but not which came first. If a bar has a high above your take-profit and a low below your stop-loss, the tester has to guess which was hit first. By default, it assumes the order that is better for your strategy, which introduces a measurable optimistic bias.
For strategies with tight stops and targets, this matters a great deal. A strategy that looks profitable on OHLC data can turn negative on tick data simply because the bar-order assumption was consistently wrong.
Tick Data Backtesting
Tick data records every price change rather than summarising it into bars. Testing on tick data eliminates the bar-order problem because fills are simulated against the actual price sequence. The downside is that high-quality tick data is harder to source and backtests run more slowly.
For MetaTrader 4 and 5, services like Dukascopy and TickStory provide historical tick data you can import. MetaTrader 5's native Strategy Tester supports tick-by-tick simulation when you use "Every tick based on real ticks" in the testing mode dropdown. This is the most accurate mode available in the platform.
If your strategy trades on daily or four-hour charts with wide stops and targets, OHLC backtests are probably acceptable. If your strategy is intraday with stops under ten pips, use tick data.
how-to-import-tick-data-metatrader
How Much Data Do You Actually Need?
Sample Size Basics
A backtest on fifty trades tells you almost nothing. At fifty trades, normal statistical variance can make a losing strategy look profitable or a profitable strategy look like a disaster. You need enough trades for the results to be meaningful rather than lucky.
A commonly cited minimum is two hundred to three hundred completed trades. That number is not arbitrary. Below it, your strategy's edge (if it has one) cannot be reliably separated from noise. The more variables your strategy has, the more trades you need to have confidence the results reflect the rules rather than the sample.
If your strategy trades infrequently on higher timeframes, running data from the last two or three years may only produce thirty or forty trades. In that case, extend your data window back further, even if data quality degrades slightly at the far end. Sixty trades on ten years of data is still sixty trades, but at least you are seeing the strategy's behaviour across multiple market regimes.
Market Regime Coverage
A backtest that only covers a trending bull market will not tell you how a mean-reversion strategy behaves in a choppy range. A sample that only includes low-volatility periods underestimates how a breakout strategy performs when volatility spikes. Aim for data that includes trending periods, ranging periods, and at least one period of sustained elevated volatility.
In-Sample vs Out-of-Sample Testing
What the Distinction Means
In-sample data is the data you used to develop and optimise your strategy. Out-of-sample data is data the strategy has never seen during development. The out-of-sample test is the only result that provides meaningful evidence of forward performance.
When you optimise a strategy entirely on one data set, the parameters you end up with are partly correct and partly shaped by the specific noise in that data set. If those parameters are then tested on the same data to generate a final result, you are measuring how well the strategy fits history, not whether it has a genuine edge.
A Practical Split
A common approach is to use roughly seventy percent of your historical data for development and optimisation, and reserve thirty percent for the final out-of-sample test. The reserved data should not be touched during development. You look at it once, run the strategy on it, and accept what you see.
If the out-of-sample result is substantially worse than the in-sample result, one of two things is true: the strategy was overfit to the in-sample data, or the market conditions in the two periods differed enough that the edge does not persist across regimes. Either way, you know something important before risking real capital.
Walk-forward testing takes this further by dividing the data into multiple rolling windows, each with its own in-sample and out-of-sample segment. It is more rigorous but also more time-consuming. For most retail traders, a single clean in-sample and out-of-sample split is a significant improvement over testing on all available data at once.
metatrader-5-strategy-tester-guide
What Is Look-Ahead Bias in Backtesting?
Look-ahead bias occurs when a backtest uses information that would not have been available at the time the trade signal was generated. It is one of the most common mistakes in manual strategy testing and in poorly coded indicators.
A simple example: you draw a support level at what turned out to be a major swing low and test entries from that level. The problem is that the swing low was only identifiable as such after price moved away from it. At the moment the entry would have been taken, that level was not yet confirmed as significant. Your backtest is using future information to define the setup.
In indicator coding, look-ahead bias often comes from applying a function that recalculates historical values as new bars form. An indicator that repaints its signals is the classic case. A signal appears on a past bar during live trading but would not have appeared at that time if you were watching in real time. Backtesting such an indicator produces extraordinary results that are essentially fictional.
Before backtesting any indicator-based strategy, verify that the indicator does not repaint. In MetaTrader, you can do this by checking whether signal arrows on completed bars move or disappear as new bars form. If they do, the backtest results cannot be trusted.
What Is Survivorship Bias in Strategy Testing?
Survivorship bias is more relevant to systems built around selecting instruments than to single-pair strategies, but it is worth understanding. If you build a strategy that trades the "best performing" currency pairs from the last five years and backtest only on those pairs, your sample is pre-selected for success. The pairs that failed, were delisted, or became untradeable during that period are not in your test.
In forex trading, survivorship bias shows up most clearly when traders select pairs based on historical performance and then test on that selection. The pairs that behaved well look even better in hindsight because you already filtered out the ones that did not.
The fix is straightforward: define your instrument selection rules before looking at performance data, or test across a broad enough universe that cherry-picking individual instruments does not dominate the result.
Common Backtest Mistakes at a Glance
- Using default or zero spread instead of realistic broker spread
- Ignoring commission entirely on commission-based accounts
- Testing on fewer than two hundred trades and treating the result as definitive
- Optimising and then testing on the same data set
- Using indicators that repaint without checking first
- Assuming a strategy that worked on one pair or one time period generalises automatically
- Not checking what happens to results when spread is doubled to simulate adverse conditions
FAQ
Q: How do I know if my MetaTrader backtest spread is realistic? A: Log into your live or demo account and check the spread on the pair you want to test at different times of day, particularly during off-peak hours and around news releases. Use the widest typical spread as your test value, not the tightest.
Q: Is backtesting in MetaTrader 4 reliable enough to use? A: MT4's Strategy Tester has limitations, particularly around bar modelling on M1 and above. For strategies that depend on precise intraday entries, MT5 with tick data is more reliable. For daily and four-hour systems, MT4 is usually adequate if you model costs correctly.
Q: How many years of data should I use to backtest a forex strategy? A: There is no fixed answer, but five to ten years of data covering different market conditions is a reasonable baseline for most strategies. The more important constraint is trade count. If five years only gives you eighty trades, extend the data window rather than accepting an underpowered sample.
Q: What is the difference between overfitting and a well-optimised strategy? A: A well-optimised strategy has a small number of parameters, and its performance holds up across different time periods and instruments without requiring constant re-optimisation. An overfit strategy has parameters tuned so precisely to historical data that minor variations in conditions cause the edge to collapse. The out-of-sample test is the primary way to distinguish between the two.
Q: Can I backtest a manual trading strategy without coding an Expert Advisor? A: Yes. MetaTrader has a manual backtesting mode using the Strategy Tester in visual mode, and dedicated tools like Forex Tester allow you to replay historical price action bar by bar and place trades manually. Manual backtesting is slower but valid if done with discipline and consistent rules.
best-practices-forward-testing-demo-account
The Bottom Line
Backtesting is not about producing a good-looking equity curve. It is about stress-testing an idea against realistic conditions before real money is involved. Model your costs accurately, use the right data quality for your strategy's timeframe, make sure your sample is large enough to be statistically meaningful, and always reserve data your strategy has never touched for the final test.
A backtest that survives honest scrutiny is worth taking forward to demo trading. One that only works under optimistic assumptions is better caught in testing than discovered after a run of live losses.