Skip to content
All library documents

Z-Score Pair Trading with Adaptive Parameter Optimization

Article MQL5 articles

Summary

This article outlines a forex pair-trading system that compares two instruments through their price ratio. It calculates a Z-score to measure how far the ratio has moved from its historical mean, then uses the sign of the score to choose which instrument to buy and which to sell. The example pairs EURUSD with GBPUSD and presents the strategy as a way to trade relative mispricing with limited exposure to broad market direction.

The proposed system also tracks rolling correlations, uses correlation lows alongside Z-score thresholds for entries, sizes positions according to risk, and periodically searches parameter combinations for a suitable lookback and entry and exit levels. Code excerpts illustrate ratio and Z-score calculation, correlation history, and trade direction. The article provides an implementation outline rather than performance evidence. Its assumption that a price ratio will revert depends on a stable relationship; correlation alone does not establish stationarity, and changing market structure can defeat mean reversion. The text acknowledges that ongoing monitoring remains necessary.

Key ideas

  • Pair trading seeks to profit when a relationship between correlated assets deviates from its historical behavior and then reverts.
  • The system measures relative deviation with a Z-score computed from the ratio of two instrument prices.
  • It combines Z-score thresholds with recent correlation lows to identify possible entries and takes opposing positions in the two instruments.
  • Automatic parameter searches are intended to adapt lookback periods and trade thresholds as market conditions change.
  • The article gives an architecture and code examples, but no documented performance results or proof that the pair relationship is stationary.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.