Skip to content
All library documents

A Divergence-Based Pair Trading Expert Advisor for Currency Pairs

Article MQL5 code base

Summary

This expert advisor compares the overlaid price histories of two currency pairs and trades when their divergence retreats from a recent maximum. It starts from a chosen point, scales the second pair’s price range to roughly match the chart pair, and measures the largest separation over a configurable training window. When divergence corrects by a specified amount, it opens positions in both symbols; further separation can trigger additional paired entries, subject to a maximum deal count.

The approach supports direct or inverse correlation, optional cross-rate trading, and periodic retraining. It closes positions either after divergence narrows from its extreme or when an open-position profit threshold is reached. The text mentions an eleven-year EURUSD hourly open-price test using default settings, but reports no performance statistics, so the test’s outcome cannot be assessed. It also notes a correction addressing gaps in the indirect symbol’s historical data. The description does not establish that the apparent convergence persists out of sample or after trading costs.

Key ideas

  • The strategy trades two currency pairs when their overlaid prices diverge and then begin to converge.
  • A training window estimates maximum divergence, while configurable thresholds govern entries and retraining.
  • Additional paired positions may be opened as divergence grows, up to a user-defined limit.
  • The system supports direct or inverse correlation and can trade a cross rate instead of both pairs.
  • Positions close when divergence contracts from its extreme or an open-position profit threshold is met.
  • An eleven-year historical test is mentioned, but no results are supplied.

Tags

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