Backtest overfitting: how to tell an edge from a lucky curve
Backtest overfitting is tuning a strategy until it fits the noise in past data. How to spot it, and how to check for data snooping and look-ahead bias.
- Written by
- The EdgeLuma team
- Published
- Updated
- Reading time
- 10 min
Table of contents
- What is backtest overfitting?
- Why does testing many versions inflate the result?
- What is look-ahead bias?
- What happens when one candle hits both the stop and the target?
- Overfitting, data snooping and look-ahead bias compared
- How many trades does a backtest need?
- How to check if a backtest edge is real
- What EdgeLuma does about overfitting
- Frequently asked questions
Backtest overfitting is tuning a strategy until it fits the random noise in past data instead of a pattern that repeats, so it shines in the backtest and fails on new data. It gets more likely with every version you try, and a backtest can flatter a strategy in quieter ways too, one of them hidden inside a single candle.
A backtest that looks too good usually is. Nobody has to cheat for that to happen. Each time you look at a result and adjust a rule, you nudge the strategy toward the stretch of history you’re testing on. After enough nudges, the rules fit that history and nothing else.
This guide explains what backtest overfitting is and why trying many versions of a strategy inflates the best one. Then it covers look-ahead bias, including the candle that touches both your stop and your target, puts the three problems side by side, and explains how many trades a result needs before you can trust it. It finishes with five checks that separate a real edge from a lucky curve, and with what EdgeLuma takes care of for you.
What is backtest overfitting?
Backtest overfitting is tuning a strategy’s rules so closely to historical data that they capture its random noise instead of a pattern that repeats. Traders also call it curve fitting. An overfit strategy looks excellent on the data it was built on and fails on any other.
It rarely takes bad intentions. A typical case: you test a moving-average crossover with a 20 and a 50-period average, and it loses money. You try 15 and 45, then 18 and 52, then a dozen more pairs. After 30 tries, one pair looks great. Part of the reason it looks great is that it’s the luckiest of the 30, and luck doesn’t carry over to the next year of data.
Bailey, Borwein, López de Prado and Zhu showed that a strategy can reach impressive simulated performance after only a fairly small number of configurations have been tried (Pseudo-Mathematics and Financial Charlatanism, 2014). In The Probability of Backtest Overfitting, the same authors proposed a way to estimate how likely a backtest is to be overfit, using the results of every version that was tested.
Before you trust the best of 30 versions, ask how good the best of 30 strategies with no edge would have looked.
Why does testing many versions inflate the result?
Every version you test is another roll of the dice. Roll enough times and one version will look good by chance, and the version you keep is, by definition, the one that rolled best. Statisticians call this data snooping: the same data gets used over and over to choose between models, so the winner’s result is inflated by the choosing itself. Halbert White proposed a test for it in A Reality Check for Data Snooping, published in Econometrica in 2000.
In practice, you have to discount the result. The more variations you tried before finding it, the more of it you should assume is luck. Many practitioners simply cut a backtest’s Sharpe ratio, its return per unit of risk, in half. In a paper simply called Backtesting, published in The Journal of Portfolio Management in 2015, Harvey and Liu call that halving only a rule of thumb and work out the “haircut” from the number of tests behind a result instead. The cut they find is uneven: the strongest results lose only a moderate share, while marginal ones are cut hard, because they are the most likely to be false discoveries.
Three habits help:
- Keep a log of every version you run, not only the one you keep.
- Prefer rules with few settings. Every free parameter is one more way to fit noise.
- Be suspicious of sharp peaks. If a stop at 1.8 times the average range works and 1.7 or 1.9 don’t, the 1.8 is fitted. A pattern that really repeats usually survives a small change in its settings.
Our RSI strategy test on Bitcoin is written this way: the rules were fixed before the first run, the one filter was chosen before it was tested, and every run made for the article is in its tables.
What is look-ahead bias?
Look-ahead bias is the use of information in a backtest that wasn’t available at the moment the trade decision was made. It’s one of the most damaging mistakes a backtest can make, because it can turn almost any idea into a winner. It’s also one of the hardest to see, since nothing in the results looks wrong.
It usually gets in one of three ways:
- Acting on a candle before it has closed. A signal computed on a candle’s close can’t be traded at that same candle’s open.
- Using levels that were only confirmed later. A swing high exists only once the candles after it have formed. If the backtest marks it on its own candle, it trades on it before any real trader could have.
- Assuming you know what happened inside a candle. A candle records its open, high, low and close, but not the order in which they happened.
The last one needs its own section, because every backtest built on candles runs into it.
What happens when one candle hits both the stop and the target?
When a single candle’s range covers both your stop and your target, the candle alone can’t tell you which level price reached first. A backtest that assumes the target came first books a win that may really have been a loss. Repeat that over hundreds of trades and you can end up with an edge that never existed.
There are two sound ways to handle it. The first is to look inside the candle: read the same stretch of time on smaller candles, one minute at a time, and see which level price crossed first. The second, for the cases that even one-minute candles can’t settle, is to assume the worst and count the stop.
Overfitting, data snooping and look-ahead bias compared
The three are easy to mix up, because each one makes a backtest look better than it is. They come from different places, though, and each has its own check:
| Problem | What goes wrong | The warning sign | The check |
|---|---|---|---|
| Overfitting | The rules fit the noise of the data they were tuned on | Great on that data, weak anywhere else | Run the final rules once on data you held back |
| Data snooping | Many versions were tried on the same data and the best one was kept | The result came out of a long search | Count the versions and discount the result |
| Look-ahead bias | The backtest used information nobody had at the time | Too good to be true, with no visible error | Check that every signal waits for a closed candle and a confirmed level |
How many trades does a backtest need?
More than most people expect. Expectancy, the average result per trade, needs a real sample before it means anything. Over 10 or 20 trades it mostly measures luck, and only at around 100 trades does it start to tell you something. A backtest that covers five years but produces 12 trades is still a small sample.
The same goes for every other number in the report. A win rate measured over 15 trades can change completely with the next five. A maximum drawdown from a short history is the worst thing that has happened so far, not the worst thing that can happen.
Our guide to how many trades a backtest needs works the number out for different kinds of strategy, and measures how often luck alone produces a result that looks like an edge.
How to check if a backtest edge is real
No single test proves an edge. Together, these five checks make a lucky curve much harder to mistake for one:
- Hold data back. Split your history, build and tune on the first part, then run the final rules once, unchanged, on the second. This is called out-of-sample testing. If the result collapses on data the rules never saw, they were fitted.
- Test in different kinds of market: rising, falling and flat. An edge that only shows up in one of them is really a bet on that kind of market.
- Nudge every setting. Move each parameter a step in each direction. If the result fades a little, fine. If it collapses after a one-step change, the original setting was fitted.
- Include costs. A strategy that only just makes money before costs often loses after them, as our guide to fees and slippage shows.
- Read the trades. If one or two trades account for most of the result, take them out and see what’s left.
What EdgeLuma does about overfitting
Software can fix some of these problems for you. The rest depends on how you work.
What EdgeLuma takes care of
- The candle that touches both levels. EdgeLuma checks every fill, stop and target on the smallest candles it has inside each candle, one minute wherever they exist. When a candle still touches both levels, it counts the stop.
- Unfinished candles. Signals are read when a candle closes, and the order goes in on the next candle.
- Swing points confirmed after the fact. A swing high or low is only used once the candles that confirm it have closed.
- Sample size. The report always shows the number of trades, so you can see how much evidence sits behind every other number.
What stays with you
- Counting the versions you try, and stopping before the curve looks perfect.
- Holding data back. You choose the period of every backtest, so you can build on one stretch of history and run the final rules once on another.
For the full method, from writing the rules to reading the report, see how to backtest a trading strategy.
Test a strategy yourself: start with the Free plan, no card needed.
Key takeaways
- Overfitting, also called curve fitting, means tuning a strategy until it matches past data so closely that it describes random noise. The more versions you try, the more likely your best one is simply the luckiest.
- Look-ahead bias means the backtest used information nobody had when the trade was taken, like a swing high that was only confirmed later. It can make almost any idea look good.
- A candle that touches both your stop and your target doesn’t show which came first. A backtest that counts the target turns some losses into wins.
- Over 10 or 20 trades, almost any result can be luck. Around 100 trades, the average starts to mean something.
- To check an edge, hold back data you never tune on, change one rule at a time, nudge every setting and keep count of the versions you try.
Frequently asked questions
What is the difference between overfitting and data snooping?
Overfitting describes the result: rules that fit the noise of the data they were tuned on. Data snooping describes the process that usually leads there: reusing the same data to choose between many versions, so the winner’s result is inflated by the choice itself.
How do I know if my backtest is overfit?
Look for the warning signs: many versions tried before this one, lots of free settings, a result that changes sharply when a setting moves a little, and performance that collapses on data the rules weren’t tuned on. The more of these apply, the more of the result is probably luck.
What is out-of-sample testing?
Out-of-sample testing means running a strategy, unchanged, on data it wasn’t built or tuned on. It’s the closest a backtest gets to the future. If the rules only work on the data they were fitted to, the out-of-sample run usually shows it.




