Question on Events during OrderSend()

 

Dears,

If I call OrderSend(..) will the order only be queued, or does the function return only upon (un-) successful Order-execution?

Is there any possibility that  "onTick() Events"  will arrive, while the SendOrder execution is running, e.g. if the order is only queued, Tick Events could arrive between the OrderSend call and the confirmation of the Server.


Best Regards

hk.

 

lve0200:

If I call OrderSend(..) will the order only be queued, or does the function return only upon (un-) successful Order-execution?

Is there any possibility that  "onTick() Events"  will arrive, while the SendOrder execution is running, e.g. if the order is only queued, Tick Events could arrive between the OrderSend call and the confirmation of the Server.


In MT4:

There is no OnTrade() event. Rather, the EA will wait for the result of the order execution, which is most likely performed under an OnTick() event. And since subsequent ticks are ignored while a given tick is still being processed, no new ticks will be processed from order sending until the actual confirmation from the server.

In MT5:

From https://www.mql5.com/en/docs/basis/function/events#ontrade

"Users must independently implement in the code the verification of a trade account state when such an event is received (if this is required by the trade strategy conditions). If the OrderSend() function call has been completed successfully and returned a value of true, this means that the trading server has put the order into the queue for execution and assigned a ticket number to it. As soon as the server processes this order, the Trade event will be generated. And if a user remembers the ticket value, he/she will be able to find out what happened to the order using this value during OnTrade() event handling."

So, yes, the orders will be queued, but on the server. The next tick processing will occur as soon as a new tick arrives right after processing the current tick. So there is a possibility, depending on your server, that OnTick() gets invoked first before the server returns a trade result, which is processed under OnTrade()

Documentation on MQL5: Language Basics / Functions / Event Handling Functions
Documentation on MQL5: Language Basics / Functions / Event Handling Functions
  • www.mql5.com
Language Basics / Functions / Event Handling Functions - Reference on algorithmic/automated trading language for MetaTrader 5
 
Enrico Lambino:

In MT4:

There is no OnTrade() event. Rather, the EA will wait for the result of the order execution, which is most likely performed under an OnTick() event. And since subsequent ticks are ignored while a given tick is still being processed, no new ticks will be processed from order sending until the actual confirmation from the server.

In MT5:

From https://www.mql5.com/en/docs/basis/function/events#ontrade

"Users must independently implement in the code the verification of a trade account state when such an event is received (if this is required by the trade strategy conditions). If the OrderSend() function call has been completed successfully and returned a value of true, this means that the trading server has put the order into the queue for execution and assigned a ticket number to it. As soon as the server processes this order, the Trade event will be generated. And if a user remembers the ticket value, he/she will be able to find out what happened to the order using this value during OnTrade() event handling."

So, yes, the orders will be queued, but on the server. The next tick processing will occur as soon as a new tick arrives right after processing the current tick. So there is a possibility, depending on your server, that OnTick() gets invoked first before the server returns a trade result, which is processed under OnTrade()

Yep, Thanks, That's the answer.
Reason: