Backtesting a Trading Strategy: How to Do It Without Fooling Yourself
Backtesting tells you how a rule behaved on data you have already seen. Done carelessly it produces a beautiful equity curve that describes the past perfectly and predicts nothing at all.
In one sentence:
Backtesting means running your trading rules over historical price data to see what would have happened, useful only if the rules were fixed before you looked, the sample is large enough to mean something, and the costs you assumed match what a broker would really have charged you.
Backtesting at a glance
| Difficulty | Intermediate. The mechanics are easy; avoiding self-deception is not. |
| Timeframes | Any, but lower timeframes need far more data and are far more sensitive to spread assumptions |
| Markets it suits | Anything with reliable historical data. Data quality varies enormously between brokers and instruments. |
| Minimum sample | A few hundred trades before results mean much, across several market conditions rather than one |
| What it needs | Rules written down before testing, realistic costs, and data covering trending, ranging and volatile periods |
| What kills it | Optimising parameters until the curve looks good. That fits the noise in your sample and nothing else. |
| In MetaTrader 5 | Results depend heavily on modelling quality and the spread setting. “Every tick based on real ticks” with realistic variable spread is the only mode worth trusting for short-term strategies. |
| Honest summary | A backtest can reliably tell you a strategy does not work. It cannot tell you one does. |
What it is and why it works
Backtesting applies a fixed set of rules to historical data and records what each trade would have produced. Its real purpose is elimination: most ideas fail, and testing lets you discard them at no cost rather than paying to discover it live. Used that way it is one of the most valuable things a trader can do.
The difficulty is that a backtest measures the past, and the past is a single sample containing a great deal of noise. Any set of rules flexible enough to be adjusted will eventually fit that noise. Once it does, the equity curve shows a strategy that would have captured the specific accidents of that particular sample, which is exactly the part of the data that will not repeat.
This is why the order of operations matters more than the software. Rules written down first and then tested give you a genuine result. Rules adjusted while watching the equity curve give you a description of the sample dressed up as a discovery. Both produce identical-looking reports, and only you know which one you did, which is why backtesting is fundamentally an exercise in intellectual honesty.
Costs are the other half. Spread, commission, slippage and swap turn many apparently profitable strategies into losing ones, and the effect is largest exactly where beginners test most: short-timeframe systems taking many trades for small targets. A strategy that averages eight pips per trade is entirely dependent on whether you assumed a one-pip or a three-pip cost, and that assumption is not a detail; it is the result.
How to trade it, step by step
- Write the rules down completely before you look at any data. Entry condition, exit condition, stop placement, target, position size, which instruments and which hours. The test is only meaningful if a second person could follow your written rules and produce the same trades. Anything left to judgement will be resolved in your favour without you noticing.
- Choose a data period that contains more than one market condition. You need trending, ranging and high-volatility phases, ideally across several years. A strategy tested over a single calm year has told you how it behaves in a calm year and nothing else. Split the data now into a test section and a completely untouched holdout section you will not open until the end.
- Check the data itself before trusting anything built on it. Look for gaps, missing sessions, obviously bad ticks and mismatched server timezones, and be aware that broker histories differ. In MetaTrader 5, download the full history first and set modelling to “Every tick based on real ticks” for anything short-term; the faster modelling modes interpolate prices inside each bar and will happily fill orders at prices that never traded.
- Set costs at least as bad as reality, not at the best case. Use a realistic variable spread rather than a fixed minimum, add commission per lot per side, and add an allowance for slippage on stops. If the strategy only works with an optimistic cost assumption, it does not work. Test it again with costs a little worse than expected and see whether the edge survives.
- Run the test without changing anything, and record the full result. Number of trades, win rate, average win, average loss, maximum drawdown, longest losing streak, and the distribution of returns. Expectancy per trade in R units is the figure that matters most: see risk-reward and expectancy for how to calculate it.
- Count the trades and be honest about what the sample supports. Thirty trades tell you almost nothing; a hundred is suggestive; several hundred across varied conditions begins to be evidence. A high win rate on a small sample is the most common false positive in retail trading, and it is exactly what an over-fitted system produces.
- Test the sensitivity of every parameter instead of optimising it. Change each input by a modest amount in both directions and re-run. A robust strategy degrades gently; a curve-fitted one collapses. If a moving average of 21 works well and 19 and 23 both fail, you have not found a setting, you have found an artefact of your sample.
- Run it forward on the holdout data you never touched, then walk it forward. Optimise only on the in-sample section, apply those fixed settings to the untouched section, and compare. Better still, roll that process through the data repeatedly (optimise on one window, test on the next, move along) so you learn how the strategy behaves when it is always trading data it has not seen.
- Forward test live on a demo account before risking money. Run the rules in real time for a meaningful number of trades and compare the results with the backtest. Divergence usually points to something the historical test missed: real spread behaviour around news, slippage on stops, requotes, or a rule you had been resolving by judgement without realising it.
Size every one of those entries with the position size calculator and check the trade is worth taking with the risk/reward calculator before you commit.
The conditions it needs
Rules fixed before the data is examined
The single condition that separates a real test from a rationalisation. Once you are adjusting rules while watching results, you are searching the sample for whatever fits it, and something always will. Writing the specification first and treating it as frozen is what makes the outcome informative.
A sample large enough and varied enough to carry a conclusion
You need enough trades that ordinary randomness cannot explain the result, and enough different market conditions that you know how it behaves when its favourite environment is absent. A trend-following system tested across a two-year trend will look superb and tells you nothing about the range that follows.
Costs modelled at least as badly as reality
Spread, commission, slippage and swap have to be in the test at realistic levels, and the shorter the average trade the more decisive they become. A useful discipline is to make the cost assumption deliberately pessimistic: if the edge survives worse costs than you expect to pay, it is a real edge rather than an accounting artefact.
Data and modelling quality appropriate to the timeframe
Intrabar behaviour matters enormously for anything with a stop and a target close together, because whether the stop or the target was hit first inside a bar decides the trade. Tick-level data answers that; bar-level modelling guesses at it, and it guesses optimistically. Higher-timeframe strategies with wide stops are far less sensitive to this.
Out-of-sample validation
Any strategy can be made to look good on the data used to build it. The only meaningful evidence comes from performance on data that played no part in its construction, whether through a held-out period or walk-forward testing. If in-sample results are excellent and out-of-sample results are mediocre, the difference is the amount of curve fitting you did.
When it fails
- Curve fitting, also called over-optimisation. Adjusting parameters until the equity curve looks good fits the strategy to the random noise in your particular sample. Every additional parameter, filter and exception makes this worse and makes the result look better, which is why heavily optimised systems produce spectacular backtests and disappointing live results. The strongest defence is sensitivity testing: robust settings work across a range, fitted ones work at a point.
- Look-ahead bias. Using information in the test that would not have been available at that moment; the closing price of the bar you are entering on, an indicator that recalculates on completed data, a revised economic figure, or an instrument list chosen with hindsight. It is the most damaging error because it inflates results dramatically while remaining almost invisible in the report. Test only against information that existed at the point of decision.
- Survivorship bias. Testing on instruments that still exist today silently excludes the ones that were delisted, collapsed, redenominated or repegged. Stock and crypto backtests suffer badly from this; the failures have simply been removed from the dataset, so the average outcome is overstated. Index constituent lists carry the same problem when today’s membership is applied to the past.
- Too few trades. A result built on a few dozen trades is dominated by chance, and a small sample with a high win rate is the classic false positive. Any conclusion needs enough trades that plausible randomness cannot account for the edge, and the reported maximum drawdown from a short sample understates what a longer one would show.
- Ignoring what the test cannot contain. Backtests assume every trade was taken exactly as specified. They do not model hesitating after three losses, skipping the setup that follows a bad day, moving a stop, or the platform freezing during a news release. The gap between backtested and live results is often behavioural rather than statistical.
- Trusting default MT5 Strategy Tester settings. Modelling quality and the spread setting change results substantially, and the faster modelling modes interpolate prices within bars in a way that favours the strategy. A short-term system that is profitable on “open prices only” and unprofitable on real ticks is unprofitable; the second number is the one that reflects what a broker would have done.
For different levels of experience
If you are brand new
Start manually rather than with software. Open a chart, scroll back to a date you have not looked at, hide the right-hand side of the screen, and step forward one bar at a time recording what your rules would have done. It is slow, and that is the point: you see the market unfold in the order it actually happened, which no automated report gives you.
Two habits will decide whether the exercise is worth anything. First, write your rules down before you begin and do not change them mid-test: note improvements for a second, separate run instead. Second, record every trade including the ones you would rather not, because a test containing only the trades you liked is not a test.
Expect most ideas to fail, and treat that as the tool working. Backtesting is far better at showing you that something does not work than at proving that something does, and discarding bad ideas cheaply is a genuine skill. Read trading plan alongside this, since a plan is what a test is testing.
If your results are inconsistent
The intermediate failure is almost always optimisation. You test, results are middling, so you try a different moving average, add a filter, restrict the hours, and each change improves the curve. What you are doing is searching your sample for coincidences, and after enough searching you will find some. The improvement is real in the data and absent in the future.
Impose the discipline of out-of-sample testing. Split your data, build on the first part only, and check the second part exactly once with the settings frozen. If the second half is dramatically worse than the first, you have measured how much fitting you did. Then run each parameter a step in either direction: robust strategies degrade gently and fitted ones fall apart.
Also make sure you are testing the right quantities. A strategy is defined by expectancy per trade, maximum drawdown and longest losing streak, not by total profit. Knowing that your method has produced nine consecutive losses in the past is what stops you abandoning it after seven live, which is the most common way a tested edge gets thrown away.
If you are experienced
The controlling problem is multiple hypothesis testing. Every variant you evaluate raises the probability that the best-performing configuration is best by chance, and the effective number of trials includes the informal ones you did not log. Deflated Sharpe ratios, White’s reality check and similar corrections exist for this reason; even a rough count of configurations tested and an adjusted significance threshold is far better than ignoring it entirely.
Walk-forward analysis with rolling re-optimisation is the practical minimum for anything parameterised, and the diagnostic that matters is the stability of the chosen parameters across windows rather than the aggregate return. Parameters that jump around between windows indicate the optimiser is fitting noise, even where the stitched equity curve looks acceptable. Combinatorially purged cross-validation handles overlapping-label leakage better than a simple chronological split where trades span multiple bars.
On execution modelling, the sensitivity that dominates short-horizon results is not average spread but its conditional distribution: spread widens exactly when signals cluster, around releases, at session boundaries and in the rollover window. Model spread as a function of time and volatility rather than as a constant, apply an explicit slippage distribution to stop fills, and if the strategy trades against resting liquidity, treat the fill assumption itself as an untested hypothesis. Session context matters here too: see trading sessions for where those cost regimes sit.
Risk management for this strategy
The main risk in backtesting is not a bad test, it is a good-looking one. A convincing equity curve produces conviction, and conviction produces size. Traders regularly go live at a risk level justified by a backtested drawdown that the sample was never large enough to establish, and the first live drawdown exceeds it.
Assume your true drawdown will be worse than the tested figure; the sample was finite, the future contains conditions the sample did not, and small samples systematically understate the tail. Sizing at half the risk the backtest appears to justify costs you very little and covers the gap between the test and reality. Set the lot size per trade from the stop distance with the position size calculator rather than scaling up because the curve looked good.
Decide in advance what live result would make you stop trading the strategy, and base it on the tested statistics: if the backtest never produced more than eight consecutive losses, then twelve live is a signal that something has changed. Writing that threshold down before you start is what turns a backtest into a risk control rather than a source of false confidence.
Where Market Structure Pro fits
Backtesting a discretionary method is difficult for one specific reason: the judgements are not written down. “I only take this setup when the market is trending” cannot be tested, because the test cannot reproduce what you meant by trending on each bar. That is the gap between a rule and a habit, and it is where most manual backtests quietly break.
Market Structure Pro helps because its output is explicit and reproducible. Twenty-seven tools resolve into a single verdict (TRADE, TRANSITION or NO TRADE) with a confidence percentage and an A/B/C grade, so a condition like “only in a TRADE state at grade A or B” is a testable rule rather than an impression. Crucially it is non-repainting: the state locks on the closed bar, so what you see when scrolling back is what would have been shown at the time. A repainting indicator makes any historical test worthless, because it is showing you a decision made with information from the future, look-ahead bias built into the tool itself.
It is also session-aware and spread-aware, which addresses two of the assumptions backtests get most wrong. MSP is decision support and nothing more: it places no trades, is not a signal service, and guarantees nothing about future results. What it gives a backtest is a fixed, honest record of what the read was on each closed bar, so the test measures your rules rather than your memory.
One verdict with a confidence score, an A/B/C grade and a plain-English reason. Non-repainting, on every MT5 instrument and timeframe.
Stop guessing whether the setup is valid
Market Structure Pro reads structure, trend, momentum, levels, volatility, volume and session in one pass and gives you a single answer with the reasoning attached. Free 7-day trial, no card required.
Start free trialFrequently asked questions
How many trades do you need for a valid backtest?
Enough that ordinary randomness cannot explain the result; a few hundred is a reasonable working minimum, and more is better. Thirty or forty trades tell you almost nothing, and a high win rate on a small sample is the most common false positive in retail trading. The sample also has to span trending, ranging and volatile conditions rather than several hundred trades from one market regime.
What is curve fitting in backtesting?
Curve fitting, or over-optimisation, means adjusting a strategy’s parameters until it performs well on the specific historical data you tested, which fits it to the random noise in that sample rather than to any real market behaviour. It produces excellent backtests and poor live results. The usual test for it is sensitivity: robust settings still work when nudged in either direction, while fitted ones collapse.
What is look-ahead bias?
Look-ahead bias is using information in a test that would not have been available at the moment of the decision: the close of the bar you enter on, a repainting indicator, a revised economic release, or an instrument chosen with hindsight. It inflates results dramatically and is very hard to spot in a report. Every input must be checked against what was genuinely knowable at that point in time.
What is survivorship bias?
Survivorship bias is testing only on instruments that still exist, which silently removes the ones that were delisted, collapsed, redenominated or repegged. Because the failures are missing from the dataset, average results are overstated. It affects stock and crypto backtests most severely, and also appears whenever today’s index constituents are applied to historical data.
Are MT5 Strategy Tester results reliable?
Only as reliable as the modelling quality and cost assumptions behind them. The faster modelling modes interpolate prices inside each bar, which can fill orders at prices that never traded and decides stop-versus-target questions in the strategy’s favour. For anything short-term, use every tick based on real ticks with a realistic variable spread and explicit commission, and treat results from a fixed minimum spread as meaningless.
Why do backtests look better than live results?
Usually some combination of over-optimisation, unrealistically low costs, optimistic intrabar fill assumptions, and behaviour; a backtest takes every trade mechanically, while a live trader hesitates after losses, skips setups and moves stops. Data limitations add to it, since a historical sample cannot contain conditions that had not yet occurred. Forward testing on a demo account before going live exposes most of the gap.
What is walk-forward testing?
Walk-forward testing optimises a strategy on one window of data, applies the resulting fixed settings to the next window it has never seen, then rolls both windows forward and repeats. It simulates how the strategy would have been run in practice, with settings always applied to unseen data. The key diagnostic is whether the chosen parameters stay stable between windows, since parameters that jump around indicate fitting to noise.
Can you backtest a discretionary strategy?
Yes, but only if the judgements are converted into stated conditions first. Manual bar-by-bar replay with the right-hand side of the chart hidden works well, provided the rules are written before you start and every trade is recorded, including the unflattering ones. Anything left as a judgement call will be resolved in your favour without you noticing, which is what makes most manual backtests overstate their results.
Should I backtest or forward test?
Both, in that order. Backtesting is fast and lets you discard bad ideas cheaply, and it is far more reliable at showing that something does not work than at proving that something does. Forward testing in real time on a demo account then reveals what the historical test could not model (real spread behaviour, slippage, and your own execution) before any money is at risk.
Related reading
- Risk-Reward and Expectancy: The statistics a backtest should be reporting, and how to read them.
- Trading Journal and Review: A live journal is a forward test you are running whether you intend to or not.
- Trading Plan: Rules have to be written down before they can be tested at all.
- Algorithmic vs Manual Trading: Automation makes testing easier and over-fitting far easier still.
- Position Sizing: Why the tested drawdown should not set your live risk level.