MT5 Netting Execution Bug

See attached images for explanation of bug. As talked about in SQ Extension/Programming this morning.

Attachments
image-2.png
(17.56 KiB)
image-3.png
(16.13 KiB)
image-1.png
(19.58 KiB)
image-0.png
(78.81 KiB)
  • Votes +10
  • Project StrategyQuant X
  • Type Bug
  • Status Fixed
  • Priority Normal

History

KB
#1

kbtech

26.10.2022 16:55

Task created

KB
#2

kbtech

26.10.2022 16:58

Attachment M15 LONG.mq5 added

Attachment M15 Short.mq5 added

M15 Short.mq5
(234.05 KiB)
M15 LONG.mq5
(234.04 KiB)
I don't want to publicly share my personal strategies live. But I have attached 2 strategies which are simpler and I have tested to still have the bug. (Though if you need my strategies I can privately email support with them)

These strategies execute on a M15 Timeframe both need to be the same symbol.
Long at 0 min, Exit at 30 min
Short at 15 min, Exit at 45 min
KB
#3

kbtech

26.10.2022 17:00
Voted for this task.
Fs
#4

Fortunate

26.10.2022 17:10
Voted for this task.
KB
#5

kbtech

26.10.2022 17:31
Expected Results:

Deals | Direction | Type | (Cumulative Contracts)
+1 Buy Enter (+1)
-1 Sell Enter (0)
-1 Buy Exit (-1)
+1 Sell Exit (0)
KB
#6

kbtech

26.10.2022 17:44
I used AMP Futures MT5 Netting can get a demo account here: https://downloads.ampfutures.com/meta-trader-5-mt5
CG
#7

Chris G

26.10.2022 18:28
Voted for this task.
k
#8

Karish

26.10.2022 18:37
Voted for this task.
Dw
#9

Diwi

26.10.2022 21:51
Voted for this task.
E
#10

Emmanuel

28.10.2022 12:59
Voted for this task.
b
#11

bentra

04.11.2022 02:35
Voted for this task.
KB
#12

Kevin

04.11.2022 05:36
Voted for this task.
g
#13

Lee Guan Chuan

08.11.2022 08:47

Status changed from New to In progress

Hi kbtech, 


Unfortunately, this is a known problem with the MT5 netting account. When you run multiple EA in one account when there is 1 buy and 1 sell order from 2 different EAs. It will net out the trade eventually. 

https://www.mql5.com/en/forum/372599


The close position function in SQX will always detect if there is an existing trade only it will perform a close position when the "Long exit" or "Short exit" signal happens.


There are 2 methods to do this

  1. Separate the EA into 2 different accounts
  2. Perform short entry to exit a long trade, perform long entry to exit a short trade


For method 1, you can apply the existing EA to multiple accounts. However, method 2 will be slightly complicated. I will make some explanation over here.


First, you need to remove the condition, Market Position (Any, Magic Number, " ") is Long or Short. This is because the trade has been closed by the other trade. You couldn't detect whether the trade was long or short anymore. 
Second, you need to add a boolean parameter to track whether you have entered trade or not. So in your entry tab, you need to assign "True" to this variable. You can use this parameter to keep track you have open trade or not. Remember this parameter will reset to default when you restart your strategy.  If you have long and short in 1 strategy, you might need to add 2 parameters to keep track of both.
Third, you can use the second step parameter to detect whether you have open trade or not. If you have open trade, you can perform the exit signal.
Fourth, the close position will detect if there is an active order and perform the close. However, in your scenario, there is no active order. You can use the "EnterAtMarket" block to exit the trade. So, when you have an active long order, you can perform a Short "EnterAtMarket" to exit your long order or a Long "EnterAtMarket" to exit your short order.


I understand that this scenario is complicated. However, when we ran multiple EA in a netting MT5 account,  the MT5 netted the trades which made us unable to track all the open trades. Therefore, it required us to take extra steps in the strategy to track every single trade.



Thank you.

g
#14

Lee Guan Chuan

08.11.2022 10:24

Status changed from In progress to Fixed

IN
#15

altenburg90

08.11.2022 10:54
Voted for this task.
KB
#16

kbtech

08.11.2022 17:31
Thank you for that excellent response & explanation. I think for now I will do method 1 and use sub accounts. But for the mid-term I will look to move to TradeStation which as far as I know has support for long and short on the same account.

Votes: +10

Drop files to upload

or

choose files

Max size: 5MB

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

...
Wait please