Statistical Pair Arbitrage
- Experts
- Versione: 1.0
Statistical Pair Arbitrage
Statistical Pair Arbitrage is a fully automated multi-symbol Expert Advisor for MetaTrader 5.
The EA is designed to identify temporary statistical deviations between two financial instruments. Instead of attempting to predict the absolute direction of a single market, the strategy analyzes the relationship between two symbols and looks for situations where their price relationship moves significantly away from its recent statistical average.
The default configuration uses EURUSD and GBPUSD on the H1 timeframe.
CORE STRATEGY
The Expert Advisor calculates a logarithmic price spread between two instruments:
Spread = Log(Symbol A Price) - Log(Symbol B Price)
The EA then calculates the historical mean and standard deviation of this spread over a configurable lookback period.
Using these values, the current deviation is expressed as a Z-Score.
The Z-Score indicates how far the current spread has moved away from its recent statistical average.
DEFAULT SETTINGS
Symbol A: EURUSD
Symbol B: GBPUSD
Timeframe: H1
Lookback Period: 100 bars
Entry Z-Score: 2.00
Exit Z-Score: 0.50
ENTRY LOGIC
When the spread rises significantly above its historical average:
Z-Score >= +2.00
the EA interprets the spread as relatively high and can open:
SELL Symbol A
BUY Symbol B
When the spread falls significantly below its historical average:
Z-Score <= -2.00
the EA interprets the spread as relatively low and can open:
BUY Symbol A
SELL Symbol B
The objective is to capture a potential normalization of the relationship between the two instruments.
EXIT LOGIC
The EA continuously recalculates the statistical relationship while a pair is open.
By default, both positions are closed when:
Absolute Z-Score <= 0.50
This means the strategy attempts to exit when the spread has moved back toward its recent statistical mean.
MULTI-SYMBOL TRADING
This Expert Advisor simultaneously works with two symbols.
The default pair is:
EURUSD / GBPUSD
However, Symbol A and Symbol B are configurable from the EA inputs.
Both symbols must be available from the user's broker and sufficient historical data must be available for the selected timeframe.
PAIR EXECUTION PROTECTION
A statistical arbitrage trade requires two positions.
The EA therefore includes protection against incomplete pair execution.
If the first leg is successfully opened but the second leg cannot be opened, the EA attempts to close the first leg instead of intentionally leaving an unpaired directional position.
POSITION MANAGEMENT
Each side of the pair uses a separate Magic Number derived from the EA's Magic Base.
This allows the Expert Advisor to identify and manage its own positions.
By default, only one statistical arbitrage pair is active at a time.
DEFAULT POSITION SIZE
Default Symbol A Lot: 0.01
Default Symbol B Lot: 0.01
Maximum Lot: 1.00
Lot sizes for both symbols can be configured independently.
Because different instruments may have different contract sizes, tick values and volatility characteristics, users should select appropriate position sizes for the pair they intend to trade.
CONSECUTIVE LOSS PROTECTION
The EA includes additional loss protection.
Default settings:
Consecutive Loss Limit: 3
Pause Period: 60 minutes
When the configured loss limit is reached, new entries are temporarily suspended for 60 minutes.
TRADING SAFETY CHECKS
Before attempting trades, the Expert Advisor checks important trading conditions including:
- Terminal connection
- Automated trading permission
- Account trading permission
- Symbol trading availability
- Broker trading sessions
- Spread limits
- Available margin
- Symbol volume requirements
- Existing pair positions
SPREAD PROTECTION
Maximum spread limits can be configured separately for Symbol A and Symbol B.
This helps prevent the EA from intentionally initiating new pairs when transaction costs exceed the configured limits.
STRATEGY CHARACTERISTICS
- Statistical pair trading
- Z-Score based entries
- Mean-reversion approach
- Two-symbol execution
- Configurable trading pair
- Configurable analysis timeframe
- Configurable entry and exit thresholds
- Separate Magic Numbers for both legs
- Incomplete-pair protection
- Consecutive-loss protection
- No Martingale
- No Grid
- No lot multiplication recovery system
IMPORTANT INFORMATION
Statistical relationships are not guaranteed to remain stable.
Two instruments that historically moved together can diverge for extended periods or permanently change their relationship due to market conditions, economic events, volatility or structural changes.
This EA does not provide risk-free or guaranteed arbitrage. It implements a statistical mean-reversion strategy based on the historical relationship between two instruments.
Execution quality is also important because the two legs cannot be guaranteed to execute at exactly the same moment or at the expected prices.
Broker spreads, commissions, swaps, slippage, liquidity, contract specifications and trading sessions can affect performance.
Before using a different symbol pair, users should test and adjust the parameters for those instruments.
RISK WARNING
Trading financial markets involves risk and losses are possible.
Statistical arbitrage does not guarantee profit. Historical correlations and statistical relationships may change without warning.
Backtesting results and historical performance do not guarantee future results.
Users should test the Expert Advisor with their own broker, symbols, account type and trading conditions before using it for live trading.
