How can I run the same EA with different settings on the same pair?

 

Hi,

I have an EA what I want to run on the same pair with different settings. Now it opens only one position even if two other EAs were suppose to open a trade as well.

And even worse, if one EA is suppose to close it position, but does not have an open one, it just closes a position from another EA.

Is there something wrong with my Magic Number?

Any ideas? Thanks in advance!


extern int        MagicNumber = 123456;

extern double     Lots=0.01;
extern int        Timeframe=0;
extern int        EMA_PeriodSlow=100;

int start(){
  
  
   int cnt, ticket; 
   double EmaSlow=iMA(NULL,Timeframe, EMA_PeriodSlow,0,MODE_EMA, PRICE_CLOSE,1);
   double EmaSlowPrev=iMA(NULL,Timeframe, EMA_PeriodSlow,0,MODE_EMA, PRICE_CLOSE,2);
  
   
   int ordTotal = 0;
   for(int i = 0;i < OrdersTotal();i++){
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol() == Symbol())
         ordTotal++;
   }
   int total=ordTotal;
   if (total<1){
         if(EmaSlow<Close[1] && EmaSlowPrev > Close[2]){
            if (Trading_on_off && alertTag != Time[0]){ 
            ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,5*places,0,0,"EMAperiod", MagicNumber,0,Green);
            alertTag=Time[0];
            PlaySound ("Alert2");
            Print("ticket ", ticket, "MagicNumber is ", MagicNumber, "EMA:", EmaSlow);
            
        }}
          if(EmaSlow>Close[1] && EmaSlowPrev <Close[2]){
            if (Trading_on_off && alertTag != Time[0]){
            ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,5*places,0,0,"EMAperiod", MagicNumber,0,Red);
            alertTag=Time[0];
            PlaySound ("Alert2");
            Print("Account free margin is ", AccountFreeMargin(), "MagicNumber is ", MagicNumber, "EMA:", EmaSlow);
        }}}  
   
   for(cnt=OrdersTotal()-1;cnt>=0;cnt--){
   if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)
         &&  OrderMagicNumber()  == MagicNumber      // my magic number
         &&  OrderSymbol()       == Symbol()          // and my pair.
         &&  OrderType()<=OP_SELL ){                  // need this only if EA opens pending orders.

         if (Close_at_EMA_break){
               if(EmaSlow>Close[1] && EmaSlowPrev<Close[2]){       
                  OrderClose(OrderTicket(),OrderLots(),Bid,5*places,Blue);
                return(0);
         }}
       
       else{
         if (Close_at_EMA_break){
           if(EmaSlow<Close[1] && EmaSlowPrev>Close[2]){
              OrderClose(OrderTicket(),OrderLots(),Ask,5*places,Violet);
              return(0);
      }}}}}
  return(0);
}
 
ARe you using the same magic number on your EAs? :) Or are you using multiple instances of the same EA on the same symbol, but multiple timeframes?
 
forexCoder:
ARe you using the same magic number on your EAs? :) Or are you using multiple instances of the same EA on the same symbol, but multiple timeframes?
different Magic Number, different EMA_PeriodSLow

Same EA, same timeframe, same symbol, same Lot, same problem

 

Seb

Sadly it is doing what just you programmed it to do..

The constructs are wrong

1) ordTotal generation is not taking MagicNumber into account, so it will miss some order entries

2) The second looping of OrdersTotal() closes an order (if found) that is specifically not of the MagicNumber set at the top...

-BB-

 
BarrowBoy:

Seb

Sadly it is doing what just you programmed it to do..

The constructs are wrong

1) ordTotal generation is not taking MagicNumber into account, so it will miss some order entries

2) The second looping of OrdersTotal() closes an order (if found) that is specifically not of the MagicNumber set at the top...

-BB-


I mean I understand the basics of programming, but to be honest, I kept trying to modify the code, but it doesnt get any better. Do you maybe have some examples what I can paste in my code?

Thanks, Seb

Reason: