Preset Perturbation Generator
A single backtest result is one sample from a parameter space, not proof the strategy is robust at those exact numbers. A preset that only performs well at its published values, and falls apart the moment one input moves by a few percent, is usually curve-fit rather than genuinely edge-bearing. The honest way to check is to test a neighbourhood of nearby presets and see whether performance holds up across the neighbourhood or collapses outside one narrow point - but hand-editing a dozen numbers into a dozen separate .set files to do that is tedious enough that most traders skip the check entirely. This script does the tedious part. It reads one baseline .set file from the sandbox, and for every purely numeric parameter it writes a requested number of copies with that value multiplied by a random factor within a chosen plus-or-minus percentage. Non-numeric parameters (strings, and any line that is not a plain number) are copied through unchanged, and the optimizer-only tail some .set files carry after "||" is preserved exactly rather than perturbed, since that tail encodes optimization range/step settings, not the parameter's actual value. The output files are ready to load one at a time into the Strategy Tester, or to feed into a batch of manual runs, to see how sensitive the result actually is to small changes around the published numbers. The script does not run any test itself, does not judge the results, and does not know which parameters are safe to perturb (a lot-size input and a magic number are both "numeric" to a text parser) - see Notes And Limitations before trusting the output blindly. Notes and limitations This is a text-level perturbation, not a strategy-aware one. The script has no idea which lines in a .set file are a stop-loss distance, a lot size, a magic number, or an indicator period - every line whose value parses as a plain number is treated the same way. A magic number or a timeframe-style input that happens to be numeric will also be perturbed, which usually makes no sense; review the generated files before running them, or hand-edit the offending lines back afterwards, if the preset contains parameters that should never move. Perturbed lot-size or risk inputs are not re-normalised to the broker's MODE_LOTSTEP/MODE_MINLOT/MODE_MAXLOT afterwards - that only happens once the EA itself reads and normalises its own inputs when it starts, the same as it would for any other .set file. Random perturbation, applied once per parameter independently, is a crude substitute for a proper multi-dimensional sensitivity/optimization sweep. It is useful as a fast first pass to catch a preset that is grossly fragile, not as a replacement for a full walk-forward or Monte Carlo robustness study. The script only writes files; nothing it produces is loaded into the Strategy Tester automatically.
Script · MT5 · v1.0 · Free
About Preset Perturbation Generator
Preset Perturbation Generator is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Baseline file, Copies and Perturb percent. MQL source code included.
Files in the download: PresetPerturbationGenerator.ex5, PresetPerturbationGenerator.mq5, PresetPerturbationGenerator.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Baseline file | Baseline.set | Baseline .set file (in MQL5\Files) |
| Copies | 10 | Number of perturbed copies to write |
| Perturb percent | 10.0 | Max perturbation, percent of each value |
| Random seed | 0 | Random seed (0 = time-based, non-repeatable) |
| Skip zero values | true | Leave 0-valued numeric parameters unchanged |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Alerts · MT5 Script · MQL5 Source Code