The MT5 strategy tester's optimizer will happily search thousands of parameter combinations and hand you the one that scored best on the past — which is precisely why it is an overfitting machine by design. This guide covers how the slow complete and fast genetic algorithms actually work, how to use the built-in Forward period as a walk-forward guardrail, and the research (Bailey, Lopez de Prado, White, Hansen) explaining why the best pass is almost always an overstatement. Educational material only, not financial advice: an optimized backtest is not a forecast, and trading carries a real risk of loss.
You cannot eliminate curve-fitting from optimization — searching parameters is fitting — but you can bound it: keep the parameter space small and the steps coarse, split your data with the tester's built-in Forward setting so every candidate is judged on data it never saw, prefer broad plateaus of good parameters over sharp isolated peaks, and treat the single best pass as the most suspicious result on the sheet, not the answer. Those four habits are the difference between using the optimizer and being used by it.
Understand what the tool is doing. The MT5 optimizer runs your EA repeatedly across combinations of the inputs you flagged for optimization, scores each pass by your chosen criterion (balance, profit factor, drawdown, Sharpe ratio, a complex composite, or a custom OnTester() value), and sorts. It is an argmax over historical outcomes. Nothing in that procedure distinguishes a parameter set that captured a real regularity from one that got lucky on this particular sample — both produce a high score, and the optimizer, by construction, surfaces whichever scored highest.
That is why the honest framing is that the optimizer is an overfitting machine by design. Its entire job is to find the parameters most flattered by the past. Your job is to build the procedure around it that distinguishes flattery from substance: out-of-sample confirmation, plateau analysis, and disciplined restraint about how many times you peek.
Everything that follows is educational only, not financial advice. Optimization tunes a backtest; it does not create an edge, no result here implies profitability, and trading carries a real risk of loss.
MT5 offers two search strategies in the Settings tab. Slow complete algorithm is a full grid search: every combination of every optimized input, at the start/step/stop values you set, gets its own pass. It is exhaustive and unbiased about the space, but combinatorics punish you quickly — four inputs with twenty values each is 160,000 passes.
Fast genetic based algorithm is a population-based search. It tests an initial generation of parameter sets, scores them by your optimization criterion, then breeds new generations biased toward the best performers — crossover, mutation, repeat — converging toward high-scoring regions without visiting most of the space. When the total combination count exceeds what the tester considers tractable, MT5 forces genetic mode regardless of your selection. Genetic runs finish enormously faster; the trade-offs are that results are not exhaustive, repeated runs can converge differently, and the selection pressure that makes it fast is precisely pressure toward whatever the criterion rewards on the in-sample data — including noise.
The optimization criterion dropdown decides what 'best' means: balance, profit factor, expected payoff, minimal drawdown, recovery factor, Sharpe ratio, a complex criterion, or Custom max — the value returned by your OnTester() handler. Custom criteria are underused; even a simple guard against thin samples improves what the genetic algorithm chases:
5
// Educational only — validate before trading; not financial advice.
double OnTester()
{
double trades = TesterStatistics(STAT_TRADES);
double pf = TesterStatistics(STAT_PROFIT_FACTOR);
if(trades < 100) // refuse to rank passes with too few trades
return(0.0);
return(pf);
}Without that guard, the optimizer routinely 'wins' with a parameter set that took three trades and got lucky three times — the purest form of the problem this article is about.
The statistics here are well established and worth knowing by name, because they explain quantitatively why your best pass will disappoint.
When you evaluate many strategies (or parameter sets) on the same data and keep the best, the winning score is biased upward — the maximum of many noisy estimates overstates the true quality of whatever produced it. Halbert White formalized the correction in his 2000 'Reality Check' for data snooping, and Hansen (2005) sharpened it with the Superior Predictive Ability test: both ask whether the best performer beats a benchmark after accounting for how many candidates were searched. An optimizer run over ten thousand passes is exactly the setting these tests were built for — and almost no retail workflow applies any such correction.
Bailey, Borwein, López de Prado, and Zhu attacked the same problem from the backtesting side. Their 'Pseudo-Mathematics and Financial Charlatanism' (2014) shows that with enough trials, a researcher is essentially guaranteed to find a strategy with an impressive in-sample Sharpe ratio even when no true edge exists, and their companion work defines the Probability of Backtest Overfitting and the Deflated Sharpe Ratio — which discounts a reported Sharpe by the number of trials and the non-normality of returns. Bailey and López de Prado also derive the minimum backtest length needed to have any confidence at all given the number of configurations tried: the more combinations your optimizer searches, the more history you need for the winner to mean anything.
The genetic algorithm makes none of this better and arguably makes it worse: its selection pressure concentrates search effort in regions where the criterion is highest, which — on a finite sample — includes regions where the criterion is high because of noise. The machine is doing its job. The correction has to come from your procedure.
MT5 ships a partial answer in the Settings tab: the Forward field, with options No, 1/2, 1/3, 1/4, and Custom. Set it to 1/3 and the tester splits your date range into a back period (the first two-thirds) and a forward period (the final third). Optimization runs only on the back period; the surviving passes are then re-run, untouched, on the forward period, and the results land in a separate Forward Results tab alongside the back-period Optimization Results.
This is a single train/test split — the simplest form of walk-forward validation — and reading it correctly is the skill. Expect degradation. A pass that earns a markedly lower but same-shaped result forward is behaving like something real plus selection bias; that is the normal, acceptable pattern. Distrust reversal. A pass that was top-decile back and bottom-decile forward was very likely fitted noise, however beautiful its in-sample curve. And look at the population, not just your favourite: if the back-period ranking has essentially no relationship to the forward-period ranking across all passes, the optimization as a whole found nothing transferable, and picking the best forward pass instead is just overfitting to the forward period.
Know the tool's limits. One split is weaker than a proper anchored walk-forward with multiple rolling windows (which you can approximate manually by repeating optimizations over shifted date ranges). The forward period is short by construction, so its statistics are noisy. And the guardrail only works while it is out of sample: the second time you adjust parameters because the forward results displeased you, the forward period has quietly become training data. That re-use — informal, incremental, invisible — is data snooping in slow motion, and it is the most common way traders defeat their own validation.
A workable discipline, in order of leverage:
Budget your parameters. Every additional optimized input multiplies the search space and, per Bailey and López de Prado's minimum-backtest-length result, raises the bar for how much history you need before the winner means anything. Two or three optimized inputs with coarse steps is a defensible search; eight inputs with fine steps is a lottery-ticket printer.
Look for plateaus, not peaks. After the run, examine the best pass's neighbours — same parameters, one step up or down on each axis. A robust region shows gently varying results across a neighbourhood; a spike surrounded by mediocrity is the signature of a fluke. MT5's optimization graph (and the 2D parameter surface view) makes this inspection quick, and it is the single highest-value habit on this list.
Re-validate at higher fidelity. Optimize on a fast mode if you must, but confirm finalists on Every tick based on real ticks with realistic spread. Parameter sets tuned on idealized fills often owe their ranking to those fills.
Hold out more than time. Forward periods hold out time; you can also hold out symbols. A parameter set that survives on a correlated instrument it was never tuned on has passed a test the optimizer could not game.
Ration your peeks. Decide in advance what forward-period result you will accept, run once, and abide. Every iterate-and-re-peek cycle consumes the out-of-sample data's evidential value, exactly as White's framework quantifies.
And keep the endpoint honest: a parameter set that survives all of this has earned plausibility, nothing more. This is educational material only, not financial advice; an optimized backtest is a fitted description of the past, never a promise about the future, and trading carries a real risk of loss.
Educational only — not financial advice. Trading involves substantial risk of loss.