Deleting Pending Orders

 
Hello,
How is everybody doing?
This is my first post in this forum. I believe that this forum has helpful people.
Will somebody help me with the following code, please?
void CloseOrders()
{
int total;
total = OrdersTotal();
for(int a = 0;a < total; a ++)
{
OrderSelect(a, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUYSTOP && OrderType()==OP_SELLSTOP)
OrderClose(OrderTicket(), OrderLots(), Bid, 3,Violet);
OrderClose(OrderTicket(), OrderLots(), Ask, 3,Violet);
}
}
}
I know this code is simple for experts.
I need to close the second pending order when the first pending order is hit.
Thank You a lot.
 
void CloseOrders()
{
  int total = OrdersTotal();
  for (int a = total-1; a >= 0; a--)
  {
    if (!OrderSelect(a, SELECT_BY_POS, MODE_TRADES)) continue;
    if (OrderSymbol() != Symbol()) continue;
 
    if (OrderType() == OP_BUY)
      OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
 
    if (OrderType() == OP_SELL)
      OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);
  }
}