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(); ..