Gold Silver Statistical Arbitrage
- Experts
- Versione: 1.1
Gold Silver Statistical Arbitrage
Gold Silver Statistical Arbitrage is a fully automated multi-symbol Expert Advisor for MetaTrader 5, designed to analyze the statistical relationship between Gold (XAUUSD) and Silver (XAGUSD).
Instead of attempting to predict the direction of Gold or Silver independently, the EA monitors the relative price relationship between the two metals and looks for temporary statistical deviations.
The strategy uses a logarithmic price spread and Z-Score calculation to identify potential mean-reversion opportunities.
CORE STRATEGY
The Expert Advisor calculates the relationship between Gold and Silver using:
Spread = Log(Gold Price) - Log(Silver Price)
It then calculates the historical mean and standard deviation of this spread over a configurable lookback period.
The current deviation from the historical mean is expressed as a Z-Score.
When the relationship moves significantly away from its recent statistical average, the EA can open opposite positions on Gold and Silver.
DEFAULT CONFIGURATION
Gold Symbol: XAUUSD
Silver Symbol: XAGUSD
Analysis Timeframe: H1
Lookback Period: 120 bars
Entry Z-Score: 2.00
Exit Z-Score: 0.50
ENTRY LOGIC
HIGH SPREAD CONDITION
When:
Z-Score >= +2.00
the Gold/Silver spread is considered relatively high.
The EA can open:
SELL Gold (XAUUSD)
BUY Silver (XAGUSD)
LOW SPREAD CONDITION
When:
Z-Score <= -2.00
the Gold/Silver spread is considered relatively low.
The EA can open:
BUY Gold (XAUUSD)
SELL Silver (XAGUSD)
The objective is to capture a potential normalization of the statistical relationship between the two metals.
EXIT LOGIC
While a pair is open, the EA continuously monitors the Z-Score.
By default, the pair is closed when:
Absolute Z-Score <= 0.50
This indicates that the Gold/Silver relationship has moved back toward its recent statistical average.
MULTI-SYMBOL TRADING
The EA trades two instruments as one statistical pair:
XAUUSD + XAGUSD
Both symbols must be available from the broker.
The symbol names can also be changed from the Expert Advisor inputs if the broker uses different names for Gold and Silver.
Examples may include:
XAUUSD
XAUUSD.a
GOLD
and:
XAGUSD
XAGUSD.a
SILVER
Users should enter the exact symbol names provided by their broker.
PAIR EXECUTION PROTECTION
A statistical arbitrage position consists of two separate trading legs.
The EA includes protection against incomplete pair execution.
If the first position is successfully opened but the second position cannot be opened, the EA attempts to close the first position rather than intentionally leaving an unpaired directional trade.
POSITION MANAGEMENT
The Gold and Silver legs use separate Magic Numbers derived from the EA's Magic Base.
Default Magic Base:
2026096100
This allows the Expert Advisor to identify and manage its own Gold and Silver positions.
By default, only one Gold/Silver pair is active at a time.
DEFAULT POSITION SIZE
Gold Lot: 0.01
Silver Lot: 0.01
Maximum Lot: 1.00
Gold and Silver can have very different contract specifications, tick values, volatility and margin requirements.
Users should therefore select appropriate lot sizes according to their broker's specifications and account conditions.
SPREAD PROTECTION
The EA includes separate spread protection for both instruments.
Default maximum spread settings:
Gold: 1500 points
Silver: 1500 points
New pair entries are prevented when the configured spread conditions are not satisfied.
TRADING SESSION PROTECTION
Before attempting an order, the EA checks whether trading is currently available for each instrument.
This helps prevent unnecessary order attempts when Gold or Silver trading is unavailable according to the broker's trading session.
CONSECUTIVE LOSS PROTECTION
The Expert Advisor includes additional loss protection.
Default settings:
Consecutive Loss Limit: 3
Trading Pause: 60 minutes
When the configured loss limit is reached, new pair entries are temporarily suspended.
After the pause period expires, the EA can resume searching for new statistical opportunities.
SAFETY CHECKS
Before attempting to open positions, the Expert Advisor checks:
- MetaTrader connection
- Automated trading permission
- Account trading permission
- Symbol trading availability
- Gold trading session
- Silver trading session
- Gold spread
- Silver spread
- Available margin
- Broker volume requirements
- Existing EA positions
STRATEGY CHARACTERISTICS
- Gold and Silver pair trading
- XAUUSD / XAGUSD analysis
- H1 statistical analysis
- Z-Score based entry logic
- Mean-reversion approach
- Logarithmic price spread
- Configurable lookback period
- Configurable entry threshold
- Configurable exit threshold
- Multi-symbol execution
- Separate Magic Numbers
- Incomplete-pair protection
- Spread protection
- Trading-session protection
- Consecutive-loss protection
- No Martingale
- No Grid
- No recovery lot multiplication
IMPORTANT INFORMATION
This Expert Advisor implements a statistical mean-reversion strategy. It is not risk-free arbitrage.
Gold and Silver have historically shown periods of related price behavior, but their statistical relationship can change significantly over time.
The spread can remain outside its historical range for an extended period, and there is no guarantee that a statistical deviation will return to its previous mean.
Execution of both trading legs at exactly the same time or price cannot be guaranteed.
Broker spreads, commissions, swaps, slippage, liquidity, contract sizes, trading sessions and execution conditions can materially affect the performance of the strategy.
RISK WARNING
Trading Gold, Silver and other leveraged financial instruments involves significant risk.
Statistical arbitrage does not guarantee profits or eliminate losses.
Historical relationships, backtests and previous market behavior do not guarantee future performance.
Users should test the Expert Advisor with their own broker, account type, XAUUSD/XAGUSD specifications and trading conditions before using it on a live account.
