A 100-ounce lot on XAUUSD means a one-dollar move is worth 100 dollars per standard lot. A normal daily range can therefore be several hundred dollars per lot, and an Expert Advisor that ignores this will either be stopped out constantly or carry far more risk than its author intended.
This article looks at the families of automated strategy commonly tried on gold, what features of the instrument help or hurt each, and how to test them. It is technical analysis, not a recommendation. No strategy or robot works in all conditions, and no EA is the best for gold.
What an EA has to cope with on gold
Gold behaves differently from a major currency pair in ways that matter to code. Its range in dollar terms is large, so lot size must be small and calculated, not fixed. Spread widens at rollover and around major news. Price can gap over the weekend, and contract specifications (one lot, tick size, digits) differ by broker, so a hard-coded pip value is a common source of bugs.
The drivers are macro: US real yields and Federal Reserve expectations, dollar strength, central-bank buying, ETF flows and safe-haven demand. These can hold the market in a sustained direction for weeks, then leave it in a range for months. The full list is covered in the article on market drivers. For automation the point is simple: the instrument alternates between regimes, and any rule set is effectively a bet on one of them.
Trend following and breakout
Trend and breakout systems have worked in sustained macro regimes, typically when real yields or dollar moves push gold in one direction for a long stretch. Gold also tends to travel in large bursts, which suits rules that stay in a position and use a trailing stop. Moving-average crossovers, channel breakouts and higher-timeframe momentum filters are the usual building blocks.
The weaknesses are equally clear. In a range, breakouts fail repeatedly, and each failure costs the spread plus a stop. Gold often spikes through a level on news, then returns, so a breakout entry placed on a tick can fill at the worst price. Many such systems have a low win rate and rely on a few large winners, which demands patience through long losing runs. Breakout entries on a closed bar, with a volatility filter, reduce false triggers but also give back part of the move.
Mean reversion, scalping and session-based ideas
Mean reversion (fading stretched moves from a band, an oscillator extreme or a distance from a moving average) can look excellent in a range and fail badly when a trend begins. Gold's large moves mean the average winner is small relative to the occasional runaway loser, so a hard stop and a regime filter matter more than the entry signal.
Automated scalping targets small moves on one-minute to five-minute charts. On gold the spread is a large share of the target, and it widens exactly when volatility rises. Results also depend heavily on execution speed and slippage, so a scalper that tests well can disappoint on another broker. Session-based logic, such as trading the London open or the COMEX futures open at 13:20 UTC (12:20 in summer), exploits the fact that activity clusters there, but liquidity at those moments is also thin and fast. Details are in the article on trading times.
Volatility-based, indicator-based and grid approaches
Volatility-based stops using ATR are almost essential on gold, because a fixed 20-dollar stop is tight in one month and wide in the next. Scaling both stop distance and position size by ATR keeps the risk per trade comparable across regimes. The ATR and volatility calculator shows current ranges and the stop distances they imply.
Indicator-based systems (RSI, MACD, Bollinger Bands and combinations) are mostly trend or mean-reversion logic in different clothes, and their parameters are easy to over-fit. Stacking five filters usually means fewer trades and a better-looking backtest, not a better strategy.
Grid and martingale designs deserve plain language. They win small amounts often, which produces smooth equity curves, until gold moves a long way in one direction. A sharp one-way move, or a weekend gap, can open a loss that exceeds the account. A stop-loss on the whole basket, a cap on the number of levels and a fixed maximum lot are the minimum safeguards, and even those do not remove the tail risk.
Timeframes, spread and execution
Lower timeframes (M1 to M15) are dominated by costs and noise. Higher ones (H1 to D1) trade less often, tolerate the spread better and are less sensitive to execution quality, but need wider stops and therefore smaller lots. Neither is better in general: the right choice depends on capital, risk tolerance and how much slippage your broker produces.
Spread is not a constant. It is tight in the busiest hours, wider at rollover and around scheduled releases. Build a spread filter into the EA, and test with variable or deliberately pessimistic spreads. Check live figures with a live spread monitor and see the article on volatility and costs for context. Slippage is asymmetric on stops during fast moves, so assume that real fills are worse than the test.
Risk management and position sizing in code
Size from risk, not from habit. The calculation is: risk amount divided by (stop distance in price multiplied by contract size, 100 ounces by default), then rounded down to the lot step, usually 0.01. Read the contract size, tick value and minimum lot from the symbol properties at runtime, because brokers differ. If the rounded lot is below the minimum, the EA should skip the trade, not force the minimum.
Add limits that do not depend on the signal: a maximum number of open positions, a daily loss cap, a spread and margin check before every order, and a pause around scheduled news if the strategy is not designed for it. Use the risk of ruin calculator to see how risk per trade changes the probability of a deep drawdown, and remember that the inputs (win rate, reward-to-risk) are estimates, not facts.
Backtesting without fooling yourself
Data quality comes first. Use real tick data where possible, since modelling modes based on bars or generated ticks can hide the intrabar behaviour that decides whether a tight stop is hit. Include realistic spread, commission and swap, and check that the data covers gaps and rollover sensibly.
Then separate the sample. Optimise on one period, test on a period the optimiser never saw, and use walk-forward testing, which repeats this over rolling windows. Over-fitting shows up as a sharp peak in the parameter map: if a setting of 14 works and 13 and 15 do not, the result is noise. Prefer broad plateaus, few parameters and a rationale you could state before testing.
Test across regimes: a strong trend, a long range, a sharp spike, a low-volatility stretch. Stress the result with a Monte Carlo simulation of trade order, and review trade-level statistics with the MT5 report analyser. A backtest describes the past; it is not a promise, and it is normal for live results to be weaker.
Which approaches are fragile
Fragility usually has the same causes: tiny profit targets that costs can erase, parameters tuned to one year, no stop-loss, averaging down, and reliance on a single regime. A strategy that needs a tight spread, a fast fill and a calm market has three ways to fail.
Robust-looking behaviour is mostly boring: a modest number of parameters, volatility-scaled risk, a hard stop on every position and a defined condition under which the EA stands aside. Even then, a regime change can end an edge, so monitor live results against the test range and decide in advance what drawdown means the system is switched off. For more on discretionary context, see how to trade XAU/USD.
Treat any gold EA as a hypothesis with a cost and a risk budget: write down the regime it expects, test it where that regime is absent, and size it so that being wrong is survivable. Our Expert Advisors area and MQL5 coding service exist for those who want ready-made or custom tools, but neither changes the risks described here.
Frequently asked questions
Is there a best Expert Advisor for gold?
No. Results depend on the broker, execution quality, timeframe, capital, risk profile and the market regime, and these change. A system that suits a trending period may lose in a range. Judge any EA by its logic, costs, drawdown and behaviour across different conditions, not by one equity curve.
What lot size should an EA use on XAUUSD?
There is no universal figure. Calculate it from the amount you accept to lose, the stop distance and the contract size (usually 100 ounces), then round down to the broker's lot step. Because gold's range is large in dollar terms, the result is often a small lot such as 0.01 to 0.10 on modest accounts.
Why does my gold EA perform worse live than in the backtest?
Common causes are optimistic spreads, unmodelled slippage, low-quality tick data, over-fitted parameters and a regime that differs from the test period. Compare live trades with the test on spread, fill price and timing to find which factor accounts for the gap.
Are grid and martingale EAs suitable for gold?
They are among the riskiest designs on gold. They collect small gains until a sharp one-way move or a weekend gap produces a loss far larger than all previous gains. If tested at all, use a basket stop, a cap on levels and a maximum lot, and accept that tail risk remains.
This article is educational. It does not recommend any trade or product, and nothing here is a promise of results. Information only, not advice. Trading leveraged products carries a high level of risk and you can lose more than you deposit. Past behaviour does not predict future results. Read the risk disclosure.