How to Backtest an Expert Advisor Without Overfitting

How to Backtest an Expert Advisor Without Overfitting

2 October 2026, 22:18
Ebrahim Yousry A Ahmad
2
62
A profitable backtest is easy to produce.

A trustworthy backtest is much harder.

One of the easiest mistakes in EA development is repeatedly changing the strategy until the historical results finally look good.

  • Change the stop loss.
  • Add a filter.
  • Remove a bad trading hour.
  • Adjust the target.
  • Test again.

Eventually, the equity curve looks excellent.

But the strategy may simply have learned the past.




This is overfitting.

Start With the Trading Idea

Before looking at the final profit curve, the strategy should already make sense.

You should be able to explain:

  • What market behaviour is being traded?

  • What invalidates the setup?

  • Why is the stop placed where it is?

  • Why is the target reasonable?

A backtest should test an idea.

It should not be used to invent one retrospectively.

Be Careful With Optimisation

MetaTrader 5 can test thousands of parameter combinations quickly.

That is powerful, but it also creates a problem.

If you test enough combinations of stop losses, take profits, trading hours, filters and indicator settings, eventually some of them will look excellent simply by chance.

The highest historical return is not always the most useful result.

I prefer looking for stability.

For example, if a strategy performs well with a target of 20 points but suddenly collapses at 19 or 21, that deserves suspicion.

A more robust strategy should usually tolerate small changes without completely falling apart.

Don't Try to Remove Every Losing Trade

Losing trades are normal.

If every change to the EA is made because you noticed a historical loser and wanted to eliminate it, the system can gradually become fitted to that exact period.

Sometimes the correct response to a losing trade is simply:

leave it alone.

The objective is not to create a perfect historical chart.

It is to find out whether the original trading logic has an advantage despite the losses.

Test Difficult Periods Too

It is easy to focus on the periods where a strategy performs well.

The difficult periods are often more informative.

Try to include different market conditions:

  • Trends

  • Ranges

  • High volatility

  • Quiet markets

  • Periods where the strategy struggles

These periods help show how much risk the strategy can experience when conditions are not ideal.

Use Realistic Testing

Where execution, spread, stop placement and intrabar movement matter, I prefer MT5's:

Every tick based on real ticks

It still does not make a backtest equivalent to live trading, but it can provide a more realistic historical simulation than simplified modelling.

And don't look only at net profit.

Also check:

  • Maximum drawdown

  • Number of trades

  • Profit factor

  • Win rate

  • Losing streaks

  • Trade duration

Profit without the accompanying risk tells only half the story.

My Main Rule

The principle I try to follow when developing an EA is simple:

Change the strategy because the market logic justifies the change — not because the equity curve asks for it.

EUR FORGE

I used the same approach while developing EUR FORGE, my EURUSD Expert Advisor for MetaTrader 5.

It uses predefined trade and risk-management logic and does not use martingale or grid recovery.

One historical MT5 Strategy Tester period:

1 April – 24 September 2026
EURUSD · IC Markets MT5
Every tick based on real ticks
35 trades
60% win rate
Profit factor: 1.91
Maximum equity drawdown: 3.84%
10,000 → 11,559.26

These are historical Strategy Tester results only. They are not live performance and do not guarantee future results.

EUR FORGE is available on the MQL5 Market for anyone who wants to test it independently.

A good backtest isn't the one you managed to make perfect. It's the one the strategy survived without needing you to rewrite the past.