Gold XAUUSD RSI EA — No Code

RSI mean-reversion on gold: XAUUSD H1 recipe, spread and session filters, ATR stop loss, export MQL5 from Strategy Builder.

📖 10 min read

📝 1,849 words

🏷️ MQL5 and Expert Advisors

Share this article:

Gold XAUUSD RSI EA — No Code

Can I build a gold (XAUUSD) RSI EA for MT5 without coding?

Yes. Open AlfaTactix Strategy Builder → Step 3 — Signals on H1 for XAUUSD → add RSI with Length 14, Overbought 70, Oversold 30 → Buy: condition Cross, Target Oversold, Direction Up, Value 30 → Sell: Cross, Target Overbought, Direction Down, Value 70 → Step 4: spread filter + market session (London/NY overlap) → Step 5: ATR-based or fixed stop loss per EA Risk Management → Save → export MQL5 from Code Generator → compile once in MetaEditor → backtest with realistic XAUUSD spread in the Strategy Tester.

Disclosure: This tutorial uses AlfaTactix Strategy Builder for a gold-only RSI mean-reversion recipe. For the full six-step platform tour, see Build EA Without Coding. For every RSI condition type (Compare, Cross, Divergence, Failure Swing, Breakout, Pattern, Slope), see RSI Overbought/Oversold EA — No Code. For MA/ATR gold case study (not RSI), see EA for Gold (XAUUSD).

Related guides: RSI Academy · Backtest in Strategy Tester · EA Prop Firm Rules · EA Strategy Library


Why RSI on Gold (XAUUSD)?

Gold (XAUUSD) is one of the most traded symbols on MT5 — high volatility, sharp intraday swings, and mean-reverting behavior during range sessions. The Relative Strength Index (RSI) maps those swings to a 0–100 oscillator: extremes near 70 (overbought) and 30 (oversold) often precede bounce moves when momentum exhausts.

Why RSI on goldDetail
Clear zonesOB/OS levels give rule-based entries without discretionary chart reading
Mean-reversion fitGold frequently oscillates in ranges during London/NY liquidity
AutomationAn EA runs OnTick() [1] logic via exported iRSI() [2] — no hand-written MQL5
Complements other gold EAsThis guide is RSI-only; trend/ATR gold systems live in EA for Gold (XAUUSD)

Gold-specific cautions: Wider spread, faster moves, and session-dependent liquidity. A forex-tuned RSI EA copied to XAUUSD without Step 4 filters often over-trades or gets stopped out by spread. This guide adds spread + session filters and ATR-aware risk on top of the classic 30/70 Cross recipe.

Not the same as trend-following gold: If you want moving-average entries on gold, use Moving Average Crossover EA — No Code or the Gold XAUUSD MQL5 case study — then optionally layer RSI as a filter later.


Classic Gold RSI Settings

SettingStarter (H1 XAUUSD)Notes for gold
Length14Try 9–11 after backtest if signals lag
Overbought70Range 50–100 in builder; 75 = stricter sells
Oversold30Range 0–50; 25 = stricter buys
SourceCloseHigh/Low = more reactive on volatile candles
SmoothingNoneOptional SMA/EMA if RSI line is too noisy
TimeframeH1M15 = more signals + spread cost; H4 = fewer, cleaner
SymbolXAUUSD (or broker gold symbol)Match Market Watch name exactly in tester

Works best: Range or mild trend days during London open through NY overlap — RSI crosses back from extremes after impulse moves.

Struggles in: Strong one-way gold trends (RSI can stay overbought/oversold for hours). Mitigate with Step 4 session filter, Step 5 stop loss, or combine with a trend filter from MA Crossover EA.

For oscillator math, divergence, and chart reading, see the RSI Academy guide.


RSI Parameters and Gold-Specific Filters

RSI parameters (from Strategy Builder UI)

When you add RSI on Step 3 — Signals, the Parameters panel matches rsiConfig:

ParameterRange / optionsDefaultGold tip
Length2 – 10014Shorter = faster signals on volatile gold
SourceClose, Open, High, LowCloseClose is standard for H1 mean-reversion
SmoothingNone, SMA, EMA, WMA, SMMA, VWMANoneAdd smoothing only if backtest improves stability
Smoothing Length1 – 10014Used when Smoothing ≠ None
Overbought50 – 10070Align with Sell Cross Value
Oversold0 – 5030Align with Buy Cross Value
Offset-50 – 500Leave 0 unless you know you need bar shift

Core signal recipe (Step 3):

TabConditionTargetDirectionValue
BuyCrossOversoldUp30
SellCrossOverboughtDown70

RSI condition types (brief): The builder exposes Compare, Cross, Divergence, Failure Swing, Breakout, Pattern, and Slope. For mean-reversion gold, start with Cross only. Compare fires while RSI stays in a zone (more entries). Divergence and Failure Swing suit advanced reversal filters. Full field-by-field documentation: RSI Overbought/Oversold EA — No Code.

Gold-specific Step 4 filters

FilterPurpose on XAUUSD
SpreadBlock entries when spread exceeds your cap (gold spread spikes at rollovers and thin sessions)
Market sessionTrade London and/or NY, or London/NY overlap when liquidity and mean-reversion are strongest
Optional ATR filterSkip ultra-low volatility bars (no room for bounce) or extreme ATR (news spikes)

Configure these on Step 4 — Filters in Strategy Builder. For a hand-coded multi-timeframe version later (the builder uses one timeframe per strategy today), see Advanced EA MTF & Filters — this article stays focused on H1 XAUUSD RSI.


Build the Gold RSI EA Step by Step

Workflow: six steps in Strategy Builder demo. Below is the XAUUSD H1 mean-reversion recipe.

Step 1 — Strategy information

  • Name: e.g. Gold RSI Mean Reversion H1 XAUUSD
  • Description: optional note — RSI 14 / 30 / 70, London/NY session

Step 2 — Timeframes

  • Enable H1 as the trading timeframe (matches tf0 on Step 3).
  • Optional later: higher timeframe trend filter — not required for this starter EA.

Step 3 — Signals (core)

  1. Open tab Buy.
  2. Select timeframe H1.
  3. Add indicator → RSI (Momentum group).
  4. Parameters:
    • Length: 14
    • Source: Close
    • Smoothing: None
    • Smoothing Length: 14 (ignored when Smoothing = None)
    • Overbought: 70
    • Oversold: 30
    • Offset: 0
  5. Add condition → Cross:
    • Target: Oversold
    • Direction: Up
    • Value: 30
  6. Open tab Sell.
  7. Add RSI (mirror parameters).
  8. Add condition → Cross:
    • Target: Overbought
    • Direction: Down
    • Value: 70

Stricter alternative: On Buy, Compare RSI <= 30 AND Cross Oversold Up 30 — fewer false starts; see condition details in the RSI EA guide.

  1. Spread filter: set maximum spread your broker typically offers during target hours (tune after demo observation).
  2. Market session: enable London and New York, or restrict to overlap window for tighter liquidity.
  3. Optional: ATR minimum/maximum if your builder build supports it for news avoidance.

Step 5 — Risk management

Gold requires realistic stops — not EURUSD pip counts.

SettingSuggestion for XAUUSD
Lot / risk %0.01 lot demo or 0.5–1% risk per trade
Stop LossATR-based (e.g. 1.5–2× ATR) or fixed points sized for your broker
Take ProfitOptional; many RSI EAs exit on opposite Cross signal
One trade at a timeReduces overlap risk in fast gold moves

Full reference: EA Risk Management. Compare with ATR/MA approach in EA for Gold (XAUUSD).

Step 6 — Preview and Save

Review Buy/Sell rules and Step 4/5 settings → Save strategy to your account.


Export, Compile, and Backtest

  1. Open Code Generator → select your saved gold RSI strategy → MQL5 → download .mq5.
  2. Copy to MQL5/Experts, compile (F7) in MetaEditor.
  3. Open Strategy Tester:
    • Symbol: XAUUSD (exact broker name)
    • Period: H1
    • Model: Every tick (or 1 minute OHLC for first pass)
    • Spread: use current or fixed realistic gold spread — tight test spreads flatter results
    • Date range: 6–12 months minimum
  4. Forward test on Demo before live.

If OrderSend fails with 10016, see Invalid Stops. Exported code uses standard iRSI() [2].

Reference: MetaTrader 5 Strategy Tester [3].


Improvements and Prop Firm Notes

ProblemBuilder lever
Spread eats edgeStep 4 spread filter; realistic spread in tester
Entries outside liquid hoursStep 4 London/NY session
Counter-trend losses in gold trendsTighter OB/OS (75/25); optional MA trend filter (MA Crossover EA)
Stops too tight for goldStep 5 ATR stop; fix 10016 via Invalid Stops guide
Prop firm rule breachCap daily loss in Step 5; read EA Prop Firm Rules on MT5

Prop firm checklist: Confirm XAUUSD is allowed, max lot and drawdown fit your Step 5 settings, and backtest spread matches live account type. Many firms restrict news trading — consider disabling the EA around high-impact USD releases if your rules require it.

Advanced RSI upgrades: Add Failure Swing or Divergence with AND on Step 3 (documented in RSI Overbought/Oversold EA). Do not stack every condition on day one — validate the base Cross 30/70 recipe first.



Tactix AI on this workflow

AlfaTactix includes Tactix AI: use Tactix Studio to describe your idea in plain language and draft timeframes, signals, filters, and risk into the same six-step Strategy Builder form — or open Tactix Guide on any step when you only need a field explained. Review every value, then export MQL5 or Pine Script from Code Generator (form-first — not untested prompt-to-code).

Next Steps

Gold friction: XAUUSD spread jumps matter more than on EURUSD. Write today's spread at London open, then set tester spread to that number before trusting RSI levels. Build RSI + hasSpread in the live demo — if the EA stops trading exactly when your broker widens, the filter is doing its job.

Frequently Asked Questions

Yes. In AlfaTactix Strategy Builder, add RSI on Step 3 — Signals for XAUUSD on H1, set Cross with Target Oversold, Direction Up, Value 30 (buy) and Target Overbought, Direction Down, Value 70 (sell), add spread and London/NY session filters on Step 4, configure ATR-based or fixed stop loss on Step 5 per EA Risk Management, save, then export MQL5 from Code Generator and backtest in the Strategy Tester.

A solid starter on H1 gold: Length 14, Overbought 70, Oversold 30, Source Close, Smoothing None. Gold moves faster than majors — some traders use Length 9–11 or tighter levels (75/25) after backtesting. Match Parameter levels to your Cross Value fields. Full RSI parameter and condition reference: RSI Overbought/Oversold EA — No Code. Indicator theory: RSI Academy guide.

XAUUSD spread widens outside liquid hours and can erase mean-reversion edge on tight stops. Step 4 spread cap skips entries when spread is too high; market session (e.g. London/NY overlap) focuses on hours when gold trends and mean-reverts more predictably. For MA/ATR gold context (this guide is RSI-only), see EA for Gold (XAUUSD).

Use Cross for classic bounces: Target Oversold, Direction Up, Value 30 (buy) and Target Overbought, Direction Down, Value 70 (sell). Compare (e.g. RSI <= 30) can fire every bar while oversold — common over-trading issue on volatile gold. See all seven RSI condition types in the RSI Overbought/Oversold EA guide.

Gold needs wider stops than EURUSD. On Step 5 — Risk management, use ATR-based stop loss (adapts to volatility) or a fixed stop sized for your broker’s point value — details in EA Risk Management. If orders fail with error 10016, stops may be too tight vs broker minimum distance: Invalid Stops.

Only if rules allow XAUUSD, your daily drawdown and max loss fit Step 5 risk settings, and backtests used realistic spread. Review EA Prop Firm Rules on MT5 before going live. Forward-test on Demo after Strategy Tester validation.

References

  1. MetaQuotes, MQL5 Reference. OnTick. https://www.mql5.com/en/docs/event_handlers/ontick
  2. MetaQuotes, MQL5 Reference. iRSI. https://www.mql5.com/en/docs/indicators/irsi
  3. MetaQuotes. MetaTrader 5 Built-in Trading Strategy Tester. https://www.metatrader5.com/en/automated-trading/strategy-tester

AlfaTactix is a no-code strategy builder for MetaTrader 5 (MQL5) and TradingView (Pine Script) traders who design and manage rule-based strategies.

Trading involves substantial risk of loss. AlfaTactix generates code from the rules you define and does not provide financial advice. Past or backtested performance does not guarantee future results.

© 2026 AlfaTactix. All rights reserved.