Minor bug when generating mql5 code (details inside)

Hi again

if  (Market position is not long) block is used in strategyquant x and then same strategy tested on MT5, the strategy will open new long trades in mt5 even though in sqx it didn't because block (Market position is not long) was used.



same thing for (Market position is not short)


in MT4 it works perfectly and results match the one in sqx, problem is with MT5.


The strategy is not supposed to open long position if there was already a long position running, in SQX and MT4 this works perfectly and no other long position is opened if there was an existing long position, but in MT5 it open another long position even though there was an open long position running.  Vice versa for short positions.


So I took a look inside the mql5 code and found why this is happening.


In MT5, OrdersTotal() returns number of pending orders, where OrdersTotal() in MT4 return number of both market and pending orders.


https://www.mql5.com/en/docs/trading/orderstotal



in MT5, sqMarketPositionIsNotLong() returns (true) all the time because obviously there were no pending orders




Fix is very easy:
in line 3170 of the mql5 code for the strategy attached below, function sqSelectOrder is used inside sqMarketPositionIsNotLong() function, instead change it to sqSelectPosition function, and leave the parameters of the function the same.


do the same thing inside sqMarketPositionIsNotShort().


And it works perfectly for me in MT5, results are exactly the same results I got in SQX


hope this gets fixed in next build
thanks



Attachments
strat_sqx.sqx
(27.82 KiB)
  • Votes +1
  • Project StrategyQuant X
  • Type Bug
  • Status Fixed
  • Priority Normal

History

SR
#1

SixtoRod

19.08.2021 10:59

Task created

h
#2

hankeys

20.08.2021 06:46
Voted for this task.
TT
#3

Tamas

08.09.2022 14:08

Status changed from New to Fixed

Already fixed in SQX 136 Dev4

Votes: +1

Drop files to upload

or

choose files

Max size: 5MB

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

...
Wait please