How to code a routine to handle a Trade timeout error?

 

Anyone know how to handle an order that has been accepted by the server but failed to be executed?

The broker's server has actually given the impression that the trade was accepted!

5:10:00 'XXXXXXX': instant order buy 0.10 EURUSD at 1.42253 sl: 1.41553 tp: 1.42953
15:10:00 'XXXXXXX': request was accepted by server
15:10:00 'XXXXXXX': request in process
15:10:01 'XXXXXXX': order was opened : #1176380 buy 0.10 EURUSD at 1.42253 sl: 1.41553 tp: 1.42953
20:35:00 'XXXXXXX': instant order buy 0.10 EURUSD at 1.42521 sl: 1.41821 tp: 1.43221
20:35:00 'XXXXXXX': request was accepted by server
20:38:18 'XXXXXXX': order buy 0.10 EURUSD opening at 1.42521 sl: 1.41821 tp: 1.43221 failed [Trade timeout]

 
ronaldosim wrote >>

Anyone know how to handle an order that has been accepted by the server but failed to be executed?

The broker's server has actually given the impression that the trade was accepted!

5:10:00 'XXXXXXX': instant order buy 0.10 EURUSD at 1.42253 sl: 1.41553 tp: 1.42953
15:10:00 'XXXXXXX': request was accepted by server
15:10:00 'XXXXXXX': request in process
15:10:01 'XXXXXXX': order was opened : #1176380 buy 0.10 EURUSD at 1.42253 sl: 1.41553 tp: 1.42953
20:35:00 'XXXXXXX': instant order buy 0.10 EURUSD at 1.42521 sl: 1.41821 tp: 1.43221
20:35:00 'XXXXXXX': request was accepted by server
20:38:18 'XXXXXXX': order buy 0.10 EURUSD opening at 1.42521 sl: 1.41821 tp: 1.43221 failed [Trade timeout]

Noticed that you are told of that error 3 mins 18 secs later - compared to an off quotes or requote error which is immediate

08:25:04 'XXXXXXX': instant order buy 0.10 EURUSD at 1.41946 sl: 1.41246 tp: 1.42646
08:25:04 'XXXXXXX': request was accepted by server
08:25:04 'XXXXXXX': request in process
08:25:04 'XXXXXXX': order buy 0.10 EURUSD opening at 1.41946 sl: 1.41246 tp: 1.42646 failed [Off quotes]

 
ronaldosim:

Anyone know how to handle an order that has been accepted by the server but failed to be executed?

The broker's server has actually given the impression that the trade was accepted!

Personally, I've never seen a situtation where OrderSend() returns a valid ticket number but the order hasn't in fact been executed. The potential problem with ERR_TRADE_TIMEOUT is more when an order is reported as failing, and OrderSend() returns 0, but the broker does in fact accept and place the order. Lots of the code posted on this site effectively ignores the ticket returned by OrderSend(), and instead repeatedly reads the trade list - which is fine. But if your code does rely on the return value from OrderSend(), then there's no alternative to doing a periodic scan of the trade list to make sure that there aren't any orders which the code thinks have failed.

 

If the Ticket Number you got is not equal to zero then your order is open with that ticket number.
 
Jacques366 wrote >>
If the Ticket Number you got is not equal to zero then your order is open with that ticket number.

Does this means that the EA will wait (in this case 3mins 18 secs ) for the ticket no to be returned ? Let's say the code is like this

int ticket = OrderSend(.....);

if (ticket<0) error routine // so this does not get executed until 3 mins 18 secs later when the server returned the Trade Timeout Error?

 
ronaldosim:

Does this means that the EA will wait (in this case 3mins 18 secs ) for the ticket no to be returned ? 

In my experience, yes. I have seen very substantial delays on OrderSend() before a timeout error is finally returned.

 
jjc wrote >>

In my experience, yes. I have seen very substantial delays on OrderSend() before a timeout error is finally returned.

jjc/ thank you for sharing this; I know how to code the routine to handle this error now.

 

Strongly suggest all readers look here https://www.mql5.com/en/forum/45549 to see what Slawa, a MetaQuotes moderator has to say about this thread's chat.

In essence, is better to be pessimistic and code for worst case, yes?

All the drudge work can be shoved into a function so that is only a few calls...

I respectively understand/acknowledge what has been posted above, however, the stated experience's may prove correct most times yet if there is the slightest possibility of ERR_TRADE_TIMEOUT and 142,143 then is it not better to have safety net?

fwiw

 
fbj wrote >>

Strongly suggest all readers look here https://www.mql5.com/en/forum/45549 to see what Slawa, a MetaQuotes moderator has to say about this thread's chat.

In essence, is better to be pessimistic and code for worst case, yes?

All the drudge work can be shoved into a function so that is only a few calls...

I respectively understand/acknowledge what has been posted above, however, the stated experience's may prove correct most times yet if there is the slightest possibility of ERR_TRADE_TIMEOUT and 142,143 then is it not better to have safety net?

fwiw

Ah, this is interesting. if due to some problems (network or otherwise), the client terminal will generate a timeout so that the client terminal will not wait forever which is 3 mins 18 secs for my case cos it is always this timing. And this deepens a conspiracy theory - the broker server refused to give an answer - to delay the number of repeated request to itself because other errors like requotes, off quotes are immediate (within 1 sec) but trade timeout is just simply no answer resulting in a long wait (3mins 18 secs for my case), delaying this long so that my repeat request will be quite way off if it ever get to be executed. oh my, now I know better why EA performs well in demo but poorly in live trading. And the trick is to avoid strategies that have trades execution sequence that are dependent on the previous.

 

Well, after such a potentially long time from original trade decision - seems maybe better to just abort that sequence. Always more trades around the corner!

Dependancies are always going to be risky. Probably more involved too, which usually means more code with more areas needing close attention regards error handling etc.

I admit to having error handler that deals with all published errors. But mainly, in such 'unreal situations' it just politely tells caller to 'take a flying leap' - why bother iow. Worst case, close ALL EA owned orders, call init() and start afresh! or forget about life and call deinit() to abort EA!

man... is suuuch a game and always a fragile co-existence between coder,EA,CT and Broker...

.

I read post by BB about some of his EA's - I must admit to considering the stopping messing around with ClickBank refundable "the next best 'n greatest Robot" offerings. I always get refunds and they never produce anything worth the mention... except headaches and much lost time!

I have my own code but the multiple income streams concept is very appealing.

Any code that consistently pays for itself with some extra income thrown in, even if apparently small compared to one's dreams?, must be worthy of consideration.

http://www.selectfx.net/zr_eurcad.htm

.

Think I'll apply for a discount!!!