How to set expiry date for pending orders?

Hi everyone. Is it possible to set a expiry date for pending orders? For instance, have your order deleted if it’s not triggered within 20 minutes?

You can delete your pending orders using OrderDelete function.

before you delete any of them you need to select them using a loop.

https://docs.mql4.com/trading/orderdelete

thank you

but how can i set the condition if the pending order wans’t executed in x duration ?

For MT4

Select the order.
See if it is still pending.
Compare the OrderOpenTime to TimeCurrent and delete if older than your 20 minutes.

Adjust for MT5.

thank you for the topic

i will try to code the fonction & i will update my result

void chekingOrders ()  

{

for(int buy=OrdersTotal()-1;buy>=0;buy++)

{

if(OrderSelect(buy,SELECT_BY_POS,MODE_TRADES))

if(OrderSymbol()==Symbol())

if(OrderMagicNumber()==magic)

if(TimeCurrent()<OrderOpenTime()+910)

;

}

}

so it’s workin i puted 910 because i run my ea on 15min timeframe

i want to correct the return fonction because i got “empty controlled statement found” error

// zikokiko , Please use " code icon " to show your code 

void chekingOrders ()  
{
for(int buy=OrdersTotal()-1;buy>=0;buy++)
{
if(OrderSelect(buy,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol())
if(OrderMagicNumber()==magic)
if(TimeCurrent()<OrderOpenTime()+910)
;
}
}
for(int buy=OrdersTotal()-1;buy>=0;buy++)  // This loop seems wrong logic . 

yes you’r right

i fix it for(int buy=OrdersTotal()-1;buy>=0;buy–)

yes you’r right

i fix it for(int buy=OrdersTotal()-1;buy>=0;buy–)