Here's a truth most EA sellers won't tell you: any Expert Advisor can show stunning backtest results if you optimize hard enough. Give me any strategy — even a random entry system — enough optimization passes, and I'll show you a perfect equity curve. That equity curve is worthless. It's curve-fitted to historical data and will blow up going forward.
I build and sell EAs for a living. This article is my honest guide to backtesting a gold EA the right way — how to avoid fooling yourself with numbers, what settings to use in the MT5 Strategy Tester, and the red flags that distinguish a robust EA from a curve-fitted one.
What Is Curve Fitting (Overfitting)?
Curve fitting happens when an EA's parameters are optimized so precisely to historical data that they capture noise patterns instead of genuine market behavior. The optimize parameters don't reflect real market dynamics — they reflect the specific sequence of candles that happened to occur during your test period.
Example: An EA optimized on 2024 Q3 might "learn" that the best RSI period for gold is exactly 17, the best ATR multiplier is exactly 2.37, and the best session filter is 08:15-09:42 GMT. These hyper-specific values work brilliantly on 2024 Q3 data because they've memorized the price action. Run the same EA on 2024 Q4, and it falls apart because the market conditions are different.
The tell-tale sign: if changing a parameter by 5-10% destroys the backtest results, the EA is overfit. A robust strategy shows gradual performance degradation when parameters shift — not catastrophic failure.
Step 1: Use Every Tick Based on Real Ticks
In the MT5 Strategy Tester, you have five modeling modes. For gold EA backtesting, only two are acceptable:
- "Every tick based on real ticks" — downloads actual tick data from your broker. This is the gold standard (pun intended). Every price movement that actually happened is replayed.
- "Every tick" — MT5 generates synthetic ticks between OHLC data. Acceptable if real tick data isn't available for your broker, but less accurate.
Never use "1 minute OHLC," "Open prices only," or "Math calculations" for gold scalping EAs. These modes skip enormous amounts of price action. A scalping EA that enters and exits within the same M5 candle will produce completely different results on open-price mode vs tick-by-tick.
Step 2: Spread Simulation Matters More Than You Think
Gold spreads vary wildly:
- ECN during London session: 5-15 pips (0.5-1.5 points)
- During Asian session: 15-30 pips
- During major news: 50-200+ pips
- Fixed spread accounts: 20-50 pips constant
If your backtest uses a fixed 10-pip spread, the results will be significantly better than reality. Many scalping EAs are only profitable at a 10-pip spread and lose money at 25-pip average spread.
My approach: test with "Current spread" mode (uses variable spread from tick data), then retest with a fixed spread of 30 pips as a stress test. If the EA is only profitable below 15-pip spread, it won't survive real market conditions — at least not on most retail brokers.
When I built Gold Quantum Scalper AI, I included a max spread filter (default 250 pips = 25 points). The EA simply doesn't trade when the spread exceeds this threshold. This is essential for any gold EA — during news events, wide spreads can turn a winning trade into an instant loss.
Step 3: Test on Enough Data (But Not Too Much)
The Goldilocks problem of backtesting:
- Too short (3-6 months): Not enough market conditions sampled. The EA might have only seen one type of environment (trending or ranging, high or low volatility). Results are not statistically meaningful.
- Too long (10+ years): Gold's market microstructure has changed significantly. Spreads were different, volatility was different, and the broker's execution quality was different. Testing a 2026 strategy on 2015 data includes conditions that no longer exist.
- Just right (2-4 years): Includes multiple market cycles — trending periods, ranging periods, high and low volatility. Recent enough that market conditions are relevant.
I typically test on 2022-2025 (3 years), which includes the post-COVID volatility normalization, the 2023-2024 gold rally, and the 2025 consolidation. This gives a diverse set of conditions.
Step 4: Walk-Forward Analysis — The Real Test
Walk-forward analysis (WFA) is the single most important technique for validating an EA. Here's how it works:
- Split your data into segments: e.g., Jan 2022-Jun 2023 (in-sample) and Jul 2023-Dec 2023 (out-of-sample)
- Optimize the EA on the in-sample period
- Without changing any parameters, test on the out-of-sample period
- Record the out-of-sample results
- Slide the window forward and repeat: optimize Jul 2022-Dec 2023, test Jan 2024-Jun 2024
If the EA is robust, out-of-sample performance should be reasonably close to in-sample performance. Not identical — some degradation is normal. But if the EA makes 300% in-sample and loses money out-of-sample, it's curve-fitted.
MT5's built-in Walk-Forward Optimization (under the Optimization tab, select "Walk Forward") automates this process. Set your total date range, the walk-forward period length, and the optimization criterion. Let it run overnight — it takes much longer than regular optimization because it's running multiple passes.
Step 5: Parameter Sensitivity Analysis
After finding your optimal parameters, test stability by deliberately changing each parameter by ±10-20%:
- Optimal ATR period is 14? Test with 12 and 16.
- Optimal SL multiplier is 1.5? Test with 1.3 and 1.7.
- Optimal session filter starts at 07:00? Test with 06:30 and 07:30.
A robust EA should show gradual performance changes — maybe 5-15% profit difference. If changing the ATR period from 14 to 12 halves the profit, that parameter is overfit to the test data.
This is one reason I built auto-adaptive features into Gold Quantum Scalper AI. Instead of using a fixed ATR period, the EA measures recent volatility and adjusts parameters dynamically. This makes it inherently less dependent on any single parameter value — and therefore less prone to overfitting.
Red Flags That Scream Overfitting
When evaluating any gold EA — yours or someone else's — watch for these red flags:
- Perfect equity curve with no drawdowns. Real trading has drawdowns. An EA that shows 0% drawdown over 2+ years of gold trading has either been curve-fitted or cherry-picks test dates.
- Extremely high win rate (90%+) on a scalping EA. Achievable only by having very wide stops and very tight TPs — which means the average losing trade wipes out 10+ winners. The first losing streak destroys the account.
- Very specific parameter values. An SL of exactly "23.7 pips" and TP of "41.2 pips" came from the optimizer, not from market logic. Round numbers or ATR multiples are usually more robust.
- Only tested on one specific date range. Show me the results on a different 2-year period. If they refuse or the results don't hold, it's overfit.
- Uses martingale or grid without proper risk limits. These strategies can produce beautiful backtests until the one losing sequence that blows the account. The backtest conveniently ends before that sequence occurs.
- No spread sensitivity. Test the EA with 2× the spread. If it goes from profitable to losing, it's spread-dependent — meaning it will fail during volatile sessions, news events, and wider-spread brokers.
How I Test My Own EAs
Transparency: here's the process I use before releasing any EA to the MQL5 Market:
- Develop the strategy based on a market thesis (e.g., ATR-ZigZag trend detection with adaptive TP)
- Code the initial version with reasonable default parameters — no optimization yet
- Backtest on 3 years of real tick data with current spreads. Check if the strategy is profitable with defaults.
- Optimize each parameter individually (not all at once) on the first 2 years
- Walk-forward test on the final year — no parameter changes
- Stress test with 2× spread, with an additional simulated slippage, with an account 50% smaller than intended
- Live demo on a real broker demo account for at least 2-4 weeks before publishing
- Monitor live performance continually after release
Steps 4-6 often send me back to step 1-2. Most strategy ideas fail at the walk-forward stage. That's normal — it means the process is working, filtering out overfitted strategies.
The Strategy Tester Settings I Recommend
For backtesting any gold EA in MT5:
- Symbol: XAUUSD (check your broker's symbol name)
- Period: M5 for scalping EAs, H1 for intraday, D1 for swing
- Modeling: "Every tick based on real ticks"
- Spread: "Current" (or test with fixed 30 pips as stress test)
- Date range: At least 2 years, ideally 3
- Initial deposit: Same as your intended live deposit
- Leverage: Same as your live account (1:100 or 1:500)
- Optimization: "Slow complete" for thorough search, "Genetic algorithm" for initial exploration
- Criterion: "Custom max" set to profit factor, or "Balance max" — never optimize purely for total profit
After the backtest, check these key metrics:
- Profit factor — should be above 1.3 (above 1.5 is good, above 2.0 is excellent)
- Max drawdown — should be below 25% of account at normal lot size
- Recovery factor — net profit ÷ max drawdown, should be above 3
- Total trades — need at least 200+ trades for statistical significance
- Sharpe ratio — above 1.0 is acceptable, above 2.0 is very good
Backtesting isn't about finding the "best" settings. It's about finding settings that are robust enough to survive the future — which will be different from the past. If you approach it with that mindset, you'll build (or choose) EAs that actually work in live trading.
Checklist: Before You Trust Any Gold EA Backtest
Print this checklist and use it before deploying any EA — yours or purchased:
- Modeling mode: Was it tested on "Every tick based on real ticks"? If not, the results are unreliable for scalping EAs.
- Spread: What spread was used? Test with 30+ pip fixed spread as stress test. If profit disappears, the EA is spread-dependent.
- Date range: At least 2 years? Does it include both trending and ranging market periods?
- Total trades: At least 200+? Fewer trades means insufficient statistical sample.
- Walk-forward: Were out-of-sample results provided? If only in-sample optimization, assume overfitting.
- Parameter sensitivity: Change each key parameter ±15%. Does profit degrade gradually (robust) or collapse (overfit)?
- Drawdown: Maximum drawdown below 25% at intended lot size? Above 30% is dangerous for real accounts.
- Profit factor: Above 1.3? Below 1.2 leaves no margin for real-world slippage and spread variation.
- Win rate vs R:R balance: High win rate (80%+) with tiny R:R (TP ≪ SL) = one bad trade wipes weeks of gains. Verify the balance is sustainable.
- Martingale/grid check: Does the EA increase lot size after losses? If yes, understand that the backtest survived — but the next losing sequence might not.
If the EA fails 3 or more items on this checklist, don't deploy it on a live account. Go back to demo testing or look for a more robust alternative.
Forward Testing: The Bridge Between Backtest and Live
Even after a clean backtest and successful walk-forward analysis, I always forward-test on a live demo account before committing real capital. Here's my forward testing protocol:
- Duration: Minimum 2 weeks, ideally 4 weeks. This needs to cover different market conditions — at least one trending week and one ranging week.
- Broker: The same broker (or same type) you'll use for live. Different brokers have different spread profiles, execution speeds, and swap rates — all of which affect EA performance.
- Compare metrics: Track win rate, average trade duration, drawdown, and profit factor during forward testing. Compare against the backtest. If forward metrics are within 20% of backtest metrics, the EA is likely robust. If forward results are drastically worse, the backtest was either overfit or conditions have changed.
- Monitor spread behavior: During forward testing, log the actual spreads your broker provides during different sessions. If your backtest assumed 10-pip spreads but your broker routinely provides 25-pip spreads during Asian session, adjust expectations.
Forward testing is boring. It generates no excitement and no profit (it's demo money). But it's the single most important risk management step between coding an EA and trusting it with real capital. Every month I spend forward-testing saves me from potential blow-ups that would cost far more.
Frequently Asked Questions
What is the best backtesting mode in MT5 for gold EAs?
"Every tick based on real ticks" is the gold standard (pun intended). It downloads actual historical tick data from your broker and replays every price movement that occurred. This is essential for scalping EAs where entries and exits happen within the same candle. "Every tick" (synthetic) is acceptable as a second choice. Never use "Open prices only" or "1 minute OHLC" for scalping strategies — they skip enormous amounts of intrabar price action.
How long should a gold EA backtest be?
2-4 years is optimal. Shorter than 2 years doesn't sample enough market conditions — you might only see trending markets and miss how the EA performs during consolidation. Longer than 5 years includes market microstructure that no longer exists (spreads, volatility regimes, and broker execution quality have all changed). I typically use 2022-2025 data for my 2026 EA testing.
What profit factor is good for a gold EA?
Above 1.3 is acceptable, above 1.5 is good, above 2.0 is excellent. Be cautious of profit factors above 3.0 on 1000+ trades — this often indicates overfitting or very specific market conditions that may not repeat. Also check if the profit factor remains stable across different sub-periods (first year vs second year). A PF of 2.5 overall but 0.8 in the last 6 months means the strategy may be degrading.
How do I know if my EA is overfitted?
Five key signs: (1) Changing any parameter by 10% destroys the results. (2) In-sample results are dramatically better than out-of-sample. (3) The equity curve has no drawdowns over 2+ years. (4) Parameter values are suspiciously precise (SL of 23.7 pips instead of round numbers). (5) The EA only works on one specific date range. A robust EA should show gradual performance degradation when parameters shift — not catastrophic failure.
Should I optimize for maximum profit or profit factor?
Neither in isolation. Optimize for a combination: profit factor (risk-adjusted returns) with a minimum trade count filter. Optimizing purely for profit often finds a few lucky large trades. Optimizing purely for profit factor can find a highly selective system that only takes 10 trades in 3 years. I use MT5's "Custom max" criterion set to maximize profit factor with a minimum of 200 trades, then verify the top 5 parameter sets all produce similar results (stability check).
Can I backtest Expert Advisors on Strategy Tester with variable spreads?
Yes — select "Current spread" in the Strategy Tester settings. When using "Every tick based on real ticks" mode, MT5 uses the actual historical spreads from the tick data. This gives you realistic spread variation throughout the day — tighter during London, wider during Asian session, spikes during news. This is far more accurate than fixed-spread testing and should be your default choice for any gold EA backtest.
Disclaimer: Backtest results do not guarantee live trading performance. All trading involves significant risk of capital loss. This article is educational content and not financial advice. Past performance, whether backtested or live, does not predict future results.