Want to delete pending orders

 

Want to delete pending orders of the particular symbol() alone(Where the EA is running)

But the code given down deletes all other pending orders.

Please give some idea to delete particular symbol's pending order alone.


int start()                                     
  {
   bool k;
        double cls;
        for(int i=0;i<OrdersTotal();i++)
          {
          k=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
          int Ticket=OrderTicket();
          if(Symbol() == OrderSymbol())
          {
          Print("Ticket = ",DoubleToStr(Ticket,0));          
          bool Ans=OrderDelete(Ticket);
          }
          }
          ObjectsDeleteAll();
          return(0);
   
  }
 
krishna_gopal_2:

Want to delete pending orders of the particular symbol() alone(Where the EA is running)

But the code given down deletes all other pending orders.

Please give some idea to delete particular symbol's pending order alone.


No it doesn't . . . the code given will only delete Pending Orders for the symbol of the chart where the EA is placed. Does your OrderSelect() work ? why aren't you testing it's return value ? does your OrderDelete work ? why aren't you testing it's return value ? why do you keep ignoring good advice ?
 
RaptorUK:
why aren't you testing it's return value ? does your OrderDelete work ? why aren't you testing it's return value ? why do you keep ignoring good advice ?


This EA is just a helping tool. While compiling the other EA's, new orders are being placed. That's why I didn't check here.

Thank you. It works.

 
You MUST count down in the presence of multiple orders especially when closing/deleting.
 
Thanks lots for your reply. It's hep me to develop my ea also.
 
int start()                                     
  {
   bool k;
        double cls;
        for(int i=0;i<OrdersTotal();i++)
          {
          k=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
          int Ticket=OrderTicket();
          Print("Ticket = ", Ticket);
          if(Symbol() == OrderSymbol())                     
          bool Ans=OrderDelete(Ticket);
          
          if(MathMod(OrderType(),2) == 0) double price = Bid;
          else if(MathMod(OrderType(),2) == 1) price = Ask;
          
          Ans = OrderClose(Ticket, OrderLots(), price, 3, NULL);
          Print("Order Type is : ", OrderType());
          Print(GetLastError());
          }
          ObjectsDeleteAll(); 
          return(0);
  }
This Code Closes and Deletes all orders of a particular Symbol.
 
krishna_gopal_2:
This Code Closes and Deletes all orders of a particular Symbol.

No it doesn't.

You MUST count down, you have already been told . . . WHRoeder read this it explains why : https://forum.mql4.com/45482#567230

Why do you try to delete the order without having first checked what type of order it is ? When doing the OrderClose you can use OrderClosePrice() instead of checking if it is a Buy or Sell.

"Does your OrderSelect() work ? why aren't you testing it's return value ? does your OrderDelete work ? why aren't you testing it's return value ? why do you keep ignoring good advice ?"

Reason: