this scipt only half works - delete all pending orders.

 

I got this script off this forum. I modified it a little, but basically the same and has only half worked in either case.

If i have 6 pending orders it will delete the last 3 placed. When i instigate the script again it will delete 2 more, leaving the first.

And if I run the script the 3 rd time it will delete the last pending order.

//+------------------------------------------------------------------+
//|                                               delete_pending.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"


//+------------------------------------------------------------------+
//| script "delete first pending order"                              |
//+------------------------------------------------------------------+
int start()
  {
   bool   result;
   int    cmd,total;
   
//----
   total=OrdersTotal();
//----
   for(int i=0; i<total; i++)
     {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderType() !=  OP_BUY &&  OrderType() != OP_SELL)
           {
           OrderDelete(OrderTicket());
           Sleep(1000);
           }
           
      }
      
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
if anyone can help me fix it, thx a bunch.
 
chingching wrote >>

I got this script off this forum. I modified it a little, but basically the same and has only half worked in either case.

If i have 6 pending orders it will delete the last 3 placed. When i instigate the script again it will delete 2 more, leaving the first.

And if I run the script the 3 rd time it will delete the last pending order.

if anyone can help me fix it, thx a bunch.

Change the loop so that it counts from total-1 down to 0. That should fix your problem.

- Tovan

 
tovan wrote >>

Change the loop so that it counts from total-1 down to 0. That should fix your problem.

- Tovan

hmmm,

i changed it to

 

Hello,

Your script seems to be ok but what happen if your I/O operations (SelectOrder, DeleteOrder) are not ok (return code != 0) ?

and why using : Sleep(1000);?

Reason: