Orometra

Guide

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

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.

An isolated peak (left) clears your minimums at a single point: one step either way and it falls below them. A plateau (right) clears them across a whole zone, and its center leaves margin on both sides.

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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. 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

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:

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

Further reading

Analyze my results How Orometra decides →