MT5 overfitting: what it is, why it happens and how to avoid it
You optimize your EA, pick the best pass, and live it looks nothing like the backtest. Execution, costs and changing markets all play a part, but there is a cause that comes before all of them and that is in your hands: the optimization picked the configuration that best fitted the noise of the past. This guide explains what overfitting is, why it is almost inevitable when you test thousands of combinations, how to recognize it in MT5 and how to keep it to a minimum.
What overfitting really is
Every backtest result has two parts: the edge the strategy may really have, and the luck of that particular price history, the moves that happened to suit a given combination and will not repeat in the same way. An optimization searches for the highest total, and it cannot tell the two parts apart. When the configuration you end up choosing owes much of its result to the second part, you have overfitted. It is also called curve fitting or over-optimization.
It is like a student who memorizes the answers to last year’s exam: a perfect score on that exam, and no idea what to do when the questions change. The parameters have learned the past by heart instead of something that repeats.
Optimizing is not the problem in itself: tuning an EA to the market it trades is legitimate and necessary. The problem is believing the best figure in the table. Overfitting is a matter of degree, and the goal is not to remove it, which is impossible, but to keep it small enough that what remains is real.
Why it happens: the winner’s curse
Picture 1,000 configurations with no real edge at all, whose results differ only by luck. None is better than the others, yet one of them will top the table. On average, the best of them stands about 3.2 standard deviations above the mean: a gap that looks like skill and is pure selection. With 100 configurations the best would be about 2.5 standard deviations above; with 10,000, about 3.9.
That is the winner’s curse: whenever you pick the best of many noisy measurements, the winner tends to be the one that noise pushed upward, and on new data that push is gone. Those figures assume independent results. In an optimization, neighboring configurations are correlated, so the effective number of trials is smaller than the number of passes, but the effect is the same in kind: the top of the list is inflated.
Research has put numbers on it. Bailey, Borwein, López de Prado and Zhu (2014) showed that, with five years of data and strategies with no real edge, trying more than about 45 independent configurations almost guarantees finding one with an annualized in-sample Sharpe ratio of 1, while its expected out-of-sample Sharpe ratio is zero. An MT5 optimization usually tests thousands.
What makes it worse
- More parameters and finer ranges. Every parameter multiplies the combinations: four parameters with 20 values each make 160,000 configurations. The more freedom the optimizer has, the easier it is to find one that fits the noise.
- Few trades. The uncertainty of an average shrinks with the square root of the number of trades: to halve it, you need four times as many. With a few dozen trades, two or three lucky ones can decide the whole result.
- Decisions that never show up in the table. Changing the symbol, the timeframe or the dates, adding a filter or dropping a bad year after looking at the results are trials too. They do not appear among the passes, but they inflate the result just the same.
- Reusing the forward. If you optimize, look at the forward, tweak something and optimize again, the forward ends up taking part in the choice. After a few rounds it is no longer an independent test, just more in-sample.
- Judging by a single metric. The table is sorted by the criterion you optimized, so the passes that got luckiest in that metric gather at the top.
A different problem adds to all of this: markets change, and a pattern can be real and still fade. That is not overfitting, but it is one more reason to prefer configurations that work across a broad zone of parameters rather than at one exact point.
How to spot it in your MT5 results
None of these signs proves overfitting on its own, and their absence does not prove that a strategy works. Together, they tell you how far you can trust the best pass.
1. The best pass is an isolated peak
Look at its neighbors: the passes that change a single parameter by one step (from 30 to 35, from 0.1 to 0.2). If the best one has a profit factor of 2 and its neighbors hover around 1, you have not found a good zone, you have found a peak. A real edge should not vanish because one parameter moves one step, and live trading never reproduces the backtest exactly. What you are looking for is a plateau, a zone where many nearby configurations clear your minimums, and you want to stand in its center, with margin on every side.
A plateau is a necessary condition, not a guarantee: it shows that the result does not hinge on one exact value, not that the strategy will make money.
2. The forward bears no relation to the in-sample
With Forward enabled, MT5 splits the period: it optimizes on the first part and then re-tests the passes on the remaining stretch (according to the MT5 help, only the best ones: the top 10% in a complete search or the top 25% with the genetic algorithm, with a minimum number of passes; some real exports bring them all). Some decline is normal and expected: it is the winner’s curse at work. What gives overfitting away is a collapse: the best in-sample passes sinking in the forward, or no relationship at all between the order of the two lists.
One trap: do not simply pick the pass with the best forward. The moment you choose by it, the forward stops being a test and becomes part of the optimization, and its figures inherit the same inflation.
3. The best result does not beat chance
As we have seen, testing many combinations raises the best result on its own. The Deflated Sharpe Ratio of Bailey and López de Prado (2014) builds on that idea: it estimates the highest Sharpe ratio you would expect from luck alone, given how many trials you ran and how much their results vary, and measures whether yours clears it by enough. If it does not, the top pass may be nothing but noise. If it does, you have ruled out one explanation, the sheer number of trials, but that does not validate the strategy.
4. It only shines in the metric you optimized
Look at several metrics at once: profit factor, drawdown, recovery factor, Sharpe ratio and number of trades. A robust configuration is reasonable in all of them; an overfitted one tends to stand out in the criterion you optimized and fall short in the rest. No criterion protects you on its own, not even the complex criterion: each only changes which kind of luck gets rewarded.
5. A few trades make all the profit
In the Strategy Tester report of the chosen pass, compare the largest winning trade with the total net profit. If taking away the two or three best trades wipes out the result, the backtest rests on a handful of events that may not happen again. A robust edge is spread across many trades.
How to keep it under control in MT5, step by step
- Start from an idea, not from the optimizer. Know what market behavior your EA exploits and why. Optimize only the parameters that really change its behavior, with ranges that make sense for that idea and steps coarse enough to matter: testing 20, 21, 22 and so on multiplies the trials without telling you much more.
- Split your history in three. An optimization period; a forward period, which MT5 sets up for you (a half, a third or a quarter of the dates, or from a date you choose); and a final stretch that you leave out of the tester dates altogether and do not look at until the end. In Orometra we call it the unseen period.
- Write down your minimums and acceptance criteria before optimizing. The profit factor, drawdown and number of trades you would accept live, and what the final test must show for you to go ahead. Set after seeing the results, they bend to fit them.
- Use a fast model to search and a precise one to confirm. “1 minute OHLC” or “Open prices only” (the latter only if your EA trades at the opening of each bar) are fine for exploring. Re-test the finalists with “Every tick based on real ticks”, the most accurate mode according to MetaQuotes itself.
- Choose the center of a plateau, not the top of the list. Before keeping a configuration, check its neighbors one step away on each parameter. If its best value sits at the edge of the range you tested, widen the range: you do not know what lies beyond.
- Read the forward as a test, not as a second ranking. Expect some decline; worry about collapses and reversals. If you change something after seeing it, assume that forward is spent and judge the result on a new stretch.
- Check how sensitive it is to costs and execution. The tester uses the spread recorded in the history, and with real ticks it is the actual one. To see how your EA copes with wider spreads you have to change the symbol’s conditions, for example with a custom symbol whose specification and history you control. The Delays option simulates execution latency, including a random delay.
- Run the final test once. Backtest the chosen configuration on the stretch you kept aside and compare it with the criteria you wrote down. If it fails, do not re-optimize on that stretch: that would turn it into in-sample too.
- Go live small. Start on a demo account or with reduced risk, and compare live results with the plateau’s usual range, not with the best backtest figures.
If you want to go further: MT5’s built-in forward is a single split. Walk-forward analysis, which repeats the optimization over successive windows and tests each one on the next, gives a much more complete picture, but MT5 does not do it natively: it has to be done by hand or with third-party tools.
Common misconceptions
- “More data fixes it.” It helps, but if you also widen the ranges and add parameters, the number of trials grows faster than the information.
- “A good forward proves it.” Only if you did not use it to choose. And even then, a single period can turn out well by chance.
- “Optimizing for profit factor or Sharpe ratio instead of balance avoids it.” It changes what gets rewarded, not the selection problem.
- “Few trades with a high profit factor are better.” A profit factor of 3 over 20 trades is far less certain than it looks: a couple of trades going the other way could change it drastically.
- “If the backtest is that good, it must be real.” In a large optimization it is the other way around: the more spectacular the best result, the larger the share of luck it is likely to carry.
How Orometra helps
Orometra applies the checks in this guide to the XML of your MT5 optimization, and it does so in your browser: your files never leave your computer. In particular:
- Your minimums first. Only configurations that clear your floors enter the search, and the floors are required in each period separately.
- Quality without the Result column. It judges each configuration by several objective metrics at once, not by the criterion you optimized.
- Plateaus, not peaks. It looks at each configuration’s neighbors on your grid, rejects isolated peaks and recommends a configuration inside the plateau, chosen by its combined in-sample and forward rank averaged with its neighbors.
- The forward as a test. It uses the forward to confirm or demote plateaus, not to pick the best row.
- How much could be luck. It compares your best Sharpe ratio with what chance alone would produce given the number of trials, and measures how often the rule “take the top of the table” fails when the configurations are resampled.
- It tests itself. It repeats the search 50 times, moving its own thresholds by up to ±20%, to check that the recommendation does not depend on them, and does the same, with fewer repetitions, moving your minimums.
- Your search, measured. It detects whether the search was complete or genetic, how much of the space it covered and whether the grid has uneven steps, and warns you when that limits the conclusions.
- The final test. Drop in the HTML report of your backtest on the unseen period: it checks that the parameters match the recommended configuration, tells you whether the result is normal for that plateau, tells you whether there are enough trades to conclude anything and shows what happens if costs get worse.
The answer comes as a reliability level, from insufficient to strong, that grades how much your data back the recommendation. It never tells you to trade: it measures evidence, it does not give permission.
What Orometra cannot do
- It does not see the equity curve of each pass, because the MT5 optimization export does not include it. That is why it does not compute the Probability of Backtest Overfitting (PBO) or the classic Reality Check and SPA tests, which require it.
- It does not judge the quality of your price history or the costs in your backtest: if the backtest is optimistic, so is the analysis.
- The forward is used to validate and rank the plateaus, so it is not blind: only the unseen period is.
- A plateau is stability in your sample, not a promise of future profit.
Further reading
- Bailey, Borwein, López de Prado and Zhu (2014). Pseudo-Mathematics and Financial Charlatanism: The Effects of Backtest Overfitting on Out-of-Sample Performance. Notices of the American Mathematical Society.
- Bailey and López de Prado (2014). The Deflated Sharpe Ratio: Correcting for Selection Bias, Backtest Overfitting and Non-Normality. The Journal of Portfolio Management.
- Bailey, Borwein, López de Prado and Zhu (2017). The Probability of Backtest Overfitting. Journal of Computational Finance.
- MetaTrader 5 help: Strategy optimization and Real and generated ticks.