Skip to main content

Optimization

MT5's built-in optimizer runs the EA across a grid of parameter values and ranks results by a fitness score. Banana EA MT5's OnTester() function returns a robustness score rather than raw profit, which is a more meaningful selection criterion for live performance.

Robustness fitness function

The EA's tester fitness is based on:

  • Daily equity returns — normalised to reduce scale bias across different account sizes
  • Probabilistic Sharpe Ratio (PSR) — statistical significance of the Sharpe Ratio against a benchmark
  • Bounded fitness — results are bounded to prevent extreme outliers dominating the ranking
  • Hard gates — results failing minimum trade count or maximum drawdown criteria are penalised heavily

The optimizer therefore selects configurations that are consistently profitable and low-drawdown rather than just high raw-profit over the test period.

Setting up an optimization run

  1. Open Strategy Tester and configure as per Backtesting Setup.
  2. Select Optimization mode in the tester.
  3. In the Inputs tab, enable the checkboxes on the parameters you want to optimize and set their Start / Step / Stop ranges.
  4. Choose an optimization criterion — select Custom max to use the EA's built-in robustness score.
  5. Click Start.

MT5 supports multi-threaded and cloud optimization natively, which significantly reduces run times on multi-core machines.

Good starting candidates (keep ranges narrow to avoid over-fitting):

InputSuggested range
SL Value0.5 – 2.0, step 0.25
TP Value (ATR mode)3.0 – 8.0, step 1.0
BE Value1.0 – 3.0, step 0.5
PC1 Trigger Value0.5 – 2.0, step 0.25
Trail Distance Value1.0 – 3.0, step 0.5
Slow EMA Period18 – 26, step 1
Slowest EMA Period50 – 100, step 10

Avoiding over-fitting

  • Out-of-sample validation: optimize on years 1–3, validate on year 4–5 with no further changes.
  • Prefer robust zones: a configuration that is second-best on the in-sample period but holds up out-of-sample beats the top in-sample result.
  • Limit the number of optimized inputs: the more parameters you vary simultaneously, the higher the risk of curve-fitting to historical noise.
  • Use Optimization Set Name to label each combination so you can track which set you are running on live charts.

Saving best settings as a preset

After optimization:

  1. In the Results tab, right-click the best result → Set input parameters.
  2. In the Inputs tab, click Save to write a .set file.
  3. Load this preset in the EA inputs dialog when attaching to a live chart.