Setting a timeout for a function

 

Sometimes an order get executed on the server-side while my EA is on the way of processing a modify on that order. Everytime that happens it needs to wait full 3 minutes until a 'timeout' error returns, because I figure my server is simply not good on handling that.

What I need is setting a way for addressing an error if that ordersend is taking too long to execute (5 or 10 seconds). In python this could easily be done with multithreading is there a way to do something similar using mql5?


Thank you all in advance!

 
Why are you modifying an order that is about to open? Don't and problem solved.
 
William Roeder:
Why are you modifying an order that is about to open? Don't and problem solved.

Don't trade at all. Problem solved. /s


That is an issue. Consider a limit getting filled while in the process of sending in the cancel request and the entire program getting blocked by the trade server's failure to respond in a timely manner. OP, you should consider using OrderSendAsync because it will not block. 

https://www.mql5.com/en/docs/trading/ordersendasync

Documentation on MQL5: Trade Functions / OrderSendAsync
Documentation on MQL5: Trade Functions / OrderSendAsync
  • www.mql5.com
"and the mode of displaying messages in Experts log. All details are displayed by default.\r\n" //| Expert initialization function                                   | //
 
William Roeder:
Why are you modifying an order that is about to open? Don't and problem solved.

Im not modifying an order that is about to open. Im modifying an order wich I opened a while back, while I havent got response that the order closed. The server should respond right-away the order is rejected but it doesnt, it waits full 3 minutes until I get a timeout response.

 
nicholi shen:

Don't trade at all. Problem solved. /s


That is an issue. Consider a limit getting filled while in the process of sending in the cancel request and the entire program getting blocked by the trade server's failure to respond in a timely manner. OP, you should consider using OrderSendAsync because it will not block. 

https://www.mql5.com/en/docs/trading/ordersendasync

Thanks! Thats exactly what I was looking for. I didnt knew this function existed it solves lots of other problems as well.
 
example 
            datetime expiration = iTime(_Symbol,Timeframe,0) + PeriodSeconds(Timeframe);
 
Sometimes brokers freeze a pending order when they are too close to be executed... Which means you will not be allowed to modify/delete them.