How MT5 Supports Custom Optimization Criteria in Strategy Testing
A profitable backtest can hide an uncomfortable question: profitable according to which measure? The Strategy Tester can rank parameter combinations by familiar statistics, but a developer may care more about drawdown, trade frequency, or the reliability of returns across market conditions. A high ranking is only meaningful if its scoring rule reflects the intended deployment.
In mt5, an Expert Advisor can supply its own numerical score through OnTester(). Selecting the custom optimization criterion lets the tester compare runs using that value. The flexibility is useful, although poorly constructed scores can reward behavior that looks attractive in a report and proves expensive in a live CFD account.
Combining Profit and Drawdown Into One Score
A developer can use TesterStatistics() inside OnTester() to retrieve results such as net profit and equity drawdown, then calculate a score that penalizes excessive losses. For example, dividing profit by a drawdown measure can favor steadier outcomes over the highest absolute return.
The denominator needs protection against zero or unusually small values. Otherwise, a strategy with negligible activity could receive an exaggerated score. Review the underlying profit, drawdown, and number of trades alongside the ranking rather than accepting the composite number alone.
Penalizing Strategies That Trade Too Infrequently
An attractive result from four trades offers little evidence about repeated execution. Custom criteria can reduce scores for runs below a chosen minimum trade count or impose a graduated penalty as observations become scarce.
More trades do not automatically make a system safer. Frequent CFD dealing incurs spreads, commissions where applicable, and potentially financing charges. A sensible criterion rewards an adequate sample without encouraging transactions merely to raise the count. Compare the test’s modeled costs with the broker’s current contract terms.
Testing Whether Execution Costs Change the Winner
Imagine two hypothetical parameter sets for a copper CFD strategy, each trading contracts representing 100 pounds. Set A completes 120 round trips and reports $4,800 net profit under an assumed $2 round-trip cost per contract. Set B completes 40 and reports $3,900 under the same assumption.
Suppose actual round-trip costs are $12 higher than modeled for each trade. Set A loses another $1,440 in costs, leaving $3,360; Set B loses $480, leaving $3,420. The original winner becomes the weaker choice without any change in the copper price path. A custom score can incorporate a conservative cost allowance, but the tester must still model execution realistically. Otherwise, the ranking simply conceals an optimistic assumption inside a formula.
Avoiding Genetic Optimization’s Preference for Misleading Peaks
The tester seeks higher custom criterion values when ranking optimization passes. In genetic optimization, those scores also influence which parameter combinations are explored further. A discontinuous formula that awards enormous bonuses at arbitrary thresholds can steer the search toward fragile corners of the parameter space.
For mt5 strategy research, a smoother score may be more useful than a severe pass-or-fail cutoff. Inspect neighboring parameter values and run an independent forward test. A broad region of acceptable outcomes often provides more evidence of robustness than a single spectacular maximum.
Keeping Custom Scores Reproducible Across Test Runs
An OnTester() calculation should depend on information available consistently at the end of each pass. If its formula relies on external files, mutable global assumptions, or data unavailable to testing agents, identical inputs may not yield comparable scores. The tester can display a precise ranking without guaranteeing that every pass was evaluated under identical conditions.
Record the scoring formula, input ranges, data period, modeling mode, and transaction-cost assumptions with each experiment. Before opening a CFD position based on an optimized EA, rerun the selected settings on untouched market data, compare the custom score with raw equity and deal statistics, and confirm that the broker’s current contract specifications match those used in testing.

