Function to delete pending orders :

Code:
//----------------------------------------------------- delete

int del(int type){
   int total=OrdersTotal();
   bool res=false;
   for(int x=total-1;x>=0;x--){
      if(OrderSelect(x,SELECT_BY_POS,MODE_TRADES)==true){
            if(OrderSymbol()==Symbol())
               if(OrderMagicNumber()==Magic){
                  if(OrderType()==OP_SELLSTOP && OrderType()==type){
                     res=OrderDelete(OrderTicket(),clrNONE);
                  }
                  if(OrderType()==OP_BUYSTOP && OrderType()==type){
                     res=OrderDelete(OrderTicket(),clrNONE);
               }
                  if(OrderType()==OP_SELLLIMIT && OrderType()==type){
                     res=OrderDelete(OrderTicket(),clrNONE);
               }
                  if(OrderType()==OP_BUYLIMIT && OrderType()==type){
                     res=OrderDelete(OrderTicket(),clrNONE);
               }
            }
      }
   }
   return(0);
}