Download MetaTrader 5
To add comments, please log in or register
Join MQL5 Cloud Network. Improve your rating!
Lynn
49
Lynn 2014.05.09 13:06 
Ever since the new MT4 build was released, I've had issues with OrderDelete(). I have a loop that manages my open trades, but this is the only function not working. Can some please help? The code is below. Thanks.
  double OpenPoint = iOpen(Symbol(), PERIOD_W1, 0);
 
  int total, i, ticket, OrdOpen;
  total = OrdersTotal();                          
  for(i=0; i<total; i++)
  { 
   if(OrderSelect(i, SELECT_BY_POS)==true)
   {
      if(OrderSymbol() == Symbol() && (OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP || OrderType() == OP_BUY || OrderType() == OP_SELL)) OrdOpen++;                                                                            
      if(OrderSymbol() == Symbol() && OrderType() == OP_BUYSTOP && Ask < OpenPoint) bool res=OrderDelete(ticket); //THIS DOES NOT WORK
      if(OrderSymbol() == Symbol() && OrderType() == OP_SELLSTOP && Bid > OpenPoint)  res=OrderDelete(ticket);    //THIS DOES NOT WORK                                               
      if(OrderSymbol() == Symbol() && OrderType() == OP_BUY && Bid > OrderOpenPrice() + 100/Multiple) res=OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + 100/Multiple, 0, 0, Red);                                        
      if(OrderSymbol() == Symbol() && OrderType() == OP_SELL && Ask < OrderOpenPrice() – 100/Multiple) res=OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - 100/Multiple, 0, 0, Red);                            
      if(OrderSymbol() == Symbol() && OrderType() == OP_BUY && Bid > OrderOpenPrice() + 5/Multiple && Bid < OrderOpenPrice() + 100/Multiple) res=OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), 0, 0, Red); 
      if(OrderSymbol() == Symbol() && OrderType() == OP_SELL && Ask < OrderOpenPrice() - 5/Multiple && Ask > OrderOpenPrice() - 100/Multiple) res=OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), 0, 0, Red);
   }
  }  
   if(OrdOpen > 0) return(0);
Keith Watford
Moderator
7990
Keith Watford 2014.05.09 13:14  

Your code is twice as wide as my screen and to be honest, I can't be bothered to scroll back and forth in order to read it.

If you make your code easier to read, on different lines and with indentation, you will probably get more people willing to help you.

Lynn
49
Lynn 2014.05.09 13:35  
Sorry GumRai. Hopefully this helps. Thanks.
double OpenPoint = iOpen(Symbol(), PERIOD_W1, 0); 
int total, i, ticket, OrdOpen;
total = OrdersTotal();                          
for(i=0; i<total; i++)
{ 
 if(OrderSelect(i, SELECT_BY_POS)==true)
 {
  if(OrderSymbol() == Symbol() && OrderType() == OP_BUYSTOP && Ask < OpenPoint) bool res=OrderDelete(ticket); 
  if(OrderSymbol() == Symbol() && OrderType() == OP_SELLSTOP && Bid > OpenPoint)  res=OrderDelete(ticket);                                                 
 }
}  
 return(0);
GreenMoney
379
GreenMoney 2014.05.09 13:39  

You haven't made the variable "ticket" equal to a valid ticket number.

You need to either make the variable "ticket" equal to OrderTicket() inside the OrderSelect() IF statement or just use OrderTicket() inside the OrderDelete().

if(OrderSymbol() == Symbol() && OrderType() == OP_BUYSTOP && Ask < OpenPoint) bool res=OrderDelete(OrderTicket());
if(OrderSymbol() == Symbol() && OrderType() == OP_SELLSTOP && Bid > OpenPoint)  res=OrderDelete(OrderTicket());

You should also consider counting down in your FOR loop. See Loops and Closing or Deleting Orders.

Lynn
49
Lynn 2014.05.09 13:41  
Thirteen:

You haven't made the variable "ticket" equal to a valid ticket number.

You need to either make the variable "ticket" equal to OrderTicket() inside the OrderSelect() IF statement or just use OrderTicket() inside the OrderDelete().

.


Thanks, Thirteen! I'll give it a whirl.
qjol
3243
qjol 2014.05.09 13:47  
OrderDelete(OrderTicket());
Lynn
49
Lynn 2014.05.09 13:47  
7455:

Thanks, Thirteen! I'll give it a whirl.

Thirteen, it works like a charm. Thanks again!
whroeder1
13644
whroeder1 2014.05.09 23:07  
for(i=0; i<total; i++)
Count DOWN. Loops and Closing or Deleting Orders - MQL4 forum
/
To add comments, please log in or register