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 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
- Open Strategy Tester and configure as per Backtesting Setup.
- Select Optimization mode in the tester.
- In the Inputs tab, enable the checkboxes on the parameters you want to optimize and set their Start / Step / Stop ranges.
- Choose an optimization criterion — select Custom max to use the EA's built-in robustness score.
- Click Start.
MT5 supports multi-threaded and cloud optimization natively, which significantly reduces run times on multi-core machines.
Recommended inputs to optimize
Good starting candidates (keep ranges narrow to avoid over-fitting):
| Input | Suggested range |
|---|---|
| Buy stop-loss buffer in pips | 0.0-2.0, step 0.25 |
| Sell stop-loss buffer in pips | 0.0-2.0, step 0.25 |
| Default TP in R, 0 disables | 1.0-5.0, step 0.5 |
| Break-even trigger in R | 0.5-3.0, step 0.25 |
| Partial close 1 trigger R | 0.5-3.0, step 0.25 |
| Trailing activation R | 0.5-4.0, step 0.25 |
| Fast EMA period / Slow EMA period / Slowest EMA period | Keep ranges narrow around the preset values |
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 clear preset filenames and notes so you can track which set you are running on live charts.
Saving best settings as a preset
After optimization:
- In the Results tab, right-click the best result → Set input parameters.
- In the Inputs tab, click Save to write a
.setfile. - Load this preset in the EA inputs dialog when attaching to a live chart.