Skip to main content

Optimization Fundamentals

Optimization is the process of testing many input combinations on historical data.

It can help you compare settings, but it can also create curve-fit results that look good in Strategy Tester and fail later. Treat optimization as research, not proof.

warning

Never evaluate a setup only on the same data used to choose its settings. Always reserve later data for out-of-sample testing and then forward test on demo.

What Optimization Actually Does

In MT4, optimization runs repeated Strategy Tester passes with different input values.

For example:

Run 1: RiskPercent=1.0, MaxSpread=3.0
Run 2: RiskPercent=1.5, MaxSpread=3.0
Run 3: RiskPercent=2.0, MaxSpread=3.0
...

The optimizer then sorts the results by a selected metric.

The top result is the best result inside that specific test setup. It is not automatically the best setting for live trading.

Backtesting vs Optimization

TaskWhat it doesMain risk
BacktestTests one fixed setupMay be too narrow
OptimizationTests many setup variationsCan overfit historical data
Out-of-sample testTests selected settings on unseen later dataCan still fail live
Forward testTests on demo/live market feed without historical hindsightTakes time and still has risk

Why Optimize

Good reasons:

  • Compare a small number of important settings.
  • Check whether a preset is sensitive to small changes.
  • Adapt a setup to a symbol or timeframe it was designed for.
  • Review whether a setting still behaves acceptably after a market regime change.
  • Build a candidate preset for later validation.

Bad reasons:

  • Trying to recover after one losing trade.
  • Searching for a perfect equity curve.
  • Optimizing every input because it is available.
  • Re-running until one backtest looks impressive.
  • Using a short period that happens to contain favorable market behavior.

Curve Fitting

Curve fitting happens when settings are fitted too closely to historical noise.

Common warning signs:

  • Too many optimized inputs.
  • Very small step sizes.
  • Very short test periods.
  • Perfect or near-perfect results.
  • One exact value works, nearby values fail.
  • The setup fails when tested on later data.
  • Most profit comes from one trade or one short period.

How Many Inputs To Optimize

For most users, optimize only one to three important settings at a time.

More inputs create more combinations and more chances to find a result that only worked by coincidence.

Good candidate inputs are settings that directly affect entry logic, stop placement, trade management, or filters.

Avoid optimizing:

  • Magic number
  • Chart colors
  • Alert preferences
  • Debug logging
  • Display-only settings
  • Many on/off switches at the same time

Risk Settings

Be careful optimizing RiskPercent or lot-size settings.

Risk changes the size of gains and losses. It can make a backtest look better without improving the underlying trade logic.

A safer workflow is:

  1. Evaluate the strategy logic at conservative risk.
  2. Check drawdown and trade distribution.
  3. Choose risk only after the setup has passed validation.

Ranges And Step Sizes

Use realistic ranges.

Too narrow:

BuyBuffer = 7.0 to 7.2, step 0.1

This may only search around a value you already chose.

Too wide:

BuyBuffer = 1.0 to 100.0, step 0.1

This creates too many passes and includes unrealistic values.

Better:

BuyBuffer = 5.0 to 20.0, step 2.5

This checks a practical range without pretending that one decimal point is meaningful.

Data Split

Use separate periods:

In-sample:
2020-2023
Use this period to optimize.

Out-of-sample:
2024-2025
Use this period to test the selected settings without changing them.

If the setup fails out-of-sample, do not keep adjusting it on that same out-of-sample period until it passes. That turns the out-of-sample period into another optimization period.

Optimization Criteria

Avoid optimizing only for net profit. Net profit can reward excessive risk.

Common metrics to review together:

  • Profit factor
  • Maximum drawdown
  • Expected payoff or average trade
  • Trade count
  • Consecutive losses
  • Recovery factor
  • Stability across periods

No single metric is enough.

Complete Search And Genetic Optimization

Complete search tests every combination in the selected grid. It finds the best result inside that grid, but the grid itself may still be badly chosen.

Genetic optimization samples the search space and can be faster when there are many combinations. It may miss useful areas and can still overfit.

Practical workflow:

  1. Use broad, sensible ranges.
  2. Use genetic optimization only for early exploration if the search is too large.
  3. Narrow the range.
  4. Re-test with a smaller complete search if practical.
  5. Validate on out-of-sample data.

Modeling Quality

Faster modeling can be useful for early screening, but validation should be done with the most realistic settings available in your MT4 environment.

Be especially careful when the EA uses:

  • Tight stops
  • Trailing stops
  • Pending orders
  • Spread filters
  • Intrabar entry or exit behavior

These can be more sensitive to tick modeling, spread, slippage, and broker execution.

Practical Workflow

  1. Define the question you are testing.
  2. Choose one to three meaningful inputs.
  3. Use practical ranges and step sizes.
  4. Split data into in-sample and out-of-sample periods.
  5. Run the optimization.
  6. Review the top group, not only the top row.
  7. Look for parameter clustering and stable areas.
  8. Test selected settings out-of-sample.
  9. Run sensitivity checks.
  10. Forward test on demo before live use.

Decision Rules

Reject or pause a setup if:

  • Out-of-sample performance collapses.
  • Nearby parameter values fail badly.
  • Drawdown exceeds your tolerance.
  • Trade count is too small to review.
  • Costs or spreads are unrealistic.
  • The result depends on one unusual trade.

Next Steps