Download MetaTrader 5

Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart .

To add comments, please log in or register
barnacle7
379
barnacle7  

If I run the EA on 1 chart, 1 currency eg:AUDUSD only, it identifies the Ordersymbol == Symbol() , When I run the same EA on another chart with another currrency attached Eg:EURUSD on the same MT4 platform (2 currencies running on seperate charts) it returns "false" Ordersymbol doesnt equal Symbol() for EURUSD only, but AUDUSD still Equals OrderSymbol() to Symbol().

If I just run 1 currency on 1 chart it works well.  

I have put code into the Trailingstop section to return an Alert when the Ordersymbol doen't equal symbol as this is were I started having problems was with the Trailing Stop wasn't triggering when the criteria was meet.

 

Any assitance is appreciated. 

Ubzen
5390
Ubzen  

Symbol() equals Attached_Chart_Symbol.

You want to give it a Magic_Number. Use that within the OrderSend.

Remove the if (OrderSymbol()!=Symb)continue;

Add instead if (OrderMagicNumber() != Magic_Number){ continue; }

Simon Gniadkowski
Moderator
18025
Simon Gniadkowski  
barnacle7:

 

 

If I run the EA on 1 chart, 1 currency eg:AUDUSD only, it identifies the Ordersymbol == Symbol() , When I run the same EA on another chart with another currrency attached Eg:EURUSD on the same MT4 platform (2 currencies running on seperate charts) it returns "false" Ordersymbol doesnt equal Symbol() for EURUSD only, but AUDUSD still Equals OrderSymbol() to Symbol().

If I just run 1 currency on 1 chart it works well.   

If you have 2 open trades, one for AUDUSD and one for EURUSD then what you are seeing is correct behaviour.  You do actually want the EA running on EURUSD to identify the AUDUSD order but you don't want it to process them.
whroeder1
15925
whroeder1  

The EA must be able to isolate its trades from all others - Same or other EAs on the same or other charts.

Adding a magic number filter to the order select loop is sufficient if all EAs on all charts are using a unique one.

If you add the EA to another pair and forget to change the magic number, they'll interfere with each other. Adding a symbol filter to the order select loop over comes the human's forgetfulness.

If you add the EA to the same pair but different timeframe then again you have the same problem. I have the EA use a range of numbers to over come this.
extern int     Magic.Number.Base          = 20130213;
int init(){
   int      chrt.tf[]={ 0, PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30,
                           PERIOD_H1, PERIOD_H4, PERIOD_D1,  PERIOD_W1        };
   string   text.tf[]={ "n/a",   "M1",      "M5",      "M15",      "M30",
                                 "H1",      "H4",      "D1",       "W1"       };
   if(Chart.iTF == 0)   while(period.chart > chrt.tf[Chart.iTF])  Chart.iTF++;
   period.market  = chrt.tf[Chart.iTF];
   magic.number   = Magic.Number.Base + Chart.iTF;
}
bool     MySelect(int iWhat, int eSelect, int ePool=MODE_TRADES){
   if(!OrderSelect(iWhat, eSelect, ePool) )  return (false);
   if(OrderMagicNumber() != magic.number  )  return (false);
   if(OrderSymbol()      != symbol.chart  )  return (false);
   if(ePool != MODE_HISTORY               )  return (true);
   return(OrderType() <= OP_SELL);  // Avoid cr/bal https://www.mql5.com/en/forum/126192
                                    // https://www.mql5.com/en/forum/124726
                                    // Never select canceled orders.
}
/////////////////////////////////////////////////////////////////////////////////////////
      for(int iPos = OrdersTotal()-1; iPos >= 0; iPos--) if(
         MySelect(iPos, SELECT_BY_POS)
      ){ oo.ticket   = OrderTicket(); ..
xanderhinds
100
xanderhinds  
whroeder1:

The EA must be able to isolate its trades from all others - Same or other EAs on the same or other charts.

Adding a magic number filter to the order select loop is sufficient if all EAs on all charts are using a unique one.

If you add the EA to another pair and forget to change the magic number, they'll interfere with each other. Adding a symbol filter to the order select loop over comes the human's forgetfulness.

If you add the EA to the same pair but different timeframe then again you have the same problem. I have the EA use a range of numbers to over come this.
In this code what is this and how is it given value?
period.chart
whroeder1
15925
whroeder1  
  1. Can't use periods in variable names, since February 3, 2014 (Build 600)
  2. Simple caching of function calls: period.chart = Period();
xanderhinds
100
xanderhinds  
whroeder1:
  1. Can't use periods in variable names, since February 3, 2014 (Build 600)
  2. Simple caching of function calls: period.chart = Period();
Thanks, you're a star!
To add comments, please log in or register