Orometra

Guide

Genetic or complete optimization in MT5: which one to use

When you optimize in MT5 you choose between testing every combination or letting a genetic algorithm hunt for the best ones. The choice does not only change how long you wait: it changes what you can conclude from the results. This guide explains how each one works, how to count your combinations and estimate the time, and how to decide.

Where you choose it

In the Settings tab of the Strategy Tester (Ctrl+R), the Optimization field offers, among other options, “Slow complete algorithm” and “Fast genetic based algorithm”. Next to it you choose the criterion. The parameters to optimize, with their start, step and stop, are set in the Inputs tab.

How many combinations you are asking for

Each optimized parameter takes (stop − start) / step + 1 values. The total number of combinations is the product of those numbers, and in a complete search each combination is one full backtest.

Example. FastMA from 10 to 30 in steps of 2: 11 values. SlowMA from 50 to 150 in steps of 10: 11 values. Stop loss from 1 to 3 ATR in steps of 0.5: 5 values. Take profit from 1 to 6 ATR in steps of 1: 6 values. Total: 11 × 11 × 5 × 6 = 3,630 combinations. Add a fifth parameter with 10 values and you reach 36,300.

To estimate the time, run one single test with the same dates and modeling and time it. MT5 spreads the passes across the testing agents of your computer (usually one per processor core, listed in the Agents tab), so the complete search takes roughly the number of combinations times the duration of one test, divided by the number of agents. With 3,630 combinations, 20 seconds per test and 8 agents: 3,630 × 20 / 8 ≈ 9,000 seconds, about two and a half hours.

Complete optimization

The slow complete algorithm runs every combination in your ranges. Its advantage is that the map is whole: you can see how the result changes as each parameter moves and whether the best zone is wide or a lone point. The Optimization Graph tab can even draw the result against two parameters, in 2D or 3D, which is a direct way to see a plateau or a peak.

In a complete search the criterion does not change what gets tested, only the order of the table and, with Forward enabled, which passes are re-tested on the forward.

Genetic optimization

The fast genetic algorithm starts with random combinations, keeps the ones that score best on your criterion and crosses and mutates them to breed the next ones, generation after generation, until they stop improving. It can find good zones in a fraction of the time, but it does not test everything: it concentrates where the criterion is high and barely visits the rest.

Two practical consequences. The criterion decides what gets explored, so a poorly chosen criterion sends the search to the wrong place. And since it starts at random, two identical runs can give different tables: a different top pass in a second run does not mean anything changed in your EA.

Why the genetic search makes overfitting easier

The algorithm actively hunts for the combination that scores highest, and that hunt also rewards the one that got lucky. It also leaves the map in pieces: around the best pass there may be few tested neighbors, and without them you cannot tell whether you are on a plateau or on a peak. That is why, with the genetic search, the top of the list deserves even less trust.

How much of the space was explored

Divide the number of passes by the total number of combinations. If a genetic search ran 5,000 passes out of 3 million combinations, it has seen less than 0.2% of the space. That is not a reason to throw the result away, but it is a reason to be careful when judging whether the best pass sits on a plateau: most of its neighbors were probably never tested.

Orometra works this out if you also give it the .set with your ranges. With genetic searches it does not invent neighbors that were never tested: it measures plateaus only with the configurations that exist, so it may fall short but never inflates the support, and it tells you when coverage limits the conclusions.

Which one to choose, step by step

  1. Count your combinations and estimate the time of a complete search as above.
  2. If it takes hours rather than days, use the complete search.
  3. If not, shrink the problem first: drop parameters that barely change anything, widen the steps and trim ranges that make no sense for your idea. Fewer combinations is not only faster: it also gives chance fewer opportunities to win.
  4. If it is still too big, use the genetic search to explore: find the promising zone, then optimize that zone with the complete search and narrower ranges.

That second, narrower complete optimization is exactly what the “range to re-optimize” .set that Orometra offers is for: it is centered on the recommended configuration and sized so that it can actually be run.

Common mistakes

Next step

Drop the XML of your optimization, complete or genetic, into Orometra, with the .set if you have it. It takes into account how much of the space was tested, is more cautious when the search was genetic and tells you whether there is a plateau behind the best pass or just a lucky point.

Analyze my results How Orometra decides →