Skip to content
All library documents

Saving Equity Curves and Custom Metrics During Expert Advisor Optimization

Article MQL5 code base

Summary

This MetaTrader 5 tutorial explains how to instrument an Expert Advisor so an optimization workflow can save balance and equity data and attach custom criteria to each test pass. It describes adding calls in tick and tester lifecycle functions, recording selected values in the tester callback, and returning a custom fitness value. The saved frames can then be processed into charts and an HTML report. The Moving Average example shows how the instrumentation is added to an existing Expert Advisor.

The article also addresses readability when many parameter values are tested: it suggests using a spaced enumerated set of inputs to reduce the number of plotted lines. In the example, a Moving Average period appears strong in the backtest, but the author cautions that top backtest results may not perform best out of sample. This is a reporting and optimization workflow, not evidence that the example strategy is profitable; the quality of conclusions still depends on the chosen metrics and forward testing.

Key ideas

  • Tester callbacks can record balance and equity observations during Expert Advisor optimization.
  • Custom criteria can be added to reports and used to define a fitness value.
  • Saved optimization frames can be processed into charts and an HTML report.
  • A spaced set of parameter values can make results easier to inspect.
  • The author warns that the strongest backtest result may not be the strongest forward result.

Tags

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