Close trades on all charts

 

Hi There fellow coders,

I have been working on a correlation EA, well it is two different EA's on two correlated pairs( separate charts) Once the two open trades come into a total profit I want to close both the trades. 

The problem I am having is I can't see how to identify the two trades on either of the charts to to take an overall profit. So my next experiment was to see if I could have a seperate EA on another chart that closes EA's with the same magic number across open charts once they come into overall profit. I have spent hours looking through MQL4 reference to find a command that I could link open charts or something but can't seem to find anything. Is it possible?? even if someone could give me a hint it would be much appreciated. 

Thanks 

 

You can use a time ticker

//+------------------------------------------------------------------+
//|Initialisation function                                           |
//+------------------------------------------------------------------+          
void init()
  {
   EventSetTimer(1);
   return;
  }

To check every 1 second (you can't go less than 1 second with  OnTimer)

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTimer()
{
        for(int i=0; i<OrdersTotal(); i++)
        {
        if(!OrderSelect(i,SELECT_BY_POS)) break;
        symbol=OrderSymbol();
        if(StringSubstr(OrderComment(),0,3)!="Pippo")
		{
		Do somwthnig....
		}
        }
}

You can check the order comment or the MagicNumber or whatever you need

 
SubZer0:

You can use a time ticker

To check every 1 second (you can't go less than 1 second with  OnTimer)

You can check the order comment or the MagicNumber or whatever you need

great thanks, think I've got it

 
SubZer0: You can use a time ticker To check every 1 second (you can't go less than 1 second with  OnTimer) You can check the order comment or the MagicNumber or whatever you need

You can go less than 1 second. Just use "EventSetMillisecondTimer()"!

 
Fernando Carreiro:

You can go less than 1 second. Just use "EventSetMillisecondTimer()"!

Thank you for the hint

 
Adam Woods:

great thanks, think I've got it

if(StringSubstr(OrderComment(),0,3)!="Pippo")

is not correct because it check the first 3 character of the comment use this one:

if(OrderComment() == "Pippo")

If you need more help just ask