How to run EA for multiple pairs?

 
Hi
I am new to Forex and MetaTrader and trying to figure out some basics.
Assuming that have an EA which is attached to a chart of EURUSD, BUT I want to find setups in multiple pairs from that EA. But EA only runs when fresh tick for EURUSD comes. Right? Now I see this as MT’s limiting feature as my EA can process for many pairs but initiates only with the fresh tick of attached pair(EURUSD in this case). This probably results in missed ticks of unattached pairs. Hence the following question--

Can EA run for multiple pairs, without attaching to a chart? If not, then what is work around for the problem above? Please advise.

Thanks
Pankaj
 

It is just the way mt4 works. I think there is no work around for this. But this one thing came to my mind right now. If you get EURUSD tick at least 1-2 minutes before new candle (lets say it is H1 candle) you can run while loop to look for new candles on other pairs. In this case if the new tick for EURUSD does not come even for a 5 minutes or more, the while loop already is running and you get all new candles on another pairs. Hope you understand this.

But the question is, why do you need this? It is better to run EA on different charts as EA running on EURUSD would not be able to execute a trade on another pair.

 

Hi there,

I prefer to keep in mind we are still working in real time processing so I just forget about using while loop or wait function to keep the hand on the communication!

Attaching your EA to a pair like EURUSD provides you enough signals to manage all the other pairs, ticks are very frequent. It's not a matter of minute but of second (running a loop for 2 minutes sounds really crazy for me). If it is not a matter of second, just think why or see with another broker.

if you really need more than what you will get in attaching your EA to eurusd, think of running separate instance of your EA attached to each currency. Sorry but I tend to think "or rethink your system".

Sorry if feel that this post is a bit abrupt. Wanted to share with you my point of view.

Good luck.

 
wrm:

 It is better to run EA on different charts as EA running on EURUSD would not be able to execute a trade on another pair.

That's not correct. The OrderSend() function can be executed for any symbol you specify as the first parameter, independent of chart.

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)

 
cloudbreaker:

That's not correct. The OrderSend() function can be executed for any symbol you specify as the first parameter, independent of chart.

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)


Very insightful. Thanks to all of you. I will go with 2nd option as that matches with what I thought before.


wrm: I want to keep things as less as possible. If technically possible then I will just keep one EA. Only reason to keep separate EA is in case I need to plot graph, which I don't need.


Ofcourse, I will test once EA is there. If it doesn't work the way I want then will change it.

 
//+------------------------------------------------------------------+
//|                                                          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);
  }
//+------------------------------------------------------------------+
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.
 
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.

Pretty neat. Thanks tigersoft

 
cloudbreaker:

That's not correct. The OrderSend() function can be executed for any symbol you specify as the first parameter, independent of chart.

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)


Hi, could you elaborate on option #3?


And also, how would price/indicator calculations work with non-native symbols using option#2? I understand sending orders to non-native symbols, but not how to check for entry-conditions on non-native symbols.

 
skyhr:

Hi, could you elaborate on option #3?


And also, how would price/indicator calculations work with non-native symbols using option#2? I understand sending orders to non-native symbols, but not how to check for entry-conditions on non-native symbols.

Use MarketInfo() function for non-native symbols. It's a friend :)

 
skyhr:

Hi, could you elaborate on option #3?


And also, how would price/indicator calculations work with non-native symbols using option#2? I understand sending orders to non-native symbols, but not how to check for entry-conditions on non-native symbols.

Option 3 - simply write a value to a file from an EA monitoring a particular symbol. Have another EA monitor that file and execute a particular piece of logic when that value is present.

Option 2 - Use the MarketInfo() function to retrieve the ask and bid prices for non-native symbols rather than using the Ask and Bid variables which are good only for the native symbol.

 
cloudbreaker:

Option 3 - simply write a value to a file from an EA monitoring a particular symbol. Have another EA monitor that file and execute a particular piece of logic when that value is present.

Option 2 - Use the MarketInfo() function to retrieve the ask and bid prices for non-native symbols rather than using the Ask and Bid variables which are good only for the native symbol.

I think both approaches are good.

Only thing I would like to add is that option #2 has performance merit due to less overhead. Everything will be in memory which obviously is faster than file operation.

One advantage for option #3 is if you want to use the file data for something which MT4 cannot do.

Reason: