How to run EA for multiple pairs? - page 3

 

Jacques, I appreciate your continuing interest in this thread. I'm still debugging my EA for its first currency, but intend to use it on several if found to be suitable. On that premise, I have been contemplating a strategy on to how implement that notion. Thus, my interest in this thread.


Pursuant to your request, I prepared graphs for three more pairs, and in doing so I discovered that two of the pairs had more than 32,000 ticks in a 24 hour period (the graphing data limit in Excel). As a result, I had to break the graph into two periods (1st 12 hours, and 2nd 12 hours). To keep things relatively consistent I broke all three pairs into 12-hour periods.


One thing to keep in mind, the vertical scale on these graphs is proportional between the horizontal lines, but the horizontal scale is NOT time proportional (ie you cannot assume that 1/12 of the ticks represents one hour)


I think the big takeaway from these graphs is that all of the pairs have periods in a 24-hour period where there are significant intervals between ticks. As a result, if you combine multiple pairs into one EA I think it would be wise to employ a "While" loop. StraightTrader's reference to https://book.mql4.com/special/index entitled "General Characteristics of Complex Programs" has a good discussion of this technique and a graph in the opening section of this article.


GBPJPY 44,834 ticks in 24 hours

EURJPY 37,140 ticks in 24 hours

GBPUSD 29,313 ticks in 24 hours

EURUSD 22,627 ticks in 24 hours













Cheers!

 
FXtrader2008:

As a result, if you combine multiple pairs into one EA I think it would be wise to employ a "While" loop. StraightTrader's reference to https://book.mql4.com/special/index entitled "General Characteristics of Complex Programs" has a good discussion of this technique and a graph in the opening section of this article.

That's exactly the case. Multiple pairs in one EA -> use while loop approach instead of start function activation by incomming ticks.


I would like to be in opposition to one currency pair for one EA.

My long temr approach is ONE MULTICURRENCY MULTISTRATEGY EA. I prepared some time ago Universal Expert Advisor scheme,which implements som of these ideas.

Later, not included in my post I followed by developing this code and started Google code project called Universaltrader. This project could fullfill your expectations. The only one thing not implemented there is noted While cycle approach (easy to implement).


Some of the advantages of MULTICURRENCY MULTISTRATEGY EA:

  • all strategies together
  • possible to tune/setup all strategies together and also independently
  • possible to switch ON/OFF different strategies/currency pairs
  • I am sure many more adv. are there

disandvantages:

  • possibility to backtest only one currency pair at a time - you have to run backtest so many times how many currency pairs you are trading, with other pairs switched off
  • performance issue - I noticed performance issue only in backtest, but I am sure in real trading it is also relevant - depends on implemented strategies complexity and number of them.

This project needs to be improved still so if anybody has an interest I can invite him into this Google code project


Current script attached here:

 
FXtrader2008 wrote >>

Jacques, I appreciate your continuing interest in this thread. I'm still debugging my EA for its first currency, but intend to use it on several if found to be suitable. On that premise, I have been contemplating a strategy on to how implement that notion. Thus, my interest in this thread.

Pursuant to your request, I prepared graphs for three more pairs, and in doing so I discovered that two of the pairs had more than 32,000 ticks in a 24 hour period (the graphing data limit in Excel). As a result, I had to break the graph into two periods (1st 12 hours, and 2nd 12 hours). To keep things relatively consistent I broke all three pairs into 12-hour periods.

One thing to keep in mind, the vertical scale on these graphs is proportional between the horizontal lines, but the horizontal scale is NOT time proportional (ie you cannot assume that 1/12 of the ticks represents one hour)

I think the big takeaway from these graphs is that all of the pairs have periods in a 24-hour period where there are significant intervals between ticks. As a result, if you combine multiple pairs into one EA I think it would be wise to employ a "While" loop. StraightTrader's reference to https://book.mql4.com/special/index entitled "General Characteristics of Complex Programs" has a good discussion of this technique and a graph in the opening section of this article.

GBPJPY 44,834 ticks in 24 hours

EURJPY 37,140 ticks in 24 hours

GBPUSD 29,313 ticks in 24 hours

EURUSD 22,627 ticks in 24 hours

Cheers!

Thanks a lot for your charts.

Lets opt for a loop instead of a tick run activation, it will be more scientific for those who need minute precision and it's not a big deal to implement. Another advantage is that you can attach the EA to what ever currency pair you want (it's useful when it draws object on the chart).

Cheers

 
cloudbreaker wrote >>

And you can retrieve the most recent ask and bid prices for symbols outside of the current chart by using the MarketInfo() function.

So you have options as follows.

- Have the same EA attached to many charts and operating for the native symbol of each chart (using Ask and Bid built-in variables)

- Have an EA attached to a specific chart which executes for all chosen symbols (with MarketInfo() function for non-native symbols) - just using the native symbol ticks as a triggering device

- Have master and slave EAs attached to different charts where one is triggered by the other (eg. one writes a value to a file, the other constantly reads the file until it finds this data and then trades)

Right now, I'm using the simplest of these strategies - I have an EA on three timeframes of four currencies, so twelve in all. They all are set to run on the first tick of the timeframe. However, I'm having a problem in that MT4 doesn't always execute all of the EA's. I put a print statement right after the start function just to see what was happening, and it was only getting to three of the four EA's of H1 for instance, but it was missing different pairs different times, and the EA was identical except for settings from optimizations for each pair.

Question - Does MT4 in only execute one EA at a time when multiple EA's are set to run simultaneously? Is one EA's execution in any way dependent of that of another (aside from trade context being busy), or are they completely independent?

If so, I could use the second option, I'm just trying to keep the EA as simple as possible, because for me at least, the more complexity I write in, the more mistakes I make.

 
joetrader:

Right now, I'm using the simplest of these strategies - I have an EA on three timeframes of four currencies, so twelve in all. They all are set to run on the first tick of the timeframe. However, I'm having a problem in that MT4 doesn't always execute all of the EA's. I put a print statement right after the start function just to see what was happening, and it was only getting to three of the four EA's of H1 for instance, but it was missing different pairs different times, and the EA was identical except for settings from optimizations for each pair.

Question - Does MT4 in only execute one EA at a time when multiple EA's are set to run simultaneously? Is one EA's execution in any way dependent of that of another (aside from trade context being busy), or are they completely independent?

If so, I could use the second option, I'm just trying to keep the EA as simple as possible, because for me at least, the more complexity I write in, the more mistakes I make.

I have multiple EA's running on charts with no problems like that. As far as I can tell they run simultaneously, only time they notice one another is when the trade context is used by one of them. As for the EA itself it's completely independent - each has it's own copy of variables, etc. Let me just get this straight - u are running 12 EA's attached to 12 charts? Maybe u have memory problems?

 
gordon wrote >>

I have multiple EA's running on charts with no problems like that. As far as I can tell they run simultaneously, only time they notice one another is when the trade context is used by one of them. As for the EA itself it's completely independent - each has it's own copy of variables, etc. Let me just get this straight - u are running 12 EA's attached to 12 charts? Maybe u have memory problems?

Right. 12 EA's on 12 charts. Pretty new computer with 6GB memory, so I wouldn't think it would be memory, but it's worth considering, and I won't rule it out. But you've answered my question - If EA's are supposed to be able to run simultaneously, then maybe I'm just doing something wrong. Not the first time! I'll check the code and study some more. Thanks for your help.

 
Are you running the charts in separate instances of the MT4 client? If you are opening all charts in one instance then they will be sharing a single trading context and you will need to code in the logic to share that context - if the behaviour of your EAs means more than one is likely to be performing a trading operation at the same time. CB
 
cloudbreaker wrote >>
Are you running the charts in separate instances of the MT4 client? If you are opening all charts in one instance then they will be sharing a single trading context and you will need to code in the logic to share that context - if the behaviour of your EAs means more than one is likely to be performing a trading operation at the same time. CB

Yes - I'm running them on the same MT4 client. But I'm using one of the trade context busy solutions from this article https://www.mql5.com/en/articles/1412 and I don't get any trade context busy errors.

It doesn't seem to even get to the point where it attempts to open a position. It doesn't seem to start the EA at all for some. I say that because I put a print statement at the beginning of my start function.

Here's my start function:

void start()
{
//---- go trading only for first ticks of new bar
if(Volume[0]>1) return;
Print("Tick Check");

if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();
}

I'm trading on CADJPY,EURCHF,GBPUSD, & USDJPY

And I get this:

2010.01.22 8:59:45 [EAName]USDJPY,H1: Tick Check

2010.01.22 8:59:45 [EAName]CADJPY,H1: Tick Check

2010.01.22 8:59:45 [EAName]GBPUSD,H1: Tick Check

2010.01.22 9:59:45 [EAName]EURCHF,H1: Tick Check

2010.01.22 9:59:46 [EAName]GBPUSD,H1: Tick Check

2010.01.22 9:59:46 [EAName]CADJPY,H1: Tick Check

Some hours all four will trade, some only three. If it's an hour for the H4's to trade, three of them might trade, but usually not all four along with three or four of the H1's.

I've created a workaround where I increase the volume to 3 or 4 ticks just to be sure everything trades, but I'm trying to understand MetaTrader better so I can fix the root problem.

So my question is - since my EA has only one tick to run, would it run each EA concurrently, and maybe that’s why they’re not all running? I have a loop in my EA that compares up to 1500 of the past fractals to find a stoploss, so that could take some time.

Again, there may just be a problem in my code somewhere.

 
I am guessing you have a problem with your code and this has nothing to do with the subject of multiple EA's. You need to pin-point the problem for the ones that don't start using the standard Print()/Alert() methods to see what doesn't work.
 
tigersoft:
Here is a simple code to open EURUSD and USDCHF on one chart. Even ea is added on another chart so it will open EURUSD and USDCHF.

 

//+------------------------------------------------------------------+
//|                                                          jkh.mq4 |
//|                      Copyright © 2009, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

bool wannaBuy = true;
bool wannaBuy1 = true;
extern double LotSize = 0.01;
extern string symbol1 = "EURUSD";
extern string symbol2 = "USDCHF";
extern int MaxDifference = 6;
extern int Slippage = 3;
extern int Magicnumber1 = 786;
extern int Magicnumber2 = 123;
int sendticket = 3;
string pairs[18];

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
pairs[0] = symbol1;
pairs[1] = symbol2;
wannaBuy = true;
wannaBuy1 = true;

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   // Send order for EURUSD & USDCHF
   if (wannaBuy) {   
   int ticket1;
   RefreshRates();
   ticket1 = OrderSend(symbol1, OP_BUY, LotSize, MarketInfo(symbol1,MODE_ASK), Slippage, 0, 0, 0,0,Magicnumber1,0) & OrderSend(symbol2, OP_BUY, LotSize, MarketInfo(symbol2,MODE_ASK), Slippage, 0, 0, 0,0,Magicnumber2,0);
   if (ticket1 <0 )
   {
   Print ("OrderSend failed with error #", GetLastError());
   return(0);
   }
   wannaBuy = false;
   }

//----
   return(0);
  }
//+------------------------------------------------------------------+

 

does not work? 

for back testing
 got ordersend error 4106 

unknown symbol name for USDCHF for ordersend function

 

Ordersend works for EURUSD if I choose the symbol EURUSD for setting or EURUSD chart.

 

If I change to another chart, I will get unknown symbol for both EURUSD and USDCHF 

 

Thanks! in advance 

Reason: