OrderClose() closing incorrect order

Back to topics list To post a new topic, please log in or register
avatar
120
DeanDeV 2015.05.27 23: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! 

avatar
65
2cent 2015.05.27 23: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());        
    }
  }
}

 

 

avatar
Moderator
3418
GumRai 2015.05.27 23:48 #
 
  
     if((OrderMagicNumber()==MagicNumber1 || OrderMagicNumber()==MagicNumber2 || OrderMagicNumber()==MagicNumber3)    
      && OrderSymbol()==Symbol()                
       && (OrderType()==OP_BUY || OrderType()==OP_SELL)) 
Try that
avatar
120
DeanDeV 2015.05.28 05:39 #
 
2cent:

Yeah, the code is total bogus :D

Try this: 


 

 

 

Hahah! I love the word "bogus". Will give this a try. Thanks!
avatar
120
DeanDeV 2015.05.28 05:40 #
 
GumRai:
Try that
Thank you. I know I have tried this. Let's see if it works! 
avatar
120
DeanDeV 2015.05.28 05: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. :) 
Back to topics list  

To add comments, please log in or register