'\end_of_program' - unbalanced left parenthesis

 
int start() /// Want to delete all pending orders
  {
   bool k;
   double cls, Lot;
   for(int i=0;i<=OrdersTotal();i++)
      {
      k=OrderSelect(i-1,SELECT_BY_POS);
      int Ticket=OrderTicket();
      Print(DoubleToStr(Ticket,3);          
      Lot=OrderLots();
      if(OrderType()==0) cls=Ask;
      else cls=Bid;
      bool Ans=OrderDelete(Ticket);
     }
return(0);
  }

I am getting such an error

'\end_of_program' - unbalanced left parenthesis ~~~~~~ Close_Orders.mq4 (53, 1)

Can any one help me?

 
  1. use /* ... */ to comment out portions of code and recompile until you isolate where.
  2.       Print(DoubleToStr(Ticket,3);          
               1           2        2  ?

 
 for(int i=0;i<=OrdersTotal();i++)
      {
      k=OrderSelect(i-1,SELECT_BY_POS);

You are OrderSelect'ing position -1 which is not acceptable.

 
if(OrderType()==0) cls=Ask;
      else cls=Bid;
      bool Ans=OrderDelete(Ticket);

you can't delete an open order ( type 0 is OP_BUY ) and if you are closing orders your loop needs to count down or you will miss orders . . .

Check return values from any functions that provide them and use them to help you, if an OrderDelete returns false report the fact to the log . . . with the relevant error

 
RaptorUK:

you can't delete an open order ( type 0 is OP_BUY ) and if you are closing orders your loop needs to count down or you will miss orders . . .

Check return values from any functions that provide them and use them to help you, if an OrderDelete returns false report the fact to the log . . . with the relevant error

Good points about the counting down and return values.

The OrderType is less certain. The comment says he wants to delete pending orders and the code does nothing useful with the OrderType test!

Clearly a test is needed for pending orders, and if anyone suggests using an OrderType > something test they will be sent to the naughty step.

 
dabbler:

if anyone suggests using an OrderType > something test they will be sent to the naughty step.

I've been there a long time . . . ;-) I've seen you mention this before . . . can you briefly explain why it's bad practice ?
 
Thank you everyone for their useful tips. The code given below works good in deleting pending orders.
      bool k;
      for(int i=0;i<=OrdersTotal();i++)
      {
      k=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      int Ticket=OrderTicket();
      Print(DoubleToStr(Ticket,0));          
      bool Ans=OrderDelete(Ticket);
      }
 
krishna_gopal_2:
Thank you everyone for their useful tips. The code given below works good in deleting pending orders.

Until something doesn't work and then you have no idea what happened . . . . check the return values from the OrderSelect and from the OrderDelete . . . if they fail report this fact and the error to the log.

And it will not work when you need to delete multiple orders . . . . you MUST count down not up in the loop . . .

And it will not only delete pending orders . . . it will delete any order . . . . and it will try to select an order that doesn't exist . . .

 
RaptorUK:

Until something doesn't work and then you have no idea what happened . . . . check the return values from the OrderSelect and from the OrderDelete . . . if they fail report this fact and the error to the log.

And it will not work when you need to delete multiple orders . . . . you MUST count down not up in the loop . . .

And it will not only delete pending orders . . . it will delete any order . . . . and it will try to select an order that doesn't exist . . .


As I told you I am new one, can you help me with this code.

I am trying an EA. While closing or removing the EA, it should delete all pending orders and close all orders opened by it.

Can you give me a code for this?

 
krishna_gopal_2:

Can you give me a code for this?

Yes I can . . . but I'm not going to. If you want to learn I'm happy to help, if you want someone to write code for you then you can simply pay someone to do it. Click here: Jobs

What I have mentioned as problems are very common problems, there are many many posts about these issues, do a little reading and you will understand the problems . . . and then be able to fix them, in the process you will have learned something. Counting down Checking return values

 
krishna_gopal_2:


As I told you I am new one, can you help me with this code.

I am trying an EA. While closing or removing the EA, it should delete all pending orders and close all orders opened by it.

Can you give me a code for this?


No One can

The EA can only close the trades the moments it is working on the chart

Reason: