Pairs Trading Expert
- Эксперты
- Rasoul Mojtahedzadeh
- Версия: 3.0
- Обновлено: 7 ноября 2025
- Активации: 5
| Profitable Statistical Arbitrage and Mean Reversion Algorithm |
This Expert Advisor implements the well-established Pairs Trading algorithm — a classic quantitative trading strategy based on statistical arbitrage and mean reversion.
The EA identifies the optimal hedge ratio between two correlated trading symbols to construct a synthetic stationary spread. It continuously monitors the deviation of this spread from its mean value and opens synthetic BUY/SELL baskets when the spread reaches statistically significant extremes (measured in standard deviations). The underlying assumption is that the spread will revert to its mean, allowing the EA to close the basket and capture profits once mean reversion occurs.
The EA automatically calculates and adjusts the hedge ratio in real time, ensuring adaptive performance under changing market conditions. Entry and exit levels (in terms of standard deviation) are fully customizable, allowing the user to fine-tune the aggressiveness of the mean-reversion strategy. The base symbol’s lot size is user-defined, while the hedge symbol’s lot size is dynamically computed by the EA to maintain the desired hedge ratio and maximize the likelihood of convergence.
This EA can be applied to any two symbols in any market — including Forex, stocks, indices, and commodities.
For optimal performance in Forex trading, it is recommended to select two pairs sharing a common currency (e.g., attach the EA to USDCAD as the base symbol and set the hedge symbol to AUDUSD).
Remember, the base symbol is always the chart symbol to which the EA is attached.
Input Settings
- Hedge Symbol (string): The hedge symbol name that exists in the Market Watch. Default is empty, if you leave it empty the EA will choose AUDUSD by default.
- Exit Std Level [0, inf) (double): The standard deviation level at which the EA will close a basket. Default is zero (mean level).
- Entry Std Level (0, inf) (double): The standard deviation level at which the EA will open the first basket. Default is 1.0.
- Lot Size Scaler (double): The base symbol lot size. Default is 1.0.
- Rolling Window Welford (integer) — Rolling window size used for Welford’s algorithm in Z-score calculation. Default: 500.
Notes:
- The Entry and Exit standard deviation levels should be optimized for each symbol pair.
- Recommended optimization range: [0.0, 3.0] with 0.1 increments.
- Not all symbol combinations are profitable — ensure they exhibit sufficient correlation or cointegration.
- The EA operates using bar open prices, so for backtesting, it’s recommended to set the Modeling mode to Open prices only for faster performance (though this is optional).
