Download MetaTrader 5

simultaneous processing of multiple order tickets?

To add comments, please log in or register
Jon Grah
387
Jon Grah  

Can asynchronous order tickets be processed at the same time? Meaning can I make a trade open/modify/close request #2,3,4, etc without waiting for confirmation from request #1.


"MT4 does process multiple orders at the same time and this change was made during a relatively recent update by Metaquotes ( around build 500)."

If this is true, are there special functions to handle processing multiple orders without getting "trade context busy"?

Simon Gniadkowski
Moderator
18036
Simon Gniadkowski  
Not from the same EA, you can have one EA open an Order while another is closing and Order and a third is modifying an Order, etc.
Jon Grah
387
Jon Grah  

So if one ea #1 is managing 10 trades, and I wish to close all 10 trades immediately, Ea #1 must close each ticket individually, waiting for confirmation from close #1 before close #2 can begin closing, close #2 to confirm closing before close #3 begin closing, etc?

what was the purpose of MQ design order flow this way? Is there a method to get around this? I don't think I could divide up the closeAll into 3-5 separate EAs on separate charts. The EA is supposed to take care of everything, or one EA could place the orders, and another EA could initiate closeAll.

Simon Gniadkowski
Moderator
18036
Simon Gniadkowski  
4evermaat:

So if one ea #1 is managing 10 trades, and I wish to close all 10 trades immediately, Ea #1 must close each ticket individually, waiting for confirmation from close #1 before close #2 can begin closing, close #2 to confirm closing before close #3 begin closing, etc?

Yes, correct.

4evermaat:

what was the purpose of MQ design order flow this way? Is there a method to get around this? I don't think I could divide up the closeAll into 3-5 separate EAs on separate charts. The EA is supposed to take care of everything, or one EA could place the orders, and another EA could initiate closeAll.

You will have to ask MQ why they did it that way. If you want to close Orders simultaneously and it is that important to you then you will have to have separate Close EAs, you can have upto 8 trading threads so you could have 7 additional Close EAs and communicate the ticket they need to close using GVs. When the CloseEA has closed it's assigned trade it would reset the GV back to 0 so it doesn't keep attempting to close the Order it just closed.
Rashid Umarov
Admin
12662
Rashid Umarov  
I think all should read again some articles from search https://www.mql4.com/search#!keyword=magicNumber&module=mql4_module_articles
Hatem Abou Ouf
1015
Hatem Abou Ouf  
Rashid Umarov:
I think all should read again some articles from search https://www.mql4.com/search#!keyword=magicNumber&module=mql4_module_articles

You mean we can use the magic number to achieve this simultaneous order opening/ closing ? However, cTrader has this asynchronous order processing.

I have a question here, to achieve this in MT4, we need multiple EAs ( communicating using GVs) on different charts on the same MT4 instance. Or we need multiple MT4 instances to be opened, each has an EA?

Rashid Umarov
Admin
12662
Rashid Umarov  
Hatem Abou Ouf:

I have a question here, to achieve this in MT4,

Sorry, can you clarify your question?
Alain Verleyen
Moderator
33486
Alain Verleyen  
nicholishen:

What do magic numbers have to do with asynchronous orders?

Nothing, Rashid probably misunderstood.
Alain Verleyen
Moderator
33486
Alain Verleyen  
Hatem Abou Ouf:

You mean we can use the magic number to achieve this simultaneous order opening/ closing ? However, cTrader has this asynchronous order processing.

I have a question here, to achieve this in MT4, we need multiple EAs ( communicating using GVs) on different charts on the same MT4 instance. Or we need multiple MT4 instances to be opened, each has an EA?

Compared what can be compared, MT4 is an old software. Compare cTrader to MT5, will be a different story.

Yes with MT4 you can do it with multiple EAs on 1 MT4 instance.

Alain Verleyen
Moderator
33486
Alain Verleyen  
nicholishen:

Thanks to this thread I finally understand the use-case for OrderCloseBy! :) 

So instead of asynchronous orders to close, you...

  1. send a hedge order in so your net position = 0, effectively closing all positions at once.
  2. loop through the remaining orders taking your sweet time and use OrderCloseBy.

I have no idea why this isn't talked about more... Here's a quick and dirty script for an alternative to asynchronous-close-orders:


Not sure why you think this has anything to do with an "alternative" to asynchronous orders. Each OrderCloseBy() will still be synchronous.

Your proposal could be discussed but is totally off-topic here.

Fernando Carreiro
2949
Fernando Carreiro  
nicholishen: Thanks to this thread I finally understand the use-case for OrderCloseBy! :) 

So instead of asynchronous orders to close, you...

  1. send a hedge order in so your net position = 0, effectively closing all positions at once.
  2. loop through the remaining orders taking your sweet time and use OrderCloseBy.

I have no idea why this isn't talked about more... Here's a quick and dirty script for an alternative to asynchronous-close-orders:

Although I do believe you may be onto a good idea here, I am somewhat uncertain of its impact on the trading costs as the opposite "Hedge" order is in equal volume as the total of all currently open orders, so you would effectively be doubling your trading costs (spread and commission).

I've never used the OrderCloseBy() function but I do vaguely remember someone stating on the forum that it did save on trading costs but I am not too sure on the specifics and the documentation is not too clear on that either.

How were your tests in this regard? Did you monitor that aspect of the spread and commission impact of the "hedge" order followed by all the subsequent OrderCloseBy() calls?

PS! Also please note that such a solution would not work for the US traders due to the "hedging" and FIFO rules (well, maybe the FIFO rules is not exactly a problem, but the "hedging" would be).

EDIT: Found the forum post I mentioned and so added the link above!

OrderCloseBy - Trade Functions - MQL4 Reference
OrderCloseBy - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderCloseBy - Trade Functions - MQL4 Reference
123
To add comments, please log in or register