Question on Handling of ERR_TRADE_TIMEOUT and knowing IF tradeOp fails or succeeds

 

Hi All,


Docs state:

Any trading operation (functions of OrderSend(), OrderClose, OrderCloseBy, OrderDelete or OrderModify) can fail, for a number of reasons, and return either negative ticket number or FALSE. One can find out about the reason for fail by calling of the GetLastError() function. Every error must be processed in a special way. The most common recommendations are given below.


Docs state:

Timeout for the trade has been reached. Before retry (at least, in 1-minute time), it is necessary to make sure that trading operation has not really succeeded (a new position has not been opened, or the existing order has not been modified or deleted, or the existing position has not been closed)


IF OrderSend() returns -1 //docsRef: Returns number of the ticket assigned to the order by the trade server or -1 if it fails

AND GetLastError() returns ERR_TRADE_TIMEOUT

THEN just how does one determine if order has been accepted by trade server?


Following a Sleep(xxx); to allow server/terminal time to sort selves out, I would presumably search trade pool for an order having the unique magic# used in OrderSend(), yes?

If so, then with luck the order will be mapped and ticket# obtained, yes?


If Sleep(xxx); not long enough and trading context is ok etc., would another Sleep(); be good idea?


OR what should one look for to indicate that no, the position was not opened/modified/deleted/closed and stop retry loops etc.

Below, are other funcs() which I think have way to deal with this timeout - but maybe not

But again - just how long does one keep trying to verify success or failure?

To reissue OrderSend() without confirming that previous call failed, seems at best risky...

It is this verify thingy that I need help with!!!


If OrderModify(..newSL..); issued and get timeout error and do a Sleep(xxx); and then map order pool entry to see if newSL was in order data - I can understand that this is SUCCESS modify.

Likewise, OrderClose() is simple enough to check orders closeTime!=0 datum, yes?

And, OrderDelete() again will be in history pool (with closeTime!=0), yes?


If above is the basic method to handle all possibilities regarding timeout error, I'd be interested to hear your feedback/suggestions/refinements.


Thanks

 

Thank you phy - will get there properally in a.m. and digest the source code. First glance has given me something to muse over in dream time :)


Ok then, is next morning and have inspected code but... held nothing new and ignores over half of documented tradeOp errors including timeout.


Anyway, for me the code is overly complicated - I grew up on single function concept - makes for easier life in all departments - hahaaa, especially when at many bodied code review and [of course] everybody is out to shoot you down given any excuse... and complication means subjectivity means hard to avoid all the lead flyin your way :)


BUT interesting to see code! To give code due diligence is only fair and it is this area that I find very time consuming! [for me] gotta dig down to bare metal to see warts 'n all :))

Regardless, I find reading [ummm, most] code is always instructive - if for no other reason than to reaffirm that [perhaps] one's own techniques are not so bad after all - :))


Almost 30 possible trading exe errors and if doc'd my errorHandler() is gonna bite the bullet and deal with 'em.

Then of course is the other 60 or so doc'd errors... oh merde!!!


I have finalised on timeout handling - just want to make generic enough so that can migrate to any situations etc. until/hopefully MT gets self sorted out and offers sensible error handling I/F...


My thinking is that OrderSend(), OrderClose, OrderCloseBy, OrderDelete or OrderModify are to be treated each as individual special cases and will have callable wrapper for each, where all the particular trade function's special requirements can be dealt with and the retry environment needed according to how I hack response to deal with this crazy MT doc statement:


Timeout for the trade has been reached. Before retry (at least, in 1-minute time), it is necessary to make sure that trading operation has not really succeeded (a new position has not been opened, or the existing order has not been modified or deleted, or the existing position has not been closed)


I reiterate that imho is not EA responsibility to deal with timeout - terminal should inform Y/N full stop and additonally, since [I believe] server is their design too, that a simple [and massively easy-to-implement] backout mechanism should be imployed so that terminal can inform Y/N... [course only my opinions/desires...]


I posted in https://www.mql5.com/en/forum/107848 regarding my concerns and well... I do not expect an answer any time soon :((


My ultimate functionality is to just die gracefully and when it is noticed that EA effectively dead, start the usual manual knife 'n fork process.


Again, great links!!! - am gonna subscribe to forum etc.


You got any other links which you think are worthy - please dooo share!