Wrong "reverse order" execution in MT5

Hello,



After several test I found that there is error during execution of market reverse order in MT5: in live test (not in backtest) if the strategy receive an opposite signal, instead to close and open immediately a new order in the other direction it only close the order and the new position is opened in the next bar (if the signal is still valid).
The error is not happening every time, I didn't understand the reason; in log is not present any error execution when this problem happen.


I'm attaching a simple strategy that open long if MA is rising and reverse if MA is falling, screenshot that compare its execution in backtest and in live (you can see the difference) and log.

Attachments
prova.mq5
(195.81 KiB)
MA reverse log.log
(13.41 KiB)
Market Reverse Wrong Execution.png
(52.62 KiB)
  • Votes +5
  • Project StrategyQuant X
  • Type Bug
  • Status Fixed
  • Priority Normal

History

SL
#1

Morningbull

20.06.2020 19:51

Task created

SL
#2

Morningbull

20.06.2020 19:51
Voted for this task.
h
#3

hankeys

21.06.2020 09:03
Voted for this task.
Dw
#4

Diwi

22.06.2020 11:26
Voted for this task.
TB
#5

Tomas Brynda

24.06.2020 21:22

Status changed from New to Waiting for information

Hi Morningbull,

from the screenshot it seems to me that something is wrong here. 

It looks like there are multiple strategies trading simultaneously.


Are you sure there is only one strategy attached? 

Also there could be a problem with magicnumbers. Please check that every one of your strategies has a unique magic number.


Let me know if it helped.


Best regards,

Tomas

E
#6

Emmanuel

25.06.2020 08:22
Voted for this task.
SL
#7

Morningbull

25.06.2020 20:56
Hello Tomas,


No nothing about that, in the screenshot you see two times every order because it is the result from the backtest and the result from live trading in demo account. I discovered that MT5 keep track of both of them in the same chart.

The magic number is for sure unique, and also I tested several type of strategies with market reverse and in all of them I found the same problem, you can just put it in demo account in M1 chart and in few hours you will see the problem.

o
#8

Enric

26.06.2020 07:32
Voted for this task.
TB
#9

Tomas Brynda

29.06.2020 09:07

Status changed from Waiting for information to In progress

TB
#10

Tomas Brynda

30.06.2020 10:13

Status changed from In progress to Refused

Hi Morningbull,

we have tested it with my colleagues live on a demo account. We tried both netting and hedging account and different brokers.

Unfortunately we were unable to simulate the issue described here. 

In all cases the strategy was trading as it is supposed to do, so we think this problem is broker-related.



Best regards,

Tomas

SL
#11

Morningbull

30.06.2020 11:10

Hello,


My broker is Admiral Market, it is very common broker used from a lot of user.

Many people also voted for this this bug, I think it should be solved in some way.

I will try with another broker and I will let you now.

SL
#12

Morningbull

01.07.2020 20:36
Hi Tomas,


I made some test with another broker and you are right, the problem is broker-related, it didn't happen with this other broker, I have not idea why it happen only with Admiral Market

I will try to contact them and ask for explanation, sorry for the time lost.


Regards



TB
#13

Tomas Brynda

02.07.2020 07:28
Hi Morningbull,

thank you for your feedback. Please let me know how do they explain this behavior.


Best regards,

Tomas

SL
#14

Morningbull

10.07.2020 23:11

Attachment Capture_1.png added

Attachment Capture_2.png added

Attachment Capture_3.png added

Capture_1.png
(66.67 KiB)
Capture_2.png
(58.36 KiB)
Capture_3.png
(48.23 KiB)
Hello Tomas,


I made some check on tthe EA code and I found the problem: despite the order is already closed, when the EA " check if live order exists", the bool sqSelectPosition return true (see Capture_1).

I checked inside bool sqSelectPosition and if I Print(PositionsTotal()), despite the position is closed and I don't have other positions opened it return 1, like if the position is still opened (see Capture_2).

When I added one Sleep(500) before to count the total positions opened (see Capture_3), the EA worked fine, every order were closed and the opposite opened in the same bar.

Probably it is caused from some broker server delay (I'm using Admiral Market) that is not able to update the information immediately after close the position.

For sure the sleep function is not the best idea to solve the problem, I think you will find some better solution, even because Admiral Market is a very common broker and a lot of user voted for this problem.

I'm waiting for your considerations.


Regards

TB
#15

Tomas Brynda

21.07.2020 15:18

Status changed from Refused to Fixed

Hi MorningBull,

we have decided to add a special internal variable called orderSelectTimeout to the MQL code.

By setting this variable to a non-zero value, a sleep interval will be used at various places in the code so it should fix the problem.


We don't want to set this variable as extern, because most users won't use it and we don't want to further complicate the EA settings which contain a lot of parameters already.

It will be available in the next release.


Thank you for debugging this issue.


Best regards,

Tomas

SL
#16

Morningbull

21.07.2020 17:35
No problem, thanks for your help!


Regards


Votes: +5

Drop files to upload

or

choose files

Max size: 5MB

Not allowed: exe, msi, application, reg, php, js, htaccess, htpasswd, gitignore

...
Wait please