How do I to close all orders limit ?

 

I have getting an issue that I cannot solve. The problem is that I am opening 2 orders as limit but I can't close it. I tried to use OrdersTotal() and PositionsTotal() to get the tickets and then try to close but it just doesn't works and I don't know why. 


How could I do this ?


Trying

ClosingPositions

void closeAllPositionsLimit(ulong magicNumber){
    CTrade trade;
    
    for(int x = PositionsTotal() - 1; x >= 0; x--){
      int _ticket = PositionGetInteger(POSITION_TICKET);
      trade.PositionClose(_ticket);
               
   
   }//for
      
}

ClosingOrders

void closeAllOrdersLimit(ulong magicNumber){
    CTrade trade;
    
    for(int x = OrdersTotal() - 1; x >= 0; x--){
      int _ticket = OrderGetTicket(ORDER_TICKET);
      trade.OrderDelete(_ticket);               
   
   }//for
      
}
Files:
close_limit.png  24 kb
 

Your orders are still pending orders, so you can't use PositionXXX() functions. There is no such thing as a position limit.

Your closeAllOrdersLimit() doesn't work because it's bugged. OrderGetTicket() requires an index (so x in your case), not ORDER_TICKET. Please read the documentation.

Reason: