What backtesting is
Backtesting means applying a fixed set of trading rules to historical price data to see how those rules would have behaved. The output is a list of simulated trades and statistics such as net result, drawdown (the fall from a peak in account equity to a later low), win rate and average trade.
A backtest does not predict the future. It only shows whether a rule set made sense on past data under the assumptions you chose. If the assumptions are wrong, the result is wrong.
Leveraged forex and CFD trading can lose money fast. A good-looking backtest does not reduce that risk.
Ready to try it on a real or demo account?
Partner link · trading carries a high risk of loss
How to backtest a trading strategy
A fair forex backtest follows the same discipline every time:
- Write the rules down before testing. Entry, exit, stop-loss, take-profit, position size, which instruments, which sessions, and what happens on news days. If a rule needs your judgement in the moment, it cannot be tested cleanly.
- Choose the data and the period. Include different market conditions: trends, ranges, quiet periods and volatile ones.
- Model costs realistically. This covers spread, commission, swap and slippage.
- Split the data. Keep part of the history untouched for out-of-sample testing.
- Run the test and record every trade. Keep the full trade list, not only the summary.
- Check for overfitting. Use the tests described below.
- Forward test on a demo account before any real money is involved.
You can backtest manually by scrolling through a chart bar by bar and logging trades, or automatically with code. MetaTrader includes a Strategy Tester for Expert Advisors (automated programs). See MetaTrader 5 and algorithmic trading.
Data quality
Bad data produces confident but false results. Check for these problems:
- Gaps and missing bars. Missing data can hide stop-outs or create trades that never could have happened.
- Bid vs ask. Charts usually show bid prices. A long trade opens at the ask, so ignoring the spread flatters buy trades.
- Bar data vs tick data. On bar data, the tester does not know whether the high or the low came first inside a bar. A strategy with a tight stop and a tight target on the same bar can look profitable when the real order of prices would have hit the stop. Tick data or a smaller timeframe reduces this problem.
- Different data sources. Forex has no central exchange, so prices differ slightly between providers. A strategy that only works on one data feed is fragile.
- Time zones and session times. Daily candles and session rules, such as a London breakout or an Asian session range, depend on the server time used.
Trading costs
Costs are where many backtests fall apart, especially for short-term systems.
| Cost | What it is | How it distorts a backtest |
|---|---|---|
| Spread | Difference between bid and ask | A fixed low spread ignores widening at news and session opens |
| Commission | Fee per lot on some account types | Easy to leave out of the tester settings |
| Swap | Overnight financing charge or credit | Matters for swing and position trades; rates change over time |
| Slippage | Fill at a worse price than requested | Stops and market orders in fast markets often slip |
The shorter the holding time, the larger costs are relative to the average trade. A scalping system can turn from positive to negative once realistic spread and slippage are added. Read swap fees and use the calculators to estimate per-trade costs for your own size.
In-sample and out-of-sample testing
In-sample data is the history you use to design and tune the rules. Out-of-sample data is history you keep aside and test only once the rules are final.
If performance collapses on the out-of-sample period, the rules probably fitted noise in the in-sample period. The out-of-sample data stops being useful as soon as you go back, change the rules and test on it again. Repeated peeking turns it into in-sample data.
Walk-forward analysis
Walk-forward analysis repeats the in-sample/out-of-sample idea across the whole history:
- Optimise parameters on a window of past data.
- Test those parameters on the period right after it.
- Move both windows forward and repeat.
- Join all the out-of-sample segments into a single result.
This tests whether the process of choosing parameters works, not just one lucky parameter set. Unstable parameters that jump from window to window are a warning sign.
Overfitting checks
Overfitting means the rules describe past noise rather than a repeatable market behaviour. Ways to check:
- Parameter stability. Change each parameter slightly. If the result collapses, the edge is probably not real. A robust strategy shows a broad area of acceptable results.
- Number of rules. Every extra filter fits the past better and the future worse. Be suspicious of rules added to remove specific losing trades.
- Enough trades. A small number of trades can look good by chance.
- Other markets and periods. Test on related instruments and different years.
- Monte Carlo shuffling. Reorder or resample the trade list to see the range of possible drawdowns, not only the one that happened.
- Look-ahead bias. Make sure no rule uses information that was not available at the time, such as the closing price of a bar that has not closed yet.
- Survivorship and selection bias. Testing many strategies and keeping only the winner gives a result that is partly luck.
How backtests lose money in practice
These are the specific ways a strategy that looked fine on history loses on a live account:
- Costs were underestimated, so a thin edge disappears.
- Stops slipped in fast markets, making real losses larger than tested losses.
- The market regime changed, for example from trending to ranging, and the rules have no filter for it.
- The drawdown was deeper than expected. The backtest showed only one path; the live path was worse, and position size was set too high.
- The trader overrode the rules after losses, so live results no longer matched the test.
- Risky structures such as martingale or grid trading looked smooth in the test until a long adverse move hit them.
Position sizing and drawdown limits are covered in risk management. Sticking to tested rules is covered in trading psychology.
Hypothetical example
Hypothetical, for illustration only. No performance is implied.
A trader tests a moving average crossover on a major pair on the daily chart: buy when a fast average crosses above a slow one, sell on the reverse cross, with a fixed stop-loss.
On the in-sample period, the trader tries many average lengths and finds a combination that looks strong. On out-of-sample data, the same combination shows a much larger drawdown. Neighbouring settings also give weak results. Once swap is added for trades held over several weeks, the result weakens further. The sensible conclusion is that the tuned version is overfitted. The trader should either simplify it and retest on fresh data, or drop it.
After the backtest
A backtest is a filter, not a green light. The next step is forward testing on a demo account, where the rules run on live prices without real money. See also demo accounts and how to write the rules into a trading plan.
A note for traders in Pakistan
Before trading live, understand the local legal position. On platforms: per the SECP, offshore forex/CFD platforms operate without regulatory approval in Pakistan. On protection: per the SECP, offshore platforms have no Pakistani licence or oversight and offer no legal protection or recourse. Details are on law and regulators and regulation and safety.
Frequently asked questions
Is forex backtesting reliable?
It is only as reliable as the data, cost assumptions and rules behind it. Even a careful backtest shows past behaviour, not future results.
Manual or automated backtesting?
Manual testing suits discretionary methods such as price action but is slow and prone to bias. Automated testing is faster and consistent, but it can only test rules that can be coded.
How much history do I need?
Enough to include different market conditions and enough trades to judge the result. Longer-term systems need more years than short-term ones.
What is the most common backtesting mistake?
Leaving out realistic costs, and tuning parameters until the past looks good.
Does a good backtest mean I should trade the strategy?
No. It means the strategy is worth forward testing. Leveraged trading can still lose money quickly.
