I want delete all orders pending only a symbol()

 

 I want delete all orders pending only a symbol()

Thank you

total=OrdersTotal();    //getting total orders including open and pending
   for(d=0; d<total; d++)
     {  
     
      if(OrderSelect(d,SELECT_BY_POS,MODE_TRADES))
        {
         Order_Type=OrderType();
         //---- pending orders only are considered
         if(Order_Type!=OP_BUY && Order_Type!=OP_SELL)
           {       
            totalPendingOrders++;
            }
         }
   }
   
   //Displaying number or total pending orders
   Print("Total Pending Orders "+totalPendingOrders);
   
   
   //Selecting pending orders and deleting first order in the loop till last order
   for(e=0; e<totalPendingOrders; e++)
     {
     for(f=0; f<totalPendingOrders; f++)
      {
      if(OrderSelect(f,SELECT_BY_POS,MODE_TRADES))
        {
         Order_Type=OrderType();
         //---- pending orders only are considered
         if(Order_Type!=OP_BUY && Order_Type!=OP_SELL&& Symbol()==OrderSymbol())
           {
            //---- print selected order
            OrderPrint();
            //---- delete first pending order
            isDeleted=OrderDelete(OrderTicket());
            if(isDeleted!=TRUE) Print("LastError = ", GetLastError());
            break;
           }
        }
      else { Print( "Error when order select ", GetLastError()); break; }
     }
 


Try this:

//+------------------------------------------------------------------+
   int ordersTotal = OrdersTotal();

   //--- search in all open positions
   for (int i = ordersTotal - 1; i >= 0; i--)
   {
      //--- if an error occurs at selecting of this position then go to the next one...
      if (!OrderSelect(i, SELECT_BY_POS,MODE_TRADES)) continue;

      //--- if the position was opened not for the current symbol, skip it...
      if (OrderSymbol() != Symbol()) continue;

      if (Order_Type() == OP_BUY || Order_Type() == OP_SELL) continue;

      if(!OrderDelete(OrderTicket())) { Print("fail deleting pending order"); }
     }
  }
//+------------------------------------------------------------------+
Reason: