Loading…

Evolution Strategy Optimiser

An evolution strategy searches a continuous parameter space by keeping a small population of "parent" candidate points, generating a larger batch of "offspring" by mutating them with random noise, evaluating every offspring against the objective function, and selecting the best ones to become the next generation's parents. Unlike a single-point search (hill climbing, simulated annealing), a population-based search like this naturally hedges its bets across several regions of the search space at once. This header is honest about what it is NOT: it is not full CMA-ES. Real CMA-ES adapts a full covariance matrix over the generations, letting mutation stretch and rotate to match the local shape of the landscape - correlated parameters, different sensible step sizes per dimension - and that adaptation is genuinely valuable on hard problems. It also needs matrix inversion/eigendecomposition machinery that plain MQL4, with no matrix library, cannot provide safely. This header instead mutates every dimension with an ISOTROPIC (same size, uncorrelated) Gaussian step, and adapts only a single scalar step size (sigma) via the classic 1/5 success rule: when more than a fifth of the offspring beat the parent generation's mean, sigma grows, because the search is doing well and can afford bigger steps; when fewer than a fifth do, sigma shrinks, because it is likely close to a optimum and needs to refine. That single adaptive knob is still real, useful self-tuning - just not per-dimension or correlated step shaping. Call this a genuine, simplified (mu,lambda)-ES, not CMA-ES under a different name. Selection is COMMA-style (the next generation's parents are always the best mu of the freshly mutated offspring, never the old parents themselves) - a non-elitist choice that lets the population step over a shallow local dip that greedy elitist selection would get stuck defending. Because comma selection can lose the single best point ever found from the visible population, the best point across the ENTIRE run is tracked separately and is what the optimiser actually returns. Notes and limitations - This is a simplified isotropic-mutation ES, not full CMA-ES - see the full description above. It does not learn correlations between parameters or per-dimension step sizes; only one global step size is adapted. - To MAXIMISE an objective instead of minimising it, hand in a wrapper function that returns the negation of the value you actually want maximised - the optimiser core only ever minimises. - lambda must be >= mu (standard ES requirement) or EsOptimise returns false - there would not be enough offspring to even fill the next parent generation otherwise. - Comma selection means the reported best point is tracked across the whole run, not read off the final generation - the final generation's population can, by design, be worse than the best point already found, since comma selection deliberately does not keep old parents around. - MathSrand() controls the whole run's reproducibility, since MQL4's MathRand() is one shared global stream - call it before EsOptimise for a repeatable result, as the demo does.

Script · MT5 · v1.0 · Free

About Evolution Strategy Optimiser

Evolution Strategy Optimiser is a script for MetaTrader 5. It has 4 settings, such as Mu, Lambda and Generations. MQL source code included.

Files in the download: EvolutionStrategyOptimiser.mq5.mqh, EvolutionStrategyOptimiser.txt, EvolutionStrategyOptimiserDemo.ex5, EvolutionStrategyOptimiserDemo.mq5.

Settings

SettingDefaultWhat it does
Mu5number of parents
Lambda20number of offspring per generation
Generations60number of generations to run
Initial sigma1.0starting mutation step size

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria