MT4 ‘Trade Context is Busy’ protection

I think it would be useful for the MT4 code to include protection from the 'Trade Context is Busy' error when 2 or more robots try to execute orders
Attachments
No attachments
  • Votes +5
  • Project StrategyQuant X
  • Type Feature
  • Status Archived
  • Priority Normal
  • Assignee None
  • Milestone Archived (To be done later)

History

Rr
#1

Partizanas

30.12.2018 17:06

Task created

Rr
#2

Partizanas

30.12.2018 17:07
Voted for this task.
g
#3

geektrader

30.12.2018 19:22
MT4 handles up to 8 orders at once since a few years already. So you will only get trade context is busy if 8 EAs at once try to open / close an order at the exact same second (not if they just run at the same time). Also, the order handling of SQX for MT4 is solid, as they use a extra industry-strength library for it. I never had a trade context is busy error with it yet. Did you? Or what exactly is the reason you are requesting this?
Rr
#4

Partizanas

30.12.2018 20:11
when i run 50 EA's and thenIt occurs quite often that are thrown specified error


g
#5

geektrader

30.12.2018 21:26
That might be the case, but SQX will try to resend the order right away, that´s handled by that industry strength order handling library. Anyhow, you might want to consider using several MT4 instances. I never run more than 8 EAs per MT4, simply because of that reason. Because even if it tries to resend / would wait if the context is busy until it is free, it means your trades will not get the entry price the strategy wanted to have and that also means that your live trades won´t match the backtest, etc. 
g
#6

geektrader

30.12.2018 21:29
Voted for this task.
t
#7

tnickel

02.01.2019 07:02
Voted for this task.
o
#8

Enric

09.01.2019 22:22
Voted for this task.
o
#9

Enric

09.01.2019 22:32

The ideal solution would be merging EA's designed on the same pair and timeframe in an only EA, each of the individuals with its own MagicNumber of course. This way the orders wouldn't execute in parallel. I have more than 30 EA's running on a same terminal and I have to edit the 30 MQ4 files 'sleeping' Orders to avoid this issue (so far it works), there was a post on the Forum BTW.

Also, there's a Feature request to merge several EA's in one:

https://roadmap.strategyquant.com/tasks/sq4_1794


m
#10

mabi

10.01.2019 02:56

Guy,s aint this already implemented.  Retry attempts is by default set to 10 in each strategy with an sleep time.  This can be edited.  Also most strategies found is with limit or stop orders so this delay has no impact on performance for that type of strategy in regards to back test results. I run more then 30 SQx strategies with no problem.  There have been reported a problem with Exit on Fridays if You have 100 strategies or so  since all want to exit at the same time some might not make it.


int  retry_attempts   = 10;
double  sleep_time    = 8.0;
double  sleep_maximum   = 25.0;


g
#11

geektrader

10.01.2019 07:26
However you bend it, you will NOT get the entry price the EA wanted if there are more than 8 orders that need to be executed at once. This is also the case with Enric´s idea, even if many strategies are merged into on MQ4 file, they can only be executed serially! So if you have 30 strategies in there and assuming your broker takes 500ms to execute one order, it will take 15 seconds until the last EA in the MQ4 code was able to place its trade and hence will be (during news or London / New York hours) most likely very far away from the entry price it really wanted / the backtest in SQX would show. This basically ruins your strategies logic/coherence to the SQX / MT4 backtest and can make it trade completely different to what it should be (hence converting a good strategy to a completely failing one). The only way around this, as mentioned, is to use a max of 8 EAs per MT4 instance and simply run many MT4 instances.
h
#12

hankeys

10.01.2019 08:11

Attachment EU_15_11151532_S_HA_CF_A_F_Ba_BE_EQ___BTvsREAL.png added

this is not a problem of entry price, because we are talking mainly of STOP and LIMIT orders, and prices are computed from history and so the price will not change with another tick in the future. Price for STOP and LIMIT order will remain the same.


With SQ3 we need to program our MQL code to trade 100 EAs in one MT, with SQX the problem was solved - feel free fo trade 100 EAS in 1 MT :)


i think that i know what talking about, because i am running 1000+ strs on demo acc - and making comparation of backtests - the problem lies elsewhere

o
#13

Enric

11.01.2019 09:07

Indeed, if your EAs are sending Stop/Limit Orders (my case) shouldn't have problems sleeping Orders when you SEND them. The problem will come when you CLOSE them because normally the Close is at Market price (except for StopLoss or TakeProfit). Anyway, I don't see any other solution than seriallizing the Orders to avoid several MT4 terminals running which makes my VPS too expensive.

I haven't checked yet if EAs coming from SQX solve us to mess with MQ4 code as mabi said. I wish it works!

h
#14

hankeys

11.01.2019 12:02
how many times will be close at the same bar (tick)? this is not a big problem
g
#15

geektrader

11.01.2019 23:53
My above warning was talking about market orders, as most of my strategies enter this way. For limit / stop orders it will not really matter if they go into the market with a little delay, except if there are news right at the bar open which might fill the order right away, then it will matter too.
TM
#16

tmatejka.

21.03.2019 08:24
Voted for this task.
MF
#17

Mark Fric

16.02.2020 13:52

Status changed from New to Archived


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