Download MetaTrader 5
To add comments, please log in or register
Do you know that MQL5 is an object-oriented language?
DeanDeV
330
DeanDeV 2015.05.27 21:34 

Hi guys,

I have a function, namely:

void CloseOrders()
 { 
  for(int d=OrdersTotal()-1; d>=0; d--) 
   {
    if(!OrderSelect(d,SELECT_BY_POS,MODE_TRADES)) continue;  
     if(OrderMagicNumber()==(MagicNumber1 || MagicNumber2 || MagicNumber3)    
      && OrderSymbol()==Symbol()                
       && OrderType()==(OP_BUY || OP_SELL) 
    RefreshRates();
     if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),10))          
      Print("Order Close failed, order number: ",OrderTicket()," Error: ",GetLastError());        
   }
 }

 The EA places 4 orders, each issued with a unique magic number (MagicNumber1, MagicNumber2, MagicNumber3 and MagicNumber4). I only want the EA to close MagicNumber1, MagicNumber2, MagicNumber3 orders, and NOT the MagicNumber4 order, however, it is closing all 4. Any ideas what could be causing this?

 Thanks! 

darksideofthemoon
57
darksideofthemoon 2015.05.27 21:43  

Yeah, the code is total bogus :D

Try this: 


 

void CloseOrders() { 
  for(int d=OrdersTotal()-1; d>=0; d--) {
    if(!OrderSelect(d,SELECT_BY_POS,MODE_TRADES)) continue;  
    if((OrderMagicNumber()==MagicNumber1 || OrderMagicNumber()==MagicNumber2 || OrderMagicNumber()==MagicNumber3)
      && OrderSymbol()==Symbol()                
      && (OrderType()==OP_BUY || OrderType()==OP_SELL)) { 
        RefreshRates();
        if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),10))          
          Print("Order Close failed, order number: ",OrderTicket()," Error: ",GetLastError());        
    }
  }
}
Keith Watford
Moderator
7979
Keith Watford 2015.05.27 21:48  
  
     if((OrderMagicNumber()==MagicNumber1 || OrderMagicNumber()==MagicNumber2 || OrderMagicNumber()==MagicNumber3)    
      && OrderSymbol()==Symbol()                
       && (OrderType()==OP_BUY || OrderType()==OP_SELL)) 
Try that
DeanDeV
330
DeanDeV 2015.05.28 03:39  
2cent:

Yeah, the code is total bogus :D

Try this: 


 

 

 

Hahah! I love the word "bogus". Will give this a try. Thanks!
DeanDeV
330
DeanDeV 2015.05.28 03:40  
GumRai:
Try that
Thank you. I know I have tried this. Let's see if it works! 
DeanDeV
330
DeanDeV 2015.05.28 03:44  
2cent:

Yeah, the code is total bogus :D

Try this: 


 

 

 

It seems my code was sheer bogus indeed. thanks for the help! Your code works. :) 
/
To add comments, please log in or register