delete pending order after X bars

 

Dear all,

i try to implement a function witch delete pending orders after X minutes or better X bars.

I have found this one in this Forum and it looks good, but it does not work as desired. It deletes order not after 5 minutes, but when another order opens. Someone any idea ? and as I said, any solution with Bars i would prefer. thx a lot !

     for(int i=0;i<OrdersTotal();i++)
    {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) continue;

         int Minutes_2delete = 5;

         if (OrderType()>1 && TimeCurrent()-OrderOpenTime()>Minutes_2delete*60) OrderDelete(OrderTicket());
       
    }
 
L0rd1:

Dear all,

i try to implement a function witch delete pending orders after X minutes or better X bars.

I have found this one in this Forum and it looks good, but it does not work as desired. It deletes order not after 5 minutes, but when another order opens. Someone any idea ? and as I said, any solution with Bars i would prefer. thx a lot !

   for(int i=0;i<OrdersTotal();i++)      //Why do you count up the loop while you delete trades ???
    {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) continue; //Why not if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)break;
        int Minutes_2delete = 5;
        if (OrderType()>1 && TimeCurrent()-OrderOpenTime()>Minutes_2delete*60) OrderDelete(OrderTicket())   
    }

you do not selecting OrderMagicNumber()   

 you do not selecting the Symbol()                 So it will mess with other pendingtrades on your account


How do you come thinking  It deletes order not after 5 minutes, but when another order opens. 

 

 and as I said, any solution with Bars i would prefer. 

 

if (OrderType()>1 && OrderOpenTime() < Time[5]) OrderDelete(OrderTicket()) 

 Check this   topic    https://www.mql5.com/en/forum/139654

Reason: