Hi; How can i set OrderDelet for Pending Orders

 

Hi 

i m newbie on EA development 

ok ; fo pending orders my broker allow  expiration duration    after 250 min in minimum;

On my EA i want to set the pending order if wasn't executed in next 20min it will be removed ;

   how can i do that 

thank you

 
zikokiko:

Hi 

i m newbie on EA development 

ok ; fo pending orders my broker allow  expiration duration    after 250 min in minimum;

On my EA i want to set the pending order if wasn't executed in next 20min it will be removed ;

   how can i do that 

thank you

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

OrderDelete - Trade Functions - MQL4 Reference
OrderDelete - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderDelete - Trade Functions - MQL4 Reference
 

thank yu Reza nasimi

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

 
zikokiko: On my EA i want to set the pending order if wasn't executed in next 20min it will be removed ;   how can i do that 
For MT4
  1. Select the order.
  2. See if it is still pending.
  3. Compare the OrderOpenTime to TimeCurrent and delete if older than your 20 minutes.
Adjust for MT5.
 
whroeder1:
For MT4
  1. Select the order.
  2. See if it is still pending.
  3. 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

 
whroeder1:
For MT4
  1. Select the order.
  2. See if it is still pending.
  3. Compare the OrderOpenTime to TimeCurrent and delete if older than your 20 minutes.
Adjust for MT5.
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 . 
 
Yip Sin Hang:

yes you'r right 

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

Reason: