How to backtest a gold (XAU/USD) trading strategy
Test your gold trading idea on years of past prices before risking money, step by step and without code.
What a backtest tells you
A backtest replays your trading rules on past prices and records every trade they would have taken. It shows how the idea behaved: how much it made or lost, how deep the losing streaks went and how often it traded.
It cannot promise future results. Markets change, and live trading adds the broker's spread (which XauLab backtests do not include) and real fills that a historical test only approximates. Use a backtest to throw out weak ideas and to understand the risk of the good ones.
Step by step in XauLab
- Open the Strategy Builder and choose the market (XAUUSD for gold) and a timeframe such as 5m, 15m, 1H or 4H.
- Add indicators (for example EMA, RSI or ATR) and write the entry rules for buys and, if you want, for sells.
- Set how trades end: stop loss, take profit, an optional trailing stop and optional exit rules.
- Choose the position size (fixed lots), your starting capital and any commission your broker charges per lot.
- Pick the date range. Longer ranges cover more market conditions; two years or more is a good start for gold.
- Press Run Backtest. The credit cost is shown on the button before you start, and failed runs are refunded.
Use your broker's own prices
Every broker's gold price is slightly different. When your MT5 account is connected, XauLab backtests on that broker's candles, the same prices your live strategy will trade on. Without a connected account it uses XauLab's research data, and the report says which one was used.
Long tests download many months of candles the first time. XauLab saves finished months, so repeat tests over the same period load almost instantly.
Read the results carefully
- Net profit and return: the end result, but never look at these alone.
- Max drawdown: the deepest fall from a peak. This is the pain you must be able to sit through.
- Profit factor: gross profit divided by gross loss. Above 1.3 over hundreds of trades is a solid sign.
- Number of trades: a handful of trades proves little; aim for hundreds.
- Monthly returns and the equity curve: steady growth beats one lucky month.
Common mistakes
- Testing a few months only, or only one market trend.
- Tweaking rules until the past looks perfect (over-fitting). Test the final rules on a period you did not tune on.
- Buy and sell rules that fire on the same candles, so no trade opens. XauLab warns you when that happens often.
- Ignoring costs: add your broker's commission so results are realistic.
Ready to try it on XauLab?
Build and backtest a strategyEducational content, not financial advice. Trading gold with leverage carries a high risk of loss, and past results do not guarantee future returns. Read the risk disclosure.