Skip to content
All library documents

Custom Profit-to-Drawdown Optimization in the MT4 Tester

Article MQL5 articles

Summary

The article shows how to implement a custom optimization criterion in the MT4 Strategy Tester using profit divided by maximum drawdown. The example tracks peak equity and the largest subsequent equity decline, then evaluates a Moving Average Expert Advisor across parameter combinations. Since the tester does not expose an optimization-completion hook, the proposed workaround varies a counter parameter and maps each run to a Moving Average period and shift.

Results and parameters are written to a file across runs, then sorted by the custom score after the final run. The author discusses using global variables and a file pointer to preserve state, and warns that cached test results may skip initialization and teardown, leaving results incomplete. The method requires disabling the genetic algorithm and manually configuring a complete counter range. It is a tester-management technique, and the excerpt does not provide the resulting parameter values or evidence that the selected settings perform well out of sample.

Key ideas

  • A custom criterion can rank test runs by net profit relative to maximum equity drawdown.
  • A counter parameter can enumerate combinations when the tester lacks a suitable completion hook.
  • Global variables and a file can preserve state and collect results across separate test runs.
  • Cached optimization results may bypass code that records runs, producing incomplete output.
  • The example requires a full counter sweep and does not establish out-of-sample performance.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.