EA of SPX500 was trying to modify AUDUSD Order

 

Hi,

I am using Metatrader 4 Build 1170.

I encountered something very interesting and I am not sure if anyone encountered this before. 

I am running a few EAs concurrently on the same computer and basically the EAs are the same set of codes. However, I have used a very different OrderMagicNumber for every instrument in order for the EAs to manage the instruments. I am not sure if this is a bug in MQL4 or not but I found that the EA of SPX500 was trying to modify AUDUSD Order. I checked, order number #34805674 belongs to AUDUSD. But why EA of SPX500 was trying to modify AUDUSD Order?

2019.07.03 05:58:53.753 Moving Average EA5 SPX500,M5: modify #34805674 sell 1.02 AUDUSD at 0.69874 sl: 1.19874 tp: 0.68825 ok


Thank you in advance.

 
kentaicm:

Without seeing the code, it is unlikely that anybody can guess.

 
Keith Watford:

Without seeing the code, it is unlikely that anybody can guess.

I just restarted the computer and see what is going on. I am just surprised that the SPX EA wanted to modify the EA of AUD despite the fact that I have added in a unique MagicNumber for the different bot. 

 
Keith Watford:

Without seeing the code, it is unlikely that anybody can guess.

 
Keith Watford:

Ok, the code is below, not sure why the breakeven stop does not kick in as well.


void MoveToBreakeven()
{
   double BEATR=NormalizeDouble((iATR(Symbol(),0,ATRPeriod,1) * ATRToBreakeven),MarketInfo(Symbol(),MODE_DIGITS)); 
   double LockInATR=NormalizeDouble((iATR(Symbol(),0,ATRPeriod,1) * ATRToLockIn),MarketInfo(Symbol(),MODE_DIGITS)); 

   int i,addwinnerTB,addwinnerTS;
   double addwinnerOPB,addwinnerOPS,AddwinnerBuyBreakevenPrice,AddwinnerSellBreakevenPrice;
   bool ans1=false,ans2=false;
   



   for(int b=OrdersTotal()-1; b >= 0; b--)
      {
      if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
         if(OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol() && OrderType()==OP_BUY) //If this is not true, it will not move down further
            if(Bid-OrderOpenPrice()>BEATR) //This need to add the pips definition from ini init
               if(OrderOpenPrice()>OrderStopLoss())
                  if( OrderComment()!="AddWinner" )
                  {
                  double BuyBreakevenPrice=OrderOpenPrice()+LockInATR; 
                  addwinnerTB=GetAddWinnerTicket(Symbol(),OP_BUY);
                  addwinnerOPB=OrderOpenPrice();
                  AddwinnerBuyBreakevenPrice=addwinnerOPB + LockInATR;
                  i=0;ans1=false;ans2=false;
                     while( (!ans1 || !ans2) && i<Resend)
                        { 
                         if(i>0)Sleep(Pause);
                         {
                         Print( "Initial Position - Trying to place buy breakeven stop Price:"+BuyBreakevenPrice+" TP:"+OrderTakeProfit());
                         ans1=OrderModify(OrderTicket(),OrderOpenPrice(),BuyBreakevenPrice,OrderTakeProfit(),0,clrOrange);
                         }
                         if( addwinnerTB!=-1 )
                         {
                         Print( "Addwinner Position - Trying to place buy breakeven stop Price:"+AddwinnerBuyBreakevenPrice+" TP:"+OrderTakeProfit());
                         ans2=OrderModify(addwinnerTB,addwinnerOPB,AddwinnerBuyBreakevenPrice,OrderTakeProfit(),0,clrOrange);
                         }      
                         else
                                ans2=true;
                         i++;
                        }//while(!ans&&i<Resend)    
                        break;            
                  }  
      }
   for(int s=OrdersTotal()-1; s >= 0; s--)
      {
      if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES))
         if(OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol() && OrderType()==OP_SELL) //If this is not true, it will not move down further
            if(OrderOpenPrice()-Ask>BEATR) //This need to add the pips definition from ini init
               if(OrderOpenPrice()<OrderStopLoss())
                  if( OrderComment()!="AddWinner" )
                  {
                  double SellBreakevenPrice=OrderOpenPrice()-LockInATR;
                  addwinnerTS=GetAddWinnerTicket(Symbol(),OP_SELL);
                  addwinnerOPS=OrderOpenPrice();
                  AddwinnerSellBreakevenPrice=addwinnerOPS - LockInATR;
                  i=0;ans1=false;ans2=false;
                     while( (!ans1 || !ans2) && i<Resend)
                     { 
                        if(i>0)Sleep(Pause);
                        {
                        
                        Print( "Initial Position - Trying to place sell breakeven stop Price:"+SellBreakevenPrice+" TP:"+OrderTakeProfit());
                        ans1=OrderModify(OrderTicket(),OrderOpenPrice(),SellBreakevenPrice,OrderTakeProfit(),0,clrOrange);
                        }
                        if( addwinnerTS!=-1 )
                           {
                           
                           Print( "Addwinner Position - Trying to place sell breakeven stop Price:"+AddwinnerSellBreakevenPrice+" TP:"+OrderTakeProfit());
                           ans2=OrderModify(addwinnerTS,addwinnerOPS,AddwinnerSellBreakevenPrice,OrderTakeProfit(),0,clrOrange);
                        }
                        else
                           ans2=true;
                        i++;
                     }      
                  break;                      
                  }                     
      }  
}
 

I can see nothing in that code that would modify a different symbol.

I think that your problem lies elsewhere.

 
Keith Watford:

I can see nothing in that code that would modify a different symbol.

I think that your problem lies elsewhere.

I also noticed that MQL4 cannot place the order as well. Not sure what's wrong as well. I check the Expert log and I noticed that it printed a long list of 2019.07.03 15:30:59.939 Moving Average EA5 GER30,M5: Initial Position - Trying to place buy breakeven stop Price:12572.5 TP:1.31506


I checked the min stop loss distance from the contract specification as well, it should be able to place as the stop is further than the minimum stop distance. However, I can amend it manually. Not sure what is wrong as well.