RTATC2011 — Day 5 — Multi-Currency Expert Advisor

Following the recent success with Z-Score optimization of my MT5 expert advisor for the Automated Trading Championship 2011, I present the next entry in my Road to ATC 2011 journal. This entry is all about adding a multi-currency support to my expert advisor.
Old Ways
As I’ve already written, adding multi-currency support to an MT5 EA can be very useful, but it’s also quite tricky. In September 2010, I’ve explained how to do it in the most simple way with the use of the standard OnTick() function. But that method has one big disadvantage — you’ll get ticks only from the chart, which has your EA attached to it, but they won’t necessarily coincide with the ticks on the charts for other currency pairs you wish to trade. This, as a result, creates an opportunity for a faulty behavior of the expert advisor. Of course, if your strategy is a long-term one and doesn’t use trailing stop, then it won’t be affected much by this disadvantage. Not the case with my ATC 2011 candidate EA.
Spying on Charts
Konstantin Gruzdev in his article on The Implementation of a Multi-currency Mode in MetaTrader 5 offered a great idea to overcome the disadvantage of using OnTick() in multi-currency EAs. He proposed to use a spy indicator that would generate chart events on all the needed charts and then the EA could use OnChartEvent() standard handler to trade — it just has to check for, which pair was the event generated for, and then use run a usual trade routines for it. You can freely download this simple Spy indicator or see his code here:

#property indicator_chart_window
 
input long chart_id = 0;
input ushort custom_event_id = 0;
 
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
{
  EventChartCustom(chart_id, custom_event_id, (long)_Period, price[rates_total - 1], _Symbol);   
  return(rates_total);
}

input long chart_id = 0;
input ushort custom_event_id = 0;

//+——————————————————————+
//| Custom indicator iteration function |
//+——————————————————————+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
EventChartCustom(chart_id, custom_event_id, (long)_Period, price[rates_total – 1], _Symbol);
return(rates_total);
}

Multi-Currency Expert Advisor 2.0
With the iCustom() function, a multi-currency EA can add these spy indicators to the charts that it wants to trade on and then use OnChartEvent() handler instead of OnTick(). That’s the whole difference between the old multi-currency EA and the new one. You can download my 
multi-currency test EA to see how it works. It can trade on two currency pairs (set via input parameters), but is easily extendable to trade with all 12 currency pairs of the ATC. Z-Score optimization and other parameters can be configured for each currency pair individually, while the trading mechanics don’t need to be changed for each new pair.
New Testing Results
Testing the new EA on the period from 2011.01.01 till 2011.07.01 on EUR/GBP H1 resulted in $247,461.84 profit, which isn’t bad considering a quadruple increase over the profit of EUR/GBP Z-Score optimized EA during the same period. Unfortunately, either due to some error in the Strategy Tester or in the logic of my EA, testing it on EUR/AUD gives different results, which is quite strange. The good thing is that this result isn’t much worse than the one obtained with the test on EUR/GBP — $226,635.36. You can see the backtest reports here:

Multi-Currency EA Test Results on EUR/GBP

Multi-Currency EA Test Results on EUR/AUD
In the next issue of this journal, I’ll show you how to configure the position sizing functions to comply with the ATC 2011 rule that limits the maximum volume of one order with 5 standard lots.
If you are wondering what this post is all about, please read my first post in RTATC2011 series.
P.S.: 2 months and 17 days left for registration in ATC 2011. 857 participants registered so far.

If you have any questions regarding my implementation of the multi-currency expert advisor for MetaTrader 5 or if you want to suggest another idea for making an EA to trade several currency pairs at a time, please reply using the form below.

Leave a Reply

Your email address will not be published. Required fields are marked *

two + 5 =