How to backtest a forex strategy without fooling yourself
A backtest can tell you a strategy is worth testing further. It cannot tell you it will work. Here is how to run one honestly, from rules to forward test.
- Backtesting applies fixed, written rules to historical prices to see how a strategy would have behaved, including costs.
- Rules must be specific enough that two people would take exactly the same trades from the same chart.
- Overfitting is the main danger: the more you tweak settings to fit the past, the less the result tells you about the future.
- Always keep an out-of-sample period you never optimise on, and follow the backtest with a forward test.
- Judge results by expectancy after costs, drawdown and number of trades, not by the final balance.
Backtesting means applying a strategy's exact rules to historical price data to see how it would have performed, trade by trade, including spreads, commissions and swaps. Done properly, it tells you whether an idea is worth testing further and what a bad run looks like. It does not tell you the strategy will work in future, and a backtest that looks too good is usually a sign of a mistake rather than a discovery.
This guide walks through the process step by step: writing testable rules, choosing data, running a manual or automated test, accounting for costs, reading the results, and the traps that make backtests look better than reality. It finishes with forward testing, which is where a backtest either earns your confidence or loses it.
What a backtest can and cannot tell you
A backtest answers a narrow question: if I had followed these exact rules on this data, with these costs, what would have happened? That is useful. It can show that an idea you liked has negative expectancy once spreads are included, that a strategy needs a much wider stop than you assumed, or that the drawdowns are deeper than you could stomach.
What it cannot do is predict. Markets change. Volatility regimes shift, central banks change policy, spreads widen or narrow, and the patterns a strategy relied on can fade. Past performance is not a reliable guide to future results, and that applies with extra force to performance that was never real in the first place.
Treat a backtest as a filter. Strategies that fail a fair backtest can be discarded cheaply. Strategies that pass move on to forward testing with small or simulated size. Nothing should go straight from a spreadsheet to full position size.
Step 1: write rules that leave no room for judgement
The most common reason backtests mislead is vague rules. "Buy pullbacks in an uptrend" is an idea, not a rule. You need definitions specific enough that two people looking at the same chart would take the same trade at the same price.
A testable rule set covers:
- Market and timeframe: which instruments, which chart timeframe, and which hours.
- Trend or condition filter: for example, "the 50-period EMA is above the 200-period EMA on the 4-hour chart". See trend following and moving averages for how these filters work.
- Entry trigger: the exact event that opens a trade, such as "a 1-hour candle closes back above the 20 EMA after touching it".
- Entry order: market order at the next candle open, or a limit or stop order at a specific price. The order types guide covers the options.
- Stop loss: a precise level, for example "1.5 × the 14-period ATR below entry" or "five pips below the most recent swing low". Our guide on where to put a stop loss explains the common methods.
- Exit: a fixed target, a trailing stop, a time exit, or a combination.
- Position size: normally a fixed percentage of the account per trade, calculated from the stop distance as described in position sizing.
- What you do not trade: for example, no new entries within 30 minutes of a high-impact release on the economic calendar, or no trades on Friday afternoons.
Write the rules down before you look at any results. If you find yourself adding "except when" clauses during the test, stop, record the new rule, and restart the test from the beginning with it included.
Step 2: choose your data and test period
Your test is only as good as the data behind it.
- Use enough history. Aim for a period that includes different conditions: trending and ranging phases, quiet and volatile periods. For a strategy on the 1-hour chart, several years is a reasonable starting point. A test run only during one strong trend will flatter any trend-following system.
- Use enough trades. A few dozen trades tells you very little. A hundred or more starts to be meaningful; several hundred is better. If a strategy only produces ten trades a year, you need a long history or several instruments to judge it.
- Know what the data is. Most retail charting data shows bid prices only. If your strategy buys at the ask, you need to add the spread yourself. Some platforms let you test with recorded tick data including variable spreads, which is more realistic for short-term strategies.
- Watch for gaps and bad ticks. Weekend gaps, holiday sessions and occasional bad prints can create trades that could never have happened. Check any unusually large win or loss against the chart.
- Split the data. Before you start, set aside the most recent portion, for example the last 25% to 30% of the history, as out-of-sample data. You will not look at it until the end. More on why below.
Data from different brokers will not be identical, because each broker's feed reflects its own liquidity providers and pricing. That matters most for strategies with small targets.
Step 3: manual or automated testing
There are two broad ways to run the test, and each has its place.
Manual backtesting
You scroll through historical charts candle by candle, hiding the future, and record each trade the rules produce in a spreadsheet. Many charting platforms have a replay mode that reveals one candle at a time.
Advantages: you learn how the strategy behaves and how its setups look in real time. You can test discretionary elements that are hard to code. It costs nothing but time.
Disadvantages: it is slow, so samples tend to be small. It is easy to cheat without meaning to, because you can often see the right-hand side of the chart or remember how a period played out. Fatigue leads to missed or misjudged trades.
To keep manual tests honest, use replay mode rather than scrolling, record each trade before revealing the next candle, and log every valid setup, not just the ones that look good.
Automated backtesting
You code the rules, for example as an Expert Advisor in MetaTrader's Strategy Tester, a cBot in cTrader, or a script in a general-purpose language, and let the software run through the data. Our guide to MetaTrader 4 vs MetaTrader 5 covers the testing differences between the two platforms, and cTrader and TradingView covers the alternatives.
Advantages: fast, consistent, and capable of testing thousands of trades across many instruments. The rules are applied exactly as written.
Disadvantages: coding errors are common and silent. The software makes assumptions about fills, spreads and the order in which prices were touched inside a candle that may not match reality. And the speed makes it very easy to run hundreds of variations, which leads straight to overfitting.
Whichever you use, spot-check the output. Pick ten trades at random and verify them against the chart by hand. If any are wrong, the whole test is suspect.
Step 4: include every cost
A backtest without realistic costs is fiction. Include:
- Spread on every entry, using a realistic average for the time of day you trade, not the tightest spread the broker advertises. Spreads widen around rollover and during news.
- Commission if your account charges it, round turn per lot. The spreads and commissions guide shows how to combine the two into one cost per lot.
- Swap for any position held past the daily rollover, which can be a charge or a credit depending on the pair and direction. See swap and overnight financing.
- Slippage: assume some on stop-loss exits and market entries, especially around data releases. A common approach is to add a fixed amount, such as half a pip to a pip per side on liquid majors, and more for less liquid pairs. Our slippage guide explains why it happens.
Worked example: costs change the verdict
This is an illustrative example. Suppose a scalping strategy on EUR/USD shows the following over 400 trades before costs: 58% win rate, average win 6 pips, average loss 6 pips.
Gross expectancy per trade = (0.58 × 6) − (0.42 × 6) = 3.48 − 2.52 = 0.96 pips.
Now add costs. Assume an all-in cost of 1.0 pip per round turn (for example, a 0.3-pip average raw spread plus commission equivalent to 0.7 pips) and 0.2 pips of average slippage. Every trade now costs 1.2 pips.
Net expectancy per trade = 0.96 − 1.2 = minus 0.24 pips.
The same strategy that looked positive loses money once you include what it actually costs to trade. Strategies with small targets are the most sensitive: costs are a fixed amount per trade, so the smaller the average trade, the larger the share costs consume. A swing strategy averaging 80-pip wins would barely notice the same 1.2 pips.
Step 5: read the results properly
The final balance is the least useful number in a backtest report. Look at these instead:
- Number of trades. Too few, and nothing else matters.
- Expectancy per trade, after costs, in pips or R. Our risk-reward ratio guide explains the formula.
- Win rate and average win and loss, to understand how the expectancy is made up.
- Maximum drawdown, in percentage and in R, and how long it took to recover. Ask yourself honestly whether you would have kept trading through it.
- Longest losing streak. You will meet it, or worse, in live trading.
- Consistency across periods and instruments. Split the results by year and by pair. A strategy that made all its money in one year or on one pair is fragile.
- Dependence on a few trades. Remove the five best trades. If expectancy turns negative, the strategy relies on rare outliers, which may or may not repeat.
A reasonable target for a first pass is modest, positive expectancy after costs that holds up across sub-periods, with drawdowns you could tolerate at your intended risk per trade. Spectacular returns with tiny drawdowns are a warning sign, not a goal.
Overfitting: the main way backtests lie
Overfitting (also called curve fitting) happens when you adjust a strategy until it matches the noise in your historical data rather than any repeatable behaviour. It is the default outcome of optimising without discipline.
Here is how it happens. You test a moving-average crossover with 10 and 30 periods. It loses. You try 12 and 35. Slightly better. You add an RSI filter, then change the RSI threshold from 50 to 55, then add a rule to skip Mondays. Each change improves the backtest a little. After fifty variations you have a beautiful equity curve. But you have tested so many combinations that some were bound to look good by chance, and the final rules describe the past, not a pattern that will recur.
Signs a strategy is overfitted:
- Many parameters and filters, especially ones with very specific values.
- Performance that collapses when you nudge a parameter slightly. A robust strategy should work reasonably well with a 20-period average and a 25-period average, not only at 22.
- Rules that only make sense in hindsight, such as skipping a particular month.
- Excellent in-sample results and poor out-of-sample results.
How to reduce it:
- Keep it simple. Fewer rules and parameters leave less room to fit noise.
- Decide the logic before testing. Each rule should have a reason you could explain without reference to the backtest.
- Test parameter ranges, not single values. Look for a broad plateau of acceptable results rather than a single peak.
- Use out-of-sample data once. Optimise only on the in-sample portion. When finished, run the final rules once on the out-of-sample data you set aside. If you then go back and tweak, that data is no longer out-of-sample.
- Consider walk-forward testing. Optimise on one window, test on the following window, roll forward, and repeat. It is more work but gives a better sense of how the process would have performed in real time.
Other biases to watch for
- Look-ahead bias: using information that was not available at the time of the trade. A classic example is entering on a candle's open based on a signal that only appears at that candle's close, or using a daily high or low before the day has finished.
- Survivorship and selection bias: testing only on the pairs or periods you already know were favourable, or only on the strategy you remember working.
- Intra-candle assumptions: if both your stop and your target sit inside the same candle's range, the software has to guess which was hit first. Some testers assume the favourable outcome. Use lower-timeframe or tick data for those trades, or assume the worse case.
- Unrealistic fills: assuming limit orders always fill when price touches them, or that stop orders fill exactly at the stop price during fast markets.
- Ignoring market changes: a strategy that relied on a particular volatility level or interest rate environment may behave differently when that changes, as covered in central banks and interest rates.
Step 6: forward test before you risk real money
A forward test means trading the strategy in real time, on a demo account or with very small live size, without changing the rules. It checks things a backtest cannot:
- whether you can actually follow the rules when trades are live;
- whether real fills, spreads and slippage match your assumptions;
- whether the strategy still behaves as it did in the test period.
Run the forward test for long enough to collect a meaningful number of trades, at least 30 to 50 and ideally more, and record every one in a trading journal. Then compare. If live expectancy is broadly in line with the backtest after allowing for normal variation, that is encouraging. If it is clearly worse, find out why before going further: execution, costs, your discipline, or the strategy itself.
Even a strategy that passes every test can lose money live. Leverage magnifies losses as well as gains, and most retail CFD accounts lose money. Starting small is not timidity; it is the last stage of the test.
Common backtesting mistakes
- Writing rules after looking at the chart, or adding exceptions during the test.
- Testing on too short a period or too few trades.
- Leaving out spread, commission, swap or slippage.
- Optimising on all the data, leaving nothing out-of-sample.
- Judging the strategy by the final balance rather than expectancy and drawdown.
- Trusting software output without checking individual trades.
- Skipping the forward test because the backtest looked convincing.
- Increasing risk per trade because the backtest drawdown looked small. Live drawdowns are usually larger.
Frequently asked questions
How many trades do I need in a backtest?
There is no fixed number, but fewer than 50 tells you very little and 100 or more is a sensible minimum. Several hundred trades across different market conditions gives much more confidence. If a strategy trades rarely, extend the history or test across several instruments.
Is manual backtesting worth it?
Yes, especially when you are learning a strategy or it includes judgement that is hard to code. It is slower and more prone to unconscious bias, so use replay mode, record every valid setup and spot-check yourself. Many traders start manually, then automate once the rules are fully defined.
What is a good backtest result?
Positive expectancy after realistic costs, consistent across different years and instruments, with a drawdown you could genuinely live through, over a large number of trades. Be suspicious of very high returns with very small drawdowns; that pattern is more often a sign of overfitting or a coding mistake than of a great strategy.
Can I trust the backtester in my trading platform?
It is a reasonable tool, but check its assumptions: what data it uses, whether spreads are fixed or variable, how it handles stops and targets within one candle, and whether swap is included. Verify a sample of trades by hand. Higher-quality tick data gives more realistic results for short-term strategies.
What is the difference between backtesting and forward testing?
Backtesting runs the rules over historical data. Forward testing runs them in real time, on demo or small live size, without changing the rules. The backtest tells you an idea is worth pursuing; the forward test tells you whether it survives real execution and your own behaviour.
Why did my strategy work in the backtest but fail live?
The usual causes are overfitting, underestimated costs and slippage, look-ahead bias in the test, a change in market conditions, or not following the rules live. Compare your live journal against the backtest trade by trade to see which it was.
Not investment advice. This is general information and education, written without knowledge of your circumstances. It is not a recommendation to buy or sell any instrument. Past performance is not a reliable indicator of future results. Trading leveraged products carries a high risk of losing money. Risk warning