Best practices for parameter optimization of gold trading EAs

 

Hello everyone,

I wanted to share some lessons learned about parameter optimization, hoping to get your feedback and maybe some ideas to improve.

1. Walk-forward optimization beats simple single-period optimization. A strategy that looks great on one year of history often breaks on the next six months.

2. Use a realistic spread model and slippage. Backtesting gold with a 20-cent spread is very different from the real 35-50 cents you see during London/NY sessions.

3. Avoid overfitting by limiting the number of free parameters. I try to keep each EA to no more than 5-6 meaningful inputs, and I check that the equity curve stays smooth across different starting points of the test period.

4. Out-of-sample validation is essential. I reserve the last 20% of history and never look at it during optimization.

5. Be careful with tick data gaps around rollovers and low-liquidity weekends on XAUUSD.

What do you use in your own workflow? Do you prefer genetic optimization or full grid search? Any tips on avoiding curve-fitting when working with gold specifically?

Best regards

 
Phan Van Khoa:


Thanks for reading. One more thing I should mention: I always validate with different broker settings (spread, commission, and swap) because the same EA can behave completely differently across brokers. It would be great to hear how others handle broker-dependent parameters in their gold EAs.

 
One practical check is to validate each parameter set under different broker settings, especially spread, commission, and swap. For XAUUSD I also find it useful to limit the number of free inputs, keep an out-of-sample segment untouched, and compare walk-forward results against a simple baseline. If performance changes a lot when spread or session filters move, the strategy is probably overfit.
 
Use Python to optimize transactions if the strategy allows it, such as studying volume and yield variance (PMMV/PMVR) to determine the best liquidity times. We focus on making the expert trade during high liquidity times with mathematical proof, not the logic that says the highest liquidity occurs during the overlap between the London and New York sessions... If it were up to me, I would guide you through this path (analyzing data quantitatively and mathematically using Python, then applying the results and conclusions to your expert).
 

I use genetic optimization only to locate promising regions, then a smaller full grid around those regions. The best single pass is usually not interesting. I prefer a wide plateau where nearby settings stay profitable with similar drawdown.

After that I repeat OOS tests across several time windows and worsen spread, commission and delay. For gold I would also test another broker’s data, because one broker-specific result can look much more robust than it really is.

 
For gold, I’d optimize across several chronological windows and keep the final period untouched for validation. Choose a stable parameter area, not the single best result. Then repeat with higher spread, commission and execution delay. If the forward trade count collapses, the entry filters or parameter ranges are probably too tightly fitted.
 
The spread and commission sweep is worth doing, but the divergence that actually cost me wasn't in the parameters.

I had an entry slip 28 pips on a news candle, and the stop went in 128 pips away instead of 100, because it was placed off where the software thought I had filled rather than where I actually did. No spread setting in the tester produces that.

On the plateau point, I'd add one check. I had a strategy look stable across parameters over seven months at 2.4% max drawdown. Same settings over three years and it was 7.2%. The plateau was real, it was just a plateau over one set of conditions.

So now when I find a stable area, I expand the test window and see whether that stability survives before I trust it.

 
One thing sits underneath all of this and is easy to skip: how much of the history you are optimising on is real ticks.

Real tick history is a rolling window, and where it begins depends on what the server keeps for that symbol. It is not the same date for every symbol and not the same for every broker. I have had an MT5 pass where one symbol had no ticks for the month, and the run still finished and printed a report that looked complete. The log said what had happened, the report did not.

So a walk-forward split can sit half on real ticks and half on something else with nothing on screen saying so. Before the spread and commission sweep is worth running, it helps to know month by month what the data underneath it actually is.

I put a small script in the Code Base that prints exactly that, per symbol and per month, free: https://www.mql5.com/en/code/76152

Then the sweep means what you think it means.
 
For XAUUSD I would not select the single best optimization pass.

I prefer to look for a parameter region where several neighbouring combinations produce similar results. If changing an EMA period from 48 to 50 or an ATR multiplier from 1.8 to 1.9 completely destroys the system, that is usually a warning sign.

After finding a stable region I would freeze the parameters and test them on untouched periods, then repeat with worse spread/execution assumptions.

Gold is especially sensitive to session changes, spread expansion and volatility regimes, so a parameter set that works perfectly in one period can easily be fitting that particular environment.

Genetic optimization is useful for finding the region quickly. A smaller full search around that region is usually more informative than chasing the best genetic result.