MQL5 Expert Advisor robustness testing
by Mahé Chadeffaud, founder of Stochastly
How can the MetaTrader 5 forward test check an optimized Expert Advisor?
Set Forward to a half, a third, a quarter or a custom date before optimizing. The tester selects parameters on the earlier part of the history and reruns them on the later part; compare the Back and Forward results for the same settings.
MetaTrader 5 can test an Expert Advisor with real ticks or simplified bar models. Parameter selection and test mode both change what a result supports.
Price models in the tester
MetaTrader 5 offers real ticks from a broker, generated ticks, one minute OHLC and open-price testing. The OHLC mode constructs control points from minute bars; open-price mode calls OnTick at bar open.
A fast model can help screen variants. Recheck finalists with real ticks where the broker supplies them, especially when intrabar order timing changes trades.
Separate optimization from evaluation
The Strategy Tester offers exhaustive search and a faster genetic algorithm for input parameters. Its forward option evaluates selected settings on a later portion of the chosen history.
A genetic search still selects from many trials. Repeatedly changing the grid, criterion or forward period after reading results reuses that history for design. Count those attempts and keep a final period untouched.
Forward test an exported Expert Advisor
Compile the exported MQL5 file in MetaEditor, then select that Expert Advisor, symbol, dates and tick model in the MetaTrader 5 Strategy Tester. Set Forward to one half, one third, one fourth, or a custom start date before optimization.
MetaTrader splits the chosen historical interval into an earlier optimization period and a later forward period. It reruns selected parameter sets on the later period; compare the Back and Forward Results tabs for the same settings. Reserve a separate untouched period if the forward results guide another revision.
Before export, Stochastly can report out-of-sample and anchored walk-forward results for the strategy selection. Its Python export test compares engine trades with generated Python trades at zero tolerance; the MQL5 source check does not execute the EA, so the MetaTrader forward run and trade comparison remain destination checks.
Export and compare the same rule
For supported graph strategies, Stochastly renders MQL5 from the same expression tree used by its Python and Pine outputs. It checks defined identifiers in the generated source but does not run MetaEditor or the MetaTrader tester.
The export report names coverage and omitted graph nodes. Compare entries, direction, session rules, stops, costs and fills between the Stochastly backtest and the Expert Advisor tester before interpreting performance.
Use walk-forward results, DSR and PBO to assess the selected rule before export. Live broker execution is planned once the applicable regulation is in place.
Frequently asked questions
Is an optimized Expert Advisor an out-of-sample result?
The optimization interval selected the parameters. A forward interval can test them later, provided its results do not feed another revision.
Does an MQL5 export compile automatically?
Stochastly checks identifiers in generated source. Compile in MetaEditor and test the Expert Advisor in MetaTrader 5.
Sources
MetaQuotes (n.d.). Strategy Testing. MetaTrader 5 Help. Accessed 2026-10-03.
MetaQuotes (n.d.). Strategy Optimization. MetaTrader 5 Help. Accessed 2026-10-03.
MetaQuotes (n.d.). Real and Generated Ticks. MetaTrader 5 Help. Accessed 2026-10-03.