Designing Custom Expert Advisor Optimization Criteria
Summary
This article explains how to define custom optimization scores for MetaTrader 5 Expert Advisors through the tester’s OnTester mechanism. It outlines built-in genetic optimization criteria and shows how a custom score can combine outcomes such as profit, drawdown, trade count, or recovery factor. More involved examples include judging the smoothness of the balance curve and a proposed coefficient intended to assess the relationship between average wins, losses, and win rate.
The examples use a moving-average trading system and tester statistics to calculate scores after each run. The article notes that custom criteria are used with genetic optimization and that larger returned values rank better. It cautions that the sample calculations need safeguards, including handling zero drawdown, and advises against overfitting by preferring middle-of-the-range parameter results for one proposed criterion. These are implementation ideas, not evidence that the resulting parameters will generalize: optimization scores still need sound statistical justification and out-of-sample validation.
Key ideas
- A custom tester criterion can combine multiple performance statistics into one score for genetic optimization.
- The tester calls OnTester after each run, and the returned value is used to rank parameter sets.
- Possible score components include profit, drawdown, trade count, recovery factor, balance-curve smoothness, and a proposed safety coefficient.
- Custom formulas need safeguards for edge cases such as zero drawdown.
- A high in-sample score does not establish robustness, so optimized results require validation beyond the fitting period.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.