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
- 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 |
|---|---|
SL Value | 0.5 – 2.0, step 0.25 |
TP Value (ATR mode) | 3.0 – 8.0, step 1.0 |
BE Value | 1.0 – 3.0, step 0.5 |
PC1 Trigger Value | 0.5 – 2.0, step 0.25 |
Trail Distance Value | 1.0 – 3.0, step 0.5 |
Slow EMA Period | 18 – 26, step 1 |
Slowest EMA Period | 50 – 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 Nameto label each combination 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.