XAU Mean Reversion EA v1.30
Complete setup guide, configuration reference, and troubleshooting.
1. System Requirements
- Platform: MetaTrader 4 (MT4) — build 1300 or later recommended
- Instrument: XAUUSD (Gold vs US Dollar)
- Timeframe: M15 (15-minute chart)
- Minimum Deposit: $500 recommended (micro lots at 0.01)
- Broker: ECN / low-spread broker with max spread under 50 points on XAUUSD
- VPS: Recommended for 24/5 uninterrupted operation — low-latency connection to your broker
- Operating System: Windows 7 or later (or Linux via Wine)
2. Installation
- Download the EA file — After purchase you will receive a
.ex4compiled expert advisor file. - Open your MT4 Data Folder — In MetaTrader 4 go to File → Open Data Folder.
- Copy the file — Navigate to
MQL4 → Expertsand paste the.ex4file there. - Restart MT4 — Close and reopen MetaTrader 4 completely so the EA appears in the Navigator panel.
- Attach to chart — Open a XAUUSD M15 chart, then drag the EA from the Navigator panel onto the chart.
- Enable live trading — In the EA properties dialog, check "Allow live trading". Also ensure the AutoTrading button on the MT4 toolbar is enabled (green icon).
- Configure parameters — Adjust the input parameters as needed (see section 3 below), then click OK.
Tip: Always test on a demo account first. Run the EA for at least 1–2 weeks on demo before going live to confirm it matches your expectations.
3. Recommended Settings & Parameters
Below is the complete list of input parameters with their default values. You can adjust these in the EA properties dialog (Inputs tab).
Lot Size & Risk Management
| Parameter | Default | Description |
|---|---|---|
| InpLotSize | 0.01 | Fixed lot size when dynamic lots are disabled |
| InpUseDynamicLots | false | Enable automatic lot sizing based on account balance and risk percent |
| InpRiskPercent | 1.0 | Percentage of account balance to risk per trade (used when dynamic lots are enabled) |
Stop Loss & Trailing Stop
| Parameter | Default | Description |
|---|---|---|
| InpInitialSL | 2.00 | Initial stop loss distance in dollars from entry price |
| InpTrailingDistance | 2.00 | Trailing stop distance in dollars — how far behind price the stop follows |
| InpTrailingStep | 0.50 | Minimum price movement in dollars before trailing stop updates |
| InpUseATRStopLoss | true | Use ATR-based dynamic stop loss instead of fixed initial SL |
| InpATRPeriod | 14 | Period for ATR indicator used in dynamic stop loss calculation |
| InpATRMultiplier | 1.5 | Multiplier applied to ATR value to determine stop loss distance |
Partial Close
| Parameter | Default | Description |
|---|---|---|
| InpUsePartialClose | true | Enable closing a portion of the position at a profit target |
| InpPartialClosePercent | 50 | Percentage of position to close when partial close target is hit |
| InpPartialClosePips | 2.0 | Profit distance in dollars at which partial close triggers |
Trading Session (Hong Kong Time)
| Parameter | Default | Description |
|---|---|---|
| InpHKTStartHour | 8 | Trading session start hour in Hong Kong Time (HKT, UTC+8) |
| InpHKTEndHour | 19 | Trading session end hour in Hong Kong Time (HKT, UTC+8) |
| InpServerOffset | 5 | Hours to add to server time to convert to HKT (see broker config section) |
Signal Indicators (EMA & RSI)
| Parameter | Default | Description |
|---|---|---|
| InpEMAFast | 9 | Fast EMA period — detects short-term price direction |
| InpEMASlow | 25 | Slow EMA period — establishes the mean reversion baseline |
| InpMinEMAGap | 1.50 | Minimum gap in dollars between fast and slow EMA to confirm divergence |
| InpConfirmBars | 5 | Number of consecutive bars the EMA crossover must persist before entry |
| InpRSIPeriod | 14 | RSI indicator period |
| InpRSIMidline | 50.0 | RSI midline — values above indicate bullish, below indicate bearish |
| InpSmoothedRSIPeriod | 7 | Smoothing period applied to RSI to reduce noise |
Trade Filters & Safety
| Parameter | Default | Description |
|---|---|---|
| InpCooldownBars | 40 | Minimum bars to wait after a trade closes before opening a new one |
| InpMaxConsecutiveLosses | 2 | Maximum consecutive losses allowed before the EA pauses trading |
| InpMaxSpread | 0.50 | Maximum allowed spread in dollars — trades are skipped if spread exceeds this |
| InpUseNewsFilter | true | Enable news filter to avoid trading around high-impact news events |
| InpNewsMinutesBefore | 30 | Minutes before a news event to stop opening new trades |
| InpNewsMinutesAfter | 30 | Minutes after a news event to resume trading |
4. Broker Configuration & Server Offset
The EA uses Hong Kong Time (HKT, UTC+8) internally to define the trading session. Because different brokers run their MT4 servers in different timezones, you need to set the InpServerOffset parameter so the EA can convert server time to HKT correctly.
How to Calculate Server Offset
The formula is: ServerOffset = 8 - BrokerUTCOffset
Where 8 is the UTC offset for Hong Kong Time, and BrokerUTCOffsetis your broker's server timezone offset from UTC.
| Broker | Server Timezone | Calculation | InpServerOffset |
|---|---|---|---|
| IC Markets | UTC+2 | 8 - 2 = 6 | 6 |
| Pepperstone | UTC+3 | 8 - 3 = 5 | 5 |
| Exness | UTC+0 | 8 - 0 = 8 | 8 |
Note on Daylight Saving Time (DST): Many brokers shift their server time by 1 hour during DST transitions (typically in March and November). When your broker switches between summer and winter time, you may need to adjust InpServerOffsetby +1 or -1 accordingly. Check your broker's announcements for DST schedule changes.
How to Verify Your Offset
- Open the Market Watch window in MT4 and note the server time shown at the bottom.
- Compare it to the current Hong Kong Time (search "HKT time now" online).
- The difference in hours is your
InpServerOffsetvalue. - For example, if server time shows 12:00 and HKT is 17:00, the offset is 5.
5. Troubleshooting
EA does not appear in Navigator panel
- Ensure the
.ex4file is placed in the correct folder:MQL4/Experts - Restart MT4 completely (close and reopen)
- Right-click in the Navigator panel and select "Refresh"
EA shows a sad face icon on the chart
- Click the AutoTrading button on the toolbar to enable it (icon should turn green)
- Open EA properties → Common tab → ensure "Allow live trading" is checked
- Go to Tools → Options → Expert Advisors → check "Allow automated trading"
EA is active but not opening trades
- Check the Experts tab (bottom of MT4) for log messages — the EA prints reasons for skipping trades
- Verify you are on a XAUUSD M15 chart
- Confirm the current time falls within the trading session (HKT 8:00–19:00 by default)
- Ensure spread is below
InpMaxSpread(default $0.50) - Check if the cooldown period is active — after a trade closes the EA waits
InpCooldownBarsbars (default 40) before the next entry - If you hit
InpMaxConsecutiveLosses(default 2), the EA pauses until the next trading session - The news filter may be blocking trades — check if a high-impact event is within the configured window
Trades open at wrong hours
- Your
InpServerOffsetis likely incorrect — see the Broker Configuration section above to recalculate - Check if your broker recently switched between summer/winter time (DST change)
Stop loss is too tight / too wide
- If
InpUseATRStopLossis true, the SL adapts to market volatility via ATR - Increase
InpATRMultiplierfor wider stops or decrease it for tighter stops - Alternatively, set
InpUseATRStopLoss=falseto use the fixedInpInitialSLvalue instead
"OrderSend Error 130" in Experts log
- Error 130 means the stop loss or take profit is too close to the current price
- Increase
InpInitialSLorInpATRMultiplierto set a wider stop - Check your broker's minimum stop level for XAUUSD
High spread warnings in the log
- The EA skips trades when spread exceeds
InpMaxSpread - If this happens frequently, consider switching to an ECN account or a broker with tighter gold spreads
- You can increase
InpMaxSpreadbut be aware that wider spreads reduce profitability
Need more help? Reach out via the contact form on the homepage.