Expert froze when pending order was executed right after order to update stop loss was send

 

Hi!

Today I experienced a freeze in my EA when updating a pending order's stop loss and I'd like to know what can I do to avoid this situation in the future.

So, by what I noticed, when we send an order to update the stop loss of a pending order, the MT5-broker system sends 4 messages like this:

DR      0       09:23:21.671    Trades  '2000312552': modify order #2715566340 buy limit 4 WINQ23 at 120080 sl: 119615 tp: 121010 -> 120080, sl: 119960 tp: 121010
KR      0       09:23:21.705    Trades  '2000312552': accepted modify order #2715566340 buy limit 4 WINQ23 at 120080 sl: 119615 tp: 121010 -> 120080, sl: 119960 tp: 121010
DG      0       09:23:21.706    Trades  '2000312552': modify order #2715566340 buy limit 4 WINQ23 at 120080 sl: 119615 tp: 121010 -> 120080, sl: 119960 tp: 121010 placed for execution (Replace received. Sending to OM)
PS      0       09:23:21.719    Trades  '2000312552': modify #2715566340 buy limit 4 WINQ23 -> price: 120080, sl: 119960, tp: 121010 done in 48.035 ms

Notice the last message, when the system returns a "done" and the duration it took for the change to be made.

So what happened was that I had a pending order in a certain price and I gave an order to update the stop loss to a different place:

KJ      0       10:09:20.708    MW MTC (WINQ23,M1)      801: ID 1: Attempting updating back stop (loss) to 120350

And the OrderSend function was called and the process to update the stop loss started, but before it finished, the pending order was executed and the EA froze:

EM      0       10:09:20.708    Trades  '2000312552': modify order #2715632433 sell stop 4 WINQ23 at 120225 sl: 120640 tp: 119395 -> 120225, sl: 120350 tp: 119395
DQ      0       10:09:20.744    Trades  '2000312552': accepted modify order #2715632433 sell stop 4 WINQ23 at 120225 sl: 120640 tp: 119395 -> 120225, sl: 120350 tp: 119395
LD      0       10:09:20.746    Trades  '2000312552': modify order #2715632433 sell stop 4 WINQ23 at 120225 sl: 120640 tp: 119395 -> 120225, sl: 120350 tp: 119395 placed for execution (Replace received. Sending to OM)
HR      0       10:09:20.774    Trades  '2000312552': deal #360358429 sell 1 WINQ23 at 120225 done (based on order #2715632433)
LP      0       10:09:20.774    Trades  '2000312552': deal #360358430 sell 1 WINQ23 at 120225 done (based on order #2715632433)
IF      0       10:09:20.775    Trades  '2000312552': deal #360358431 sell 2 WINQ23 at 120225 done (based on order #2715632433)

And after that, that last, 4th message with the time didn't reached. Fearing loosing the proper management of the position, I closed the Terminal and reopened it again (so the next line, at 10:10:03.719, is about my EAs and Indicators being closed). The impression that I have is that, if I had waited (in my experience, around 3 minutes and half), the EA would have unfrozen with an error TRADE_RETCODE_TIMEOUT .

So, how can I avoid such freeze in the futures? The only thing that come to my mind is to use Asyncronous orders, but while that may have avoided the EA's freeze, I'm not sure how should I've processed it. So, any ideas that could help in such scenarios? Regarding the code, is normal OrderSend request, tested and used for years without problems until now.

Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
  • www.mql5.com
Trade Server Return Codes - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

You should report this to your broker and MetaQuotes as a bug. Is that happening on a demo or real account ?

Asynchronous order would avoid the freeze I suppose, but I suppose you would still have the same delay to get the answer.

You could also avoid changing a pending order when the order price is too close to the market price.

 
Alain Verleyen #:

You should report this to your broker and MetaQuotes as a bug.

Gosh, OK! It seems more serious than I initially thought, then! How can I report it to MetaQuotes? I couldn't find any link for that purpose in the Terminal, nor in their website.

Alain Verleyen #:

Is that happening on a demo or real account ?

Real account.

Alain Verleyen #:

Asynchronous order would avoid the freeze I suppose, but I suppose you would still have the same delay to get the answer.

Hmm then I've the impression that I could end up making a huge change in my code only to still end up with problems, just a little minimized instead. It doesn't seem cost-benefit worth it.

Alain Verleyen #:

You could also avoid changing a pending order when the order price is too close to the market price.

That sounds like a good and practical idea, specially worth it giving that cases like this are rare. Thanks!

 
Martin Bittencourt #:

Gosh, OK! It seems more serious than I initially thought, then! How can I report it to MetaQuotes? I couldn't find any link for that purpose in the Terminal, nor in their website.

Real account.

Hmm then I've the impression that I could end up making a huge change in my code only to still end up with problems, just a little minimized instead. It doesn't seem cost-benefit worth it.

That sounds like a good and practical idea, specially worth it giving that cases like this are rare. Thanks!

You can report it here, but it needs more details, including the log with current market price, the error message, timeout...