What you will learn
- A step-by-step method for testing a trading idea so that the result means something.
- Why a good backtest is easy to produce and hard to trust, shown with our own experiment on 90 parameter combinations.
- How many trades you need before an average result in R is informative, with the formula.
- How to count your tests, because every extra variant raises the chance of fooling yourself.
- What to do after the backtest: forward testing and a decision rule.
The idea in plain words
A backtest applies a set of trading rules to past data and records what would have happened. It is the cheapest way to check an idea. It is also the easiest way to fool yourself, because the past is fixed, you can look at it as many times as you like, and with enough tries something will look good by chance.
Testing a strategy honestly is mostly about discipline in how you test. The method has seven parts: rules fixed in advance, realistic costs, a baseline, enough trades, data held out, a count of how many things you tried, and a forward test with real conditions. Each part guards against a specific way a backtest lies.
This is the last strategy lesson, and it uses the same test method and data as the three before it (pullback, breakout and retest, liquidity sweep), so you can see where the numbers came from.
How it works
What the research says about testing rules
- Brock, Lakonishok and LeBaron (Journal of Finance, 1992) tested moving-average and trading-range break rules on the Dow Jones index from 1897 to 1986 and reported strong support for them, using bootstrap methods.
- Sullivan, Timmermann and White (Journal of Finance, 1999) used White’s Reality Check bootstrap to evaluate technical rules while quantifying the data-snooping bias in the full universe the rules were drawn from. They expanded Brock and colleagues’ 26 rules and applied them to 100 years of daily Dow Jones data.
- White’s “A Reality Check for Data Snooping” (Econometrica, 2000) is the paper behind that method. We read its abstract, which defines data snooping as using the same data more than once for inference or model selection, and offers a procedure for testing whether the best model found in a specification search has any predictive superiority over a benchmark. We did not read the full text, so we cite it only for that idea: when many rules are tried on the same data, the best of them needs to be tested against the whole set that was tried.
- Park and Irwin (Journal of Economic Surveys, 2007) reviewed 95 modern studies of technical trading profitability: 56 positive, 20 negative and 19 mixed. They noted that most studies suffer from data snooping, ex post selection of trading rules, and difficulty in estimating risk and transaction costs.
- Bailey and co-authors (working paper, SSRN, 2013) propose a framework to estimate the probability that a backtest is over-fitted. Their abstract states that standard techniques designed to prevent over-fitting, such as hold-out, tend to be unreliable and inaccurate in investment backtests.
The last point is important: holding out data, which is the main protection we use below, is necessary but not sufficient.
The seven parts of an honest test
1. Rules fixed in advance. Write every rule (entry, stop, target, exit, filters, position size) before looking at results. Anything left vague will be filled in with hindsight.
2. Realistic costs. Include spread, commission and slippage. In our three strategies a cost of 0.10 ATR per trade was 0.067R when the stop was 1.5 ATR and about 0.16R when the stop was structural and tight. Test at least two cost levels.
3. A baseline. Run the same stops, targets and costs with arbitrary entries. In our tests, a random baseline gave −0.056R (D1) and −0.133R (H4) per trade. A strategy has to beat that, not zero.
4. Enough trades. The standard error of the mean R is the standard deviation of R divided by the square root of the number of trades. For a strategy with a 2R target and a win rate near 40%, the standard deviation is about 1.5R. To see an average of +0.1R at two standard errors you need about (2 × 1.5 ÷ 0.1)² = 900 trades, and for +0.2R about 225. Our tests had 227 to 400 trades each.
5. Data held out. Design on one part, check on another. We used the first 60% and last 40% of each series, with rules fixed in advance. If you tune parameters, the held-out part must not be used for tuning, and you should look at it once.
6. A count of what you tried. Every variant you test is another chance for luck. If you test 20 variants at a 5% significance level, you expect about one false positive even if none works.
7. A forward test. After the backtest, trade the rules on a demo account for a pre-agreed number of trades and compare the results with the test. Live execution adds spreads, slippage and your own behaviour.
Our experiment: how overfitting works
To show the danger of tuning, we took an always-in-the-market moving-average crossover (long when the fast EMA is above the slow EMA, short otherwise) and tested every combination of fast length in 5, 10, …, 50 and slow length in 20, 40, …, 200 where fast is less than slow. That is 90 combinations. For each of five instruments on daily candles we picked the combination with the best in-sample result (first 60% of the data, measured by an annualised Sharpe ratio, mean over standard deviation of daily returns times the square root of 252, costs of 0.005% of price per unit of position change), and then looked at the same combination in the last 40%.
| Instrument | Best in-sample combination | In-sample Sharpe | Out-of-sample Sharpe | Median of all 90, in / out |
|---|---|---|---|---|
| EUR/USD | 10 / 20 | +0.59 | +0.37 | +0.04 / −0.00 |
| GBP/USD | 15 / 40 | +0.64 | −0.01 | +0.11 / −0.48 |
| USD/JPY | 5 / 80 | +1.19 | −0.02 | +0.86 / −0.55 |
| Gold | 20 / 60 | +0.44 | +1.00 | −0.04 / +1.11 |
| Bitcoin | 45 / 200 | +0.75 | +0.23 | +0.29 / +0.07 |
In four of the five cases the out-of-sample result was lower than the in-sample result, and for two it was about zero. The exception, gold, rose in the last part for almost every combination (the median was +1.11), which says the market was trending, not that the parameters were good.
A cleaner test removes any real structure. We took EUR/USD’s daily returns, shuffled their order randomly (so that there is no trend, no pattern and no information left in the sequence) and repeated the whole 90-combination search on 200 shuffled series.
– Best in-sample Sharpe: mean +0.50, median +0.47. In half of the 200 trials, the best combination had a Sharpe above +0.5.
– The same combinations out-of-sample: mean −0.09, median −0.08. In 19% of trials the Sharpe was above +0.5, which is the noise level of a 2.3-year sample.
On data with nothing in it, searching 90 combinations produced an in-sample Sharpe of about +0.5 on average, and it vanished out-of-sample. That is overfitting, in its simplest form: the search finds the luck that was in the sample.
Note on noise: the standard error of a Sharpe ratio estimated over a number of years is roughly 1 divided by the square root of the years (a standard approximation). With 3.5 years in-sample that is about 0.5 and with 2.3 years out-of-sample about 0.65, which is as large as the numbers in the table.
Counting what you tried
In the strategy lessons we reported eight pooled results (four rules, two timeframes). The t-statistics (mean R divided by its standard error) were:
| Rule | D1 | H4 |
|---|---|---|
| Trend pullback | +1.99 | −1.29 |
| Plain breakout | +0.31 | −0.80 |
| Breakout + retest | −1.66 | −1.55 |
| Liquidity sweep reversal | −2.69 | −2.58 |
Two of the eight are beyond −2 (both for the sweep rule, where costs on tight stops did the damage), and the pullback on D1 sits at +1.99, the only clearly positive one. If none of the eight rules had any effect, the chance of at least one result beyond ±2 in eight independent tests would be 1 − 0.95⁸ ≈ 34%. The tests are not independent (they share data and instruments), so the exact chance differs, but the lesson holds: one result near two among several is weak evidence, and it should be treated as a hypothesis for new data.
Worked examples
Example 1: standard error and sample size
A strategy with a 2R target and costs has outcomes of +1.933R and −1.067R. Suppose the win rate is 40%.
1. Mean: 0.4 × 1.933 − 0.6 × 1.067 = 0.773 − 0.640 = +0.133R.
2. Variance: p(1 − p) × (1.933 + 1.067)² = 0.24 × 9.0 = 2.16, so the standard deviation is 1.47R.
3. With 100 trades, the standard error is 1.47 ÷ 10 = 0.147R, so a measured mean of +0.133R is under one standard error from zero.
4. With 400 trades, the standard error is 0.073R, and +0.133R is 1.8 standard errors.
5. To get the true +0.133R to two standard errors you need about (2 × 1.47 ÷ 0.133)² = 489 trades.
So even a strategy that works at that level needs hundreds of trades before the data can show it, and a typical retail trader takes that many over a year or two. This is why the forward test and the journal matter.

What to notice: How slowly the error falls.
Example 2: reading one of our own results
The D1 trend pullback had 316 trades with a mean of +0.153R and a standard error of 0.077R.
1. The t-statistic is 0.153 ÷ 0.077 = 1.99.
2. Compare with the baseline: the random-entry baseline was −0.056R. The gap is 0.209R.
3. With zero costs the mean was +0.220R, and with 0.2 ATR costs it was +0.087R.
4. We tested eight things. The chance that at least one of eight useless rules has a t above 1.99 in the positive direction is about 1 − (1 − 0.023)⁸ ≈ 17%.
So the right reading is: interesting, not established. The next step is not to trade it, but to fix the rules and gather new data, in a forward test or on instruments and years not used so far.
Example 3: a pre-registration checklist
Before testing a new idea, write down:
1. The rules, with exact numbers.
2. The instruments, timeframes and date range.
3. The cost assumptions, and the two levels you will test.
4. The baseline.
5. The success criterion, for example “mean R above the baseline by two standard errors out-of-sample with at least 300 trades”.
6. How many variants you will test (ideally one).
Then run it once. If you change the rules afterwards, that is a new test and counts as another try.

What to notice: That failing does not send you back to tune.
How to apply it step by step
- Write the idea as exact rules and a success criterion before touching data.
- Get clean data for at least several years, and check it for gaps and errors.
- Code the rules once, with conservative assumptions: stop first when both levels are in one candle, fills at the open on gaps, costs included.
- Run the baseline.
- Run the test on the in-sample part, and the out-of-sample part once.
- Compute the mean R, standard error, win rate and profit factor, by instrument and pooled.
- Count how many variants you have tried in total, and adjust your expectations.
- If the result survives, forward-test it on a demo account for a pre-agreed number of trades with a journal.
- If it does not, discard it or write a new, different hypothesis. Do not tune the old one on the same data.
- Keep the code and the results, so that the test can be repeated.
Common mistakes
- Tuning until it looks good. In our shuffled-data experiment, the search found a Sharpe of +0.5 in noise.
- Reusing the held-out data. Once you tune on it, it is in-sample.
- Leaving out costs. Zero cost turned our sweep rule from clearly negative to roughly break-even.
- Trusting small samples. A few dozen trades say nothing about a 0.1R edge.
- Not counting tries. You will remember the test that worked, not the nine that did not.
- Peeking. Using information that was not available at the time, such as a swing that is only confirmed three candles later.
- Believing a result because it fits a story. A convincing explanation can be written for any outcome.
When it works and when it does not
Testing works when the rules are specific, the sample is large, costs are honest and you refuse to tune on the held-out data. It protects you from the most common trap, which is trading something that never worked.
It cannot guarantee future performance. Markets change, and a rule that worked in the sample may stop. Even careful hold-out testing can be unreliable in investment backtests, as the Bailey and co-authors abstract warns. Our tests are also limited: one feed, about 4 to 6 years of D1 and under a year of H4, five partly related instruments, and an assumed cost. A rule that passes all of this can still fail live. So the only conclusion a backtest supports is “worth a forward test” or “not worth one”.
Practice exercise
- A strategy has a standard deviation of 1.2R per trade. How many trades give a standard error of 0.1R?
- A strategy has 150 trades, a mean of +0.20R and a standard deviation of 1.3R. What is the standard error and the t-statistic?
- You test 12 independent variants at the 5% level. What is the chance that at least one passes by luck?
- In shuffled data, the best of 90 combinations had an in-sample Sharpe of +0.5. What does this say about a +0.5 you find on real data after a similar search?
Answers:
1. n = (1.2 ÷ 0.1)² = 144 trades.
2. SE = 1.3 ÷ √150 = 0.106; t = 0.20 ÷ 0.106 = 1.9.
3. 1 − 0.95¹² = 1 − 0.540 = 46%.
4. That a result of this size is what pure noise produces on average from such a search, so it is not evidence of an edge until it holds on new data.
Key terms
Backtest – applying rules to past data to see what would have happened.
In-sample / out-of-sample – data used to build a rule and data held back to check it.
Overfitting – fitting a rule to the noise in the sample.
Data snooping – using the same data to test many rules and reporting the best.
Baseline – the result of arbitrary entries with the same stops, targets and costs.
Standard error – the typical sampling error of an average.
t-statistic – the average divided by its standard error.
Forward test – trading the rules on new data after the backtest.
Frequently asked questions
How do I backtest a trading strategy properly?
Write exact rules first, include costs, compare with a random baseline, use enough trades, hold out data you do not tune on, count how many variants you tried, and then forward-test on a demo account.
How many trades do I need for a reliable backtest?
It depends on the edge. For a strategy with a standard deviation of about 1.5R per trade, seeing a +0.2R average at two standard errors takes about 225 trades, and +0.1R takes about 900.
What is overfitting in trading?
Choosing rules or parameters because they fit past data, including its noise. In our experiment, searching 90 moving-average combinations on shuffled data produced an average best Sharpe of +0.50 that vanished out-of-sample.
Is out-of-sample testing enough?
It helps but is not sufficient. If you look at the held-out data repeatedly, it stops being held out, and research on investment backtests reports that hold-out methods can be unreliable.
Why include a random baseline?
Because stops, targets and costs alone produce results. In our tests the baseline gave −0.056R on D1, so a strategy must beat that figure, not zero.
What should I do after a good backtest?
Forward-test the exact rules on a demo account for a pre-agreed number of trades with a journal, then compare with the backtest before risking real money, and keep position sizes small at first.
Key takeaways
- A backtest is a hypothesis check, not a promise.
- Fix rules in advance, include costs, and compare with a baseline.
- Hundreds of trades are needed to see an edge of 0.1 to 0.2R.
- Searching many variants finds luck: our noise experiment gave a best Sharpe of +0.50 that vanished.
- Count your tries, and treat a result near two standard errors among several as weak evidence.
- Forward-test before risking money.
Quick quiz
Q1. What is the standard error of a mean R with a standard deviation of 1.5R over 225 trades?
A: 1.5 ÷ √225 = 0.1R.
Q2. Why should you not tune parameters on the out-of-sample data?
A: Because it then becomes in-sample and no longer checks anything.
Q3. If you test 20 useless variants at the 5% level, how many false positives do you expect?
A: About one.
Q4. Why does zero cost make a strategy look better?
A: Costs reduce every trade, and they matter most when stops are tight, so leaving them out inflates the result.
Q5. What did the shuffled-data experiment show?
A: A search of 90 combinations found an average best in-sample Sharpe of +0.50 on data with no structure, and the same combinations averaged −0.09 out-of-sample.
Q6. What is a forward test?
A: Trading the exact rules on new data, usually on a demo account, after the backtest.
Going deeper
- Trend pullback strategy – the first worked test.
- Breakout and retest strategy – plain versus filtered rules.
- Liquidity sweep reversal – how costs decide tight-stop strategies.
- Keeping a trading journal – how to track a forward test.
- MT5 Strategy Tester: six ways a backtest misleads you – the MetaTrader-specific cases.