Escape Function Order when Order Takes Too Long

 
   bool tradeAttempt=false; 
   Print("attemp "+pSybmol);
   tradeAttempt= trade.Buy(LotUsed,Sybmol,bid,0,0,comment);
   Print(tradeAttempt+" "+trade.ResultRetcode()+" "+trade.ResultRetcodeDescription());     
 

Hi everyone 

This a simple part of code that place a Buy  Market Order  that opens the trade fine.

What I wish to do is to add some safety control  that if the Order Takes over 5 seconds to return a result(executed/rejected)  the EA  automatically terminates rather than the wait for the result?  

Is there a way to terminate an operation/line/function  and/or skip to a different line if it that line of code takes tool long ?

For example

  1.  datetime  startTime=TimeCurrent();
  2.  int allowedSeconds=5;
  3.  ErrorHanlder :  If NextLine is not executed before  startTime+allowedSeconds  skip to line 5 and don't wait
  4.  bool Result=PerformOperationFunction(); 
  5.  VariousCode
 
No, that is not possible.

But you can use OrderSendAsync.


This would at least give you the opportunity to continue with the execution of your code.

Also you can set, if supported by your broker, a lifetime for your order, but I guess you are asking for the time between sending the order and receiving the confirmation of that order by the server.

If that's the case, then you have no power to interrupt this process, it is outside of your code. You need to wait for a reply and then you can remove the order, if it is invalid, or has taken to long.
 

OrderSendAsync will not give you any control after being send, exactly the same as OrderSend. 

If the orders take to long to be executed, consider changing broker. 5 seconds is crazy.

Reason: