Forex course · Section 5: Risk, Strategy and Testing
How to Backtest a Forex Strategy Properly
A step-by-step method for forex backtesting: clean data, realistic spreads and swaps, no look-ahead bias, out-of-sample checks and how to spot overfitting.
Advanced6 min read·6:12 video·Lesson 22 of 26·quiz: 4 questions
▶ Video lesson · 6:12Watch on YouTube ↗
On this page +
To backtest a forex strategy properly, write precise rules, run them on many years of clean historical data across several pairs, charge realistic spreads, commissions, slippage and swaps, enter only on information that was available at the time, and then check whether the result survives on data you did not use to design it. Most strategies that look excellent on a chart fail one of these steps. A good backtest's main job is to stop you from trading a rule that does not work.
Step 1: Write rules a computer could follow
"Buy when the trend is up and price pulls back" cannot be tested. This can:
- Universe: 28 major and cross pairs, daily candles closing at 17:00 New York.
- Entry: buy at the next open when the daily close is above the 200-day SMA and RSI(2) is below 10.
- Stop: 2 × ATR(14) below entry. Exit: when the close is above the 5-day SMA, or after 10 days.
- Size: 1% of equity at risk per trade, at most 4 open positions.
- Costs: spread per pair, commission, swaps, slippage.
If you cannot write it down this precisely, you do not yet have a strategy.
Step 2: Get clean data
- Enough history: ideally 15 years or more, covering crises, calm years, rate hikes and cuts.
- Consistent daily close: as explained in Forex Market Hours, different time zones produce different daily candles, including stray Sunday candles. Pick one definition and use it everywhere.
- Bad ticks: free tick or minute data often contains spikes to impossible prices, frozen prices and gaps. Plot the data and check unusual candles before trusting results.
- Bid, ask or mid: know which one your data is. If it is bid or mid, add the spread yourself.
- Regime changes: pegs and floors, such as the Swiss National Bank's 1.20 floor under EUR/CHF from 2011 to 2015, make some history unrepresentative.
Step 3: Charge realistic costs
| Cost | How to model it |
|---|---|
| Spread | Typical spread per pair at your trading hour; wider around the daily rollover and news |
| Commission | Your broker's rate per lot, on entry and exit |
| Slippage | Extra pips on stop exits and on entries at busy times |
| Swaps | Daily credit or charge for each night held, using historical rate differentials minus a broker markup, with triple swaps on Wednesdays |
Example
A strategy averages +2.5 pips per trade before costs over 1,000 trades. With 1.8 pips of real costs per round turn, it nets +0.7 pips per trade. If your costs turn out to be double (3.6 pips), it loses 1.1 pips per trade. A strategy whose edge disappears when costs double is too fragile to trade.
Swaps are easy to forget and matter a lot for trades held for weeks. Over the years, a strategy that is usually long low-yielding currencies can lose much of its gross profit to swaps (see Swaps, Rollover and the Carry Trade).
Step 4: Remove look-ahead bias
Look-ahead bias means the backtest uses information that would not have been available at the moment of the decision. Common forms:
- Entering at the same close that produced the signal. You only know the close once the candle is finished. Enter at the next open, or just after the close, with realistic costs.
- Using the day's high or low to trigger a decision during that day, then assuming fills that ignore the order in which the high and low happened.
- Using revised economic data. GDP and jobs numbers are revised; the first published figure is what traders saw.
- Choosing pairs or periods with hindsight, such as testing only pairs that you know trended.
Example
A breakout rule tested with entries at the signal close shows a healthy profit. Re-tested with entries at the next day's open, a slice of every winning trade disappears, because breakouts often gap or run further overnight. The difference is not a detail; it can decide whether the rule makes money at all.
Step 5: Fight overfitting
Overfitting (curve fitting) means tuning a strategy so closely to past data that it captures noise rather than a real pattern. With enough parameters and enough tries, any rule can be made to look brilliant on the past.
Defences:
- Few rules, few parameters. Every extra filter must earn its place.
- Out-of-sample testing: design on one period (say 2005 to 2016), then test once, unchanged, on the rest. If performance collapses, the design was fitted to noise.
- Walk-forward testing: repeatedly optimise on a past window and test on the next one.
- Parameter stability: if a 50-day average works but 45 and 55 do not, the result is likely luck. Look for broad plateaus, not sharp peaks.
- Count your tries. If you tested 300 variations, the best one is expected to look good by chance alone.
Step 6: Check robustness
A real effect should show up broadly. Check:
- Both halves of the history, and year by year.
- Long and short trades separately.
- Most pairs, not just one or two.
- Doubled costs.
- Enough trades: a few dozen trades say little; aim for hundreds.
Then measure: number of trades, win rate, average win and loss in R, expectancy per trade after costs, maximum drawdown and the longest losing streak.
Pro note
These are the same checks DanioX applies on the forex backtest page and describes on the methodology page: long daily histories on the 28 pairs, costs and swaps charged, long and short sides, different periods and a doubled-cost test. In its current tests no forex strategy passed robustly, so no forex signals are published. A failed test is a valid, useful result.
Step 7: Forward test before risking real money
A backtest is a hypothesis, not proof. Next:
- Run the rules on a demo account or on paper for at least a few months, recording every signal and fill.
- Compare live fills, spreads and swaps with your backtest assumptions.
- If results are in line, start live with small size, then increase gradually.
Risk
Even a carefully tested strategy can fail live because markets change. Expect live results to be worse than the backtest, and decide in advance what drawdown would make you stop and re-examine the strategy.
The full path from idea to live trading is built into the capstone, Build and Test Your Forex Trading Plan.
Key takeaways
- Write the rules so precisely that a computer could follow them, before looking at results.
- Charge realistic spreads, commissions, slippage and swaps; then test again with doubled costs.
- Avoid look-ahead bias: decide on information available at the time and fill at the next possible price.
- Overfitting is the biggest trap: keep rules simple, test out of sample, across pairs and periods, and distrust settings that work only in a narrow range.
Quiz: check what you learned
0/4 answeredAnswer every question to finish the lesson. Wrong answers are fine: read the explanation and try again.
⚠ Not financial advice — educational signals only. Read the disclaimer.