Optimization

Over-Optimization - Dangers and How to Avoid It

Over-optimisation fits a strategy to the noise of past data. Why it happens, the warning signs in backtests and optimiser results, and practical defences that keep strategies tradable.

By AlgoXP3 min readUpdated

In-sample results keep rising with more parameters while out-of-sample results peak and then fall

Over-optimisation (curve fitting, overfitting) happens when a strategy is tuned so closely to historical data that it captures noise instead of a real, repeatable effect. The backtest looks excellent because the strategy has effectively memorised the past. In live trading, the noise is different, and the edge disappears.

It is the single most common reason a good-looking trading bot fails.

Why it happens

Degrees of freedom. Every parameter, filter and special rule gives the strategy another way to bend around historical data. With enough of them, any history can be fitted.

Multiple testing. Testing 1,000 parameter sets and keeping the best is like flipping 1,000 coins ten times and admiring the one that landed heads ten times. The winner is partly luck, and the more you test, the larger that part becomes. Bailey, Borwein, López de Prado and Zhu formalised this as the probability of backtest overfitting: with enough trials, the best in-sample result is likely to underperform out of sample.

Feedback loops. After each test you add a filter that removes the worst losing trades. Each filter is reasonable on its own; together they describe the past perfectly and the future poorly.

Warning signs

Sign What it suggests
In-sample results far better than out-of-sample The optimiser found noise
Isolated peak - neighbours perform much worse Lucky value, not a real effect
Many parameters relative to the number of trades Too much freedom for the data
Very high profit factor or Sharpe on few trades Small sample plus selection
Rules with exact numbers that “fix” specific periods Fitting to known events
Most profit from a handful of trades Results depend on rare outliers

Defences that work

1. Keep the model simple

Fewer parameters mean fewer ways to fit noise. As a rough sanity check, you want many more trades than free parameters - dozens of trades per parameter at least. If a filter improves results only slightly, leave it out.

2. Use coarse steps and wide ranges

Steps of 5 bars rather than 1, or 0.25 ATR rather than 0.01, stop the optimiser from finding needle-thin peaks. If a strategy only works at one precise value, that is information: it probably does not work.

3. Prefer plateaus to peaks

Look at the optimisation landscape. A broad region where many neighbouring values work similarly is far more likely to reflect a real effect than the single best pass. Choose a value from the middle of that region. See parameter stability analysis.

4. Keep data the optimiser never sees

Split data before optimising and judge the result on the untouched part. Better still, use walk-forward analysis, which repeats this split many times through history.

5. Count your trials

Write down how many variants and parameter sets you tested. The more you tried, the more out-of-sample evidence you need before believing the winner.

6. Stress the result

  • Increase costs.
  • Delay entries by one bar.
  • Remove the top 5% of winning trades.
  • Reshuffle trade order with Monte Carlo simulation.
  • Test on related markets or timeframes.

A real edge weakens under stress; an overfitted one collapses.

7. Optimise for robustness, not maximum profit

Objectives like return over drawdown with a minimum number of trades select more balanced settings than raw profit. In cTrader you can combine standard criteria or write a custom fitness function that, for example, returns zero for passes with too few trades.

A worked example

A breakout bot is optimised on 2019-2023 with five parameters and fine steps: 40,000 combinations. The best pass shows a profit factor of 2.9 with 70 trades. On 2024 data it returns a profit factor of 0.9.

Rerun with two parameters, coarse steps and a minimum of 150 trades: 60 combinations. A plateau appears with profit factors of 1.4-1.6 and 180-220 trades. On 2024 data the middle of the plateau gives 1.3. Less impressive in sample - and actually tradable.

When to stop optimising

Stop when changes improve the in-sample result only slightly, when each new filter targets a specific historical period, or when you catch yourself repeating optimisations on the same data. At that point, more optimisation adds fit, not edge.

Key takeaways

  • Over-optimisation fits noise; it is driven by too many parameters and too many trials.
  • Warning signs: isolated peaks, few trades, big in-sample/out-of-sample gaps.
  • Defend with simplicity, coarse steps, plateaus, untouched data, walk-forward and stress tests.
  • A modest, stable result beats a spectacular, fragile one.

FAQ

How do I know if my strategy is over-optimised?

Typical signs: performance drops sharply out of sample, neighbouring parameter values give very different results, the strategy has many parameters or special-case filters, and a few trades produce most of the profit.

Is it possible to optimise without overfitting?

You cannot remove the risk completely, but you can control it: few parameters, coarse steps, stable regions, untouched out-of-sample data, walk-forward analysis and honest counting of how many variants you tried.

Does a longer backtest prevent over-optimisation?

It helps, because noise is harder to fit across more data and more regimes. But a strategy with enough free parameters can fit long histories too. Data length is a defence, not a guarantee.

Sources and further reading

  1. Bailey, Borwein, López de Prado, Zhu: The Probability of Backtest Overfitting - papers.ssrn.com
  2. cTrader Help: Optimise a cBot - help.ctrader.com