multiple simultanious orders ?

 

I wonder if someone might be able to explain what exactly would occur if my EA was to generate more than one order signal on the same tick ?
The EA I'm working on uses more than one trade criteria and there can be circumstances where more than one generates an open new position signal at the same time,( by at the same time I mean during the same tick) I was wondering, for instance if 3 order signals were generated by the same tick, would my EA be able to send those orders simultanioulsy to the server or do they have to be sent one at a time after each confirmation ?
I need to know this as obviously if they were to be sent one at a time this would not work very well as a new tick could very well be recieved while the EA is waiting for the confirmation of the first order thereby wasting valuable seconds and rendering the second order bid or ask price out of date.

 
1. make your code be fast. dont do unnecessary commands that prolong execution of start().
2. if all signals execution of orders are fast enough, make them happen inside one start() execution.
3. if they are slow, theres nothing you can do. you can still put all in one sweep on start(), but the quotes may be 'old' already on the 2nd or onward signals.
 
jcadong5 wrote >>
1. make your code be fast. dont do unnecessary commands that prolong execution of start().
2. if all signals execution of orders are fast enough, make them happen inside one start() execution.
3. if they are slow, theres nothing you can do. you can still put all in one sweep on start(), but the quotes may be 'old' already on the 2nd or onward signals.


OK thanks but what I really wanted to know is, if there are multiple orders can mql4 send them all to the server at the same time or does it have to wait for the first order to be processed by the brokers server before it can send the next one ?

 
SDC:

OK thanks but what I really wanted to know is, if there are multiple orders can mql4 send them all to the server at the same time or does it have to wait for the first order to be processed by the brokers server before it can send the next one ?

The latter. Orders are placed one after the other. The OrderSend() function does not return, and EA execution does not continue, until the order has been accepted or rejected. In addition, MT4 has a single-threaded "trade context", meaning that separate EAs cannot place orders at the same time.

In your scenario with three orders per signal, the only remotely simple way of placing the orders in parallel rather than serially is (a) to run three different versions of the EA, each responsible for placing one of the three trades, and (b) to run these EAs in separate copies of MT4, all logged in to the same account.

 
hi,
if you are trading one single pair you could summarize the lotsizes of all the orders and then open one single order and then close partially.

another option is to save the ask and bid prices and every time after a ordersend() you could refresh the prices and check if they have changed.
 

Thanks everyone for replying I will have to rethink my program, I think I'll try and implement zzueggs solution and combine orders if more than one trade signal triggers on the same tick, that would work if I can still somehow manage to give that combined order a special magic number to signify it is the orders of three different criteria, my system depends on being able to do this as it involves opening orders based on several different trading criteria, and keeping track of which orders belong to which set of trading criteria, then subsequent orders are opened if profit level reaches predifined levels and then closing positions based on the individual trade criteria this system is designed to maximize profits to loss ratio because losses are confined to a single position whereas a profitable trade can eventually consist of ten positions,

 
An EA can open multiple orders in one start() call. Change the magic number each time. You just have to call RefreshRates() between each call to update Bid and Ask
 

I think I will use a global array for this, is a global array what I think it is ? Can I access it from any other function and does any new data put into it from another function appear in the global array for other functions to use too ?

 
SDC:

I think I will use a global array for this, is a global array what I think it is ? Can I access it from any other function and does any new data put into it from another function appear in the global array for other functions to use too ?

Yes. You can read about variable scope (global via local) here -> https://book.mql4.com/variables/types.

 

thanks gordon