Learn › EAs and automated trading
What Is Overfitting? Pick EA Settings on a Plateau, Not a Peak
Tuning an EA until the backtest looks great may be pure luck. Pick values whose neighbours also work, split search and confirm years, and beat a plain lot increase.
- A good setting is one where nearby values give similar results, not the single best value.
- The more setting combinations you try, the more of them look good by luck.
- Pick values on older years, then confirm on newer years you didn't use to pick.
- A filter that pushes Profit factor up can wipe out almost all of the profit.
- Every tweak has to beat simply raising the lot size at the same Drawdown.
Overfitting (tuning settings to fit the past too closely) means adjusting an EA’s settings until the backtest looks great, when that great look comes from catching random details of the data you tuned on. On new data, the result disappears. Two defences work in practice: pick values whose neighbours also give good results (a plateau) instead of a value that’s good at just one point (a peak), and pick values on one period, then check them on another period you didn’t use to pick.
What causes overfitting
An EA has many parameters (settings), such as the entry level, Stop loss distance, profit target distance and filters. Every time you try a new value and keep the one that did better, you are letting past data choose the value for you.
Past data mixes two things: price behaviour that tends to repeat, and coincidences that don’t, such as one big news day that made one batch of trades a large profit. Tune enough, and the values start capturing the second part. The Backtest (testing on past data) keeps getting better while the real skill doesn’t improve at all.
The more combinations you try, the more fake winners you find
Put it in numbers. Say we try 40 setting combinations, and none of them has any real edge. Each combination has a 5% chance of looking good by pure luck.
- Expected number of combinations that look good by luck = 40 × 5% = 2 combinations
- Chance that none of the 40 gets lucky = 0.95 to the power of 40 ≈ 0.129, or 12.9%
- Chance that at least 1 combination gets lucky = 100% − 12.9% ≈ 87%
Check: 2 combinations out of 40 = 2 ÷ 40 = 5%, which matches the chance we set.
The number of combinations grows faster than you think. 3 settings with 5 values each = 5 × 5 × 5 = 125 combinations, so expect 125 × 5% ≈ 6 fake winners.
Peak vs plateau
The simplest way to tell real from lucky is to look at nearby values. If a system has a real edge at level 61.8, then 58 or 65 should give similar results. If it’s good at only one point and breaks with a small shift, that point is usually luck.
The picture below comes from two of our backtests on gold (XAUUSD) M1, real tick data, January to September 2026, 0.10 lot per trade, $10,000 balance.
- A. A system that buys pullbacks at 61.8% of the previous large ZigZag swing, measured by net profit ÷ Drawdown (Drawdown is how far the balance falls from its peak; the higher this ratio, the more profit per unit of pain you have to sit through)
- B. A system that fades when price runs past the previous swing range to various levels, measured by net profit
Panel A is a plateau. Entries at 58, 61.8 and 65 give 3.42–3.86, all close together. Only 55 drops to 1.73. The value we use (61.8) sits in the middle of the plateau, so if the market shifts a little, there’s still room to absorb it.
Panel B is more worrying. 127.2 made $3,526, but 120 broke even and 144 lost $1,895. In that round we tried 6 levels × 2 profit-target styles = 12 combinations, so we’d expect 12 × 5% = 0.6 fake winners. A positive point standing alone like that can’t be trusted yet.
So we shifted the other settings around 127.2: Stop loss, profit target, neighbouring levels and time window, 10 setups in total. 8 were positive and 2 lost. Then we ran other years on 1-minute data: 2025 +$2,914 and 2024 +$1,641. It passes, but it’s clearly weaker than panel A, and 1-minute data tends to flatter results. For 2026, that kind of data gave +$5,366 versus +$3,526 on real ticks, 1.52 times higher. Backtest results do not predict the future and are not a return you should expect.
The best value in the table isn’t always the one to pick. The one to pick sits in the middle of a cluster of good values close together.
The in-sample trap: never confirm on the years you picked from
In-sample is the data period used to pick values. Out-of-sample is the period you didn’t touch while picking. In-sample results always look better than reality. So our research notebook set a rule from the start: search on 2022–2024, confirm on 2025–2026, and never pick a formula from the confirm years.
But we broke this rule ourselves. 2026 has real ticks and a volatile market, so new ideas almost always got tried on 2026 first. The result:
- A combined system of several pullback setups on ZigZag swings of different sizes. With every value picked from 2026, it made +$43,963, Profit factor 1.47. Running the same values on 2025 (simulated ticks) gave −$694 and a 61.2% Drawdown, nearly wiping out the account. 2024 was −$197.
- A system that follows large ZigZag swings and times entries with small swings (simulated ticks every year, 0.10 lot, $100,000 balance). 2026 made +$22,810, but 2022–2025 combined had 2,189 trades with a 48.61% win rate, when it needed 51.88% just to break even. That gap is too wide to be just bad luck (Win rate vs break-even).
All of these are backtest results. Past results do not predict the future and are not a return you should expect.
The lesson: use the latest year to find ideas, and trust it when it says “this one is dead.” But which values to use has to be decided across many years. (For why each period differs so much, read When the market changes character.)
A filter that’s only good for one year
A filter is an extra condition that cuts out some trades. It’s where overfitting hides best, because almost any filter can make the tuning year look better.
We added a volatility filter (hourly ATR above its 20-day average) and an M15 confirmation bar to the system in panel A. For 2026, Profit factor (total profit divided by total loss) rose from 1.44 to 4.02. It looked like a find, until we ran other years.
| Year | No filter | ATR filter + M15 confirmation bar |
|---|---|---|
| 2026 (real ticks) | +5,320 | +3,412 |
| 2025 | +2,091 | +465 |
| 2024 | +1,178 | −845 |
| 2023 | +221 | −87 |
Gold M1, 0.10 lot, $10,000 balance. 2023–2025 use 1-minute data. Values in dollars. Backtest results do not predict the future.
Over the three years not used for tuning, no filter totals 2,091 + 1,178 + 221 = +$3,490. With the filter, 465 − 845 − 87 = −$467. This filter was tuned purely to 2026, so we use the unfiltered version.
Higher Profit factor doesn’t mean better
Tighter filters often push Profit factor up, because they cut down to only the trades that happened to do well in that data. An example from a system buying pullbacks at the 50% level of medium ZigZag swings (gold M1 real ticks, Jan–Sep 2026, 0.10 lot, $10,000 balance):
| No filter | Nested small-swing filter | |
|---|---|---|
| Profit factor | 1.48 | 2.14 |
| Net profit | +10,927 | +1,492 |
| Trades | 406 | 27 |
Profit factor rose 45%, but profit fell to 1,492 ÷ 10,927 = 13.7% of the original, and trades fell to 27 ÷ 406 = 6.7%. A sample of 27 trades is too small to tell you anything. Backtest results do not predict the future.
It has to beat “just raising the lot” at the same Drawdown
Raising the lot is the cheapest tweak there is. No extra trades, no extra spread, no extra complexity. In our tests, profit and Drawdown in money scaled with lot size almost in a straight line. So any tweak that raises profit and Drawdown together first has to beat raising the lot to the same Drawdown.
A real example: another 61.8% pullback system, gold M1 real ticks, 2026, 0.01 lot, $3,000 balance. We tried switching from a fixed lot to a risk-based lot of $12 per trade.
- Fixed lot: profit +2,532, Drawdown $265
- Risk-based lot: profit +2,817, Drawdown $375
Profit rose by $285, which looks like an improvement. Now imagine just scaling up the fixed lot to the same Drawdown:
- Lot multiplier = 375 ÷ 265 = 1.415 times
- Expected profit = 2,532 × 1.415 ≈ $3,583
- Compare 3,583 with 2,817: simply scaling the lot makes $766 more at the same Drawdown
Check: 265 × 1.415 ≈ $375, which matches the other version’s Drawdown. 2025 and 2024 (1-minute data) came out the same way. So this method doesn’t add skill; it just adds size at a poor rate. Backtest results do not predict the future.
A tweak that raises profit but raises Drawdown faster isn’t an improvement. It’s just a more expensive, roundabout way of raising the lot.
Common mistakes
- Grabbing the top row of the Optimization table. That row is usually the luckiest combination, not the best one. Pick a value in the middle of a plateau.
- Picking and confirming on the same period. The result always looks great, because the answer was chosen to fit the test. Split the periods before you start, and run the confirm period only once.
- Confirming with years you hand-picked. Two years that both happened to be good can fool you. Use every year you have and look year by year.
- Ignoring data quality. 1-minute data and real ticks can give very different results (Tick data quality in MT5).
- Re-tuning after every losing streak. Losing streaks are normal (Losing streaks are normal). Chasing the latest period is overfitting to the latest data.
Frequently asked questions
Can I use Optimization in MT5?
Yes. Use it to find which area of the settings gives good results, but don't grab the top row of the table. Check whether nearby values are good too, then test the chosen values on a period you didn't optimize on before you trust them.
My confirm years are worse than the years I picked on. Is the system broken?
Some drop-off is normal, because the chosen values usually carry some of that period's luck. What to watch for is a turn into a loss, or a Drawdown that jumps several times over. That means those values only captured quirks of the period you picked on.
How many years of testing is enough?
There's no fixed number. At minimum you need a period you didn't use to pick values, and it should include both fast-moving and quiet markets. Confirming with two years that both happened to be good can fool you too.
This is general education, not investment advice. Trading is risky and you may lose all of your capital.