Home System Trading Post

Mastering Pair Trading with Tandem: Your Go-To EA for MetaTrader 5

Attachments
955.zip (3.3 MB, Download 0 times)

If you’re new to pair trading, don’t worry! You can dive deeper into the concept in the Literature section. To give you a quick overview, pair trading is all about comparing two similar assets. When you overlay their charts, you’ll notice they tend to diverge and then converge repeatedly. So, why not take advantage of that and turn it into a profit?

The Tandem Expert Advisor (EA) operates on the EURUSD H1 chart, with GBPUSD set as the default correlating pair (this is referred to as the Symbol2 variable or "Indirect symbol"). The EA follows a structured trading plan, but remember, this isn’t about synthetic analysis! Synthetic analysis involves constant averaging and merging both assets, while here, we simply overlay the charts. Before this overlay, the EA identifies an unrestricted starting point, which marks the first crossover of the two pairs.

Next, the EA adjusts Symbol2 so that its price movements align closely with those of the primary symbol. It gathers statistics for the Range (or "Field of training") candles and identifies the maximum divergences during this period. If the divergence exceeds the CorrectLimit (or "Correction of signal border"), a new position is opened—specifically, a pair of positions, one for each symbol. If the divergence continues, a second set of trades is triggered after a predefined number of points. The maximum number of trades is capped by the MaxDeals variable ("Maximum number of transactions").

CorrectDist ("Coefficient length of the search of separation") allows for deeper analysis by adjusting the training period.

The EA trades two currency pairs that either directly or inversely correlate. You can easily switch the Correlation option ("The correlation coefficient") to suit your strategy. Alternatively, if you prefer to trade on a single pair while analyzing divergences between two pairs, you can opt for EURGBP instead of trading EURUSD and GBPUSD. Just enter "EURGBP" (without quotes) into the Cross variable ("Which pair to trade instead of two (cross)"). If you wish to trade GBPEUR, simply set the CrossType variable ("Direct cross-rate") to false.

Once the knowledge gained during the last training cycle expires, the EA undergoes retraining based on Optimum ("Interval of retraining") candles.

The EA provides two signals for closing all trades. Positions will close when the symbols revert by CloseCorr ("Close on reducing of discrepancies") from the maximum divergence or when the open positions hit a specified Profit percentage.

The .mqh include files house essential functions for the EA’s optimal performance:
MyMQL_v2.1.mqh - functions to adapt the EA from MQL4 to MQL5;
PrintLog.mqh - this is crucial for generating an equity.csv file in the Files folder during EA testing, which logs the account equity history. This data can provide insights into drawdowns during testing, and you can even overlay equity graphs from various trading systems.

Testing with Default Parameters Over 11 Years Using Open Prices on EURUSD H1:


Further Reading:

  1. Learn more about Pair Trading
  2. In-depth article on Pair Trading (in Russian)
  3. Another insightful resource (in Russian)
  4. Check the attached magazine in the strategii_parnogo_treydinga.zip archive (in Russian)

Change Log:

September 8, 2012 - Enhanced the EA code considering feedback on potential "holes" in the history of the indirect symbol.

Related Posts

Comments (0)