View Single Post
  #1 (permalink)  
Old 12-13-2005, 10:58 PM
christan christan is offline
Junior Member
 
Join Date: Nov 2005
Posts: 5
christan is on a distinguished road
Function to effectively close all orders.

I have been using this function to try and close all my orders, both pending and open. However for some unknown reason, there's always unclosed orders remaining. How do I ensure that every single pending/open order closes?

Code:
// close all open and pending orders
void closeAllOrders()  {
   int total = OrdersTotal();
   for (int i=total-1; i>=0; i--)  {
      if (OrderSelect(i, SELECT_BY_POS))  {
         if (OrderType() == OP_BUY)  {
            OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 3, Red);
         } else if (OrderType() == OP_SELL)  {
            OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 3, Red);   
         } else if (OrderType() > 1)  {
            OrderDelete(OrderTicket());   
         }
      }
   }
} // end closeAllOrders()
Reply With Quote