CFDs and forex are complex instruments and come with a high risk of losing money rapidly due to leverage. Risk disclosure

Backtesting a Trading Strategy

This guide explains how backtesting works, how to run a fair forex backtest, and the common ways a backtest misleads traders and leads to real losses.

Extrade Pakistan editorial team ·

On this page
  1. What backtesting is
  2. How to backtest a trading strategy
  3. Data quality
  4. Trading costs
  5. In-sample and out-of-sample testing
  6. Walk-forward analysis
  7. Overfitting checks
  8. How backtests lose money in practice
  9. Hypothetical example
  10. After the backtest
  11. A note for traders in Pakistan
  12. Frequently asked questions

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.

Past data (tuned)New datastart
Over-fitting: a strategy tuned to past data looks smooth on that data and often fails on data it has not seen. Test on a separate period and on a demo first. Illustrative example: made-up numbers for learning, not real prices or a broker's conditions.

How to backtest a trading strategy

A fair forex backtest follows the same discipline every time:

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:

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:

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:

How backtests lose money in practice

These are the specific ways a strategy that looked fine on history loses on a live account:

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.

Sources

  1. Securities and Exchange Commission of Pakistan (press release, 09.04.2025) · secp.gov.pk › Press Release SECP Cautions Public Against Illegal Offshore Trading an — checked 2026-11-11

Related pages