Block execution till trade server responds.

 
Hi. Does trade operations like OrderSend suspend execution until the result returns? I can't find any source saying anything about it. It is critical to understand how this, and other functions such as... wait. I've found it. For anyone out there with a similar curiosity, Ordersend is a blocking operation. It waits for server response on sent requests before code execution proceeds. A non-blocking version is OrderSendAsync().
 

If you want that you can also code it to wait for the results.

Sending a buy trade request leads to a chain of trade transactions on a trading account:

1) request is accepted for processing,

2) an appropriate purchase order is created for the account,

3) the order is then executed,

4) the executed order is removed from the list of active ones,

5) adding to the history of orders,

6) the subsequent transaction is added to history and

7) a new position is created.

All these stages are trade transactions.

The arrival of each such transaction to the terminal is the TradeTransaction event.

Priority of these transactions' arrival at the terminal is not guaranteed.

Thus, you should not expect that one group of transactions will arrive after another one when developing your trading algorithm.

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Transaction Types
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Transaction Types
  • www.mql5.com
Removing an order from the list of the open ones. An order can be deleted from the open ones as a result of setting an appropriate request or execution (filling) and moving to the history. Updating a deal in the history. There may be cases when a previously executed deal is changed on a server. For example, a deal has been changed in an...
 
Marco vd Heijden:

If you want that you can also code it to wait for the results.

Sending a buy trade request leads to a chain of trade transactions on a trading account:

1) request is accepted for processing,

2) an appropriate purchase order is created for the account,

3) the order is then executed,

4) the executed order is removed from the list of active ones,

5) adding to the history of orders,

6) the subsequent transaction is added to history and

7) a new position is created.

All these stages are trade transactions.

The arrival of each such transaction to the terminal is the TradeTransaction event.

Priority of these transactions' arrival at the terminal is not guaranteed.

Thus, you should not expect that one group of transactions will arrive after another one when developing your trading algorithm.

Using OrderSendAsync in order to wait for results is futile. Then just use OrderSend.

Anyways, in order to not reinvent the wheel, see https://www.mql5.com/ru/code/22166

 

If you want to keep some background process running while halting primary or sub routines.

As always it depends on the specific implementation.

 
Marco vd Heijden:

If you want to keep some background process running while halting primary or sub routines.

As always it depends on the specific implementation.

True.
 
Enrique Dangeroux:

Using OrderSendAsync in order to wait for results is futile. Then just use OrderSend.

Anyways, in order to not reinvent the wheel, see https://www.mql5.com/ru/code/22166

It's not about reinventing the wheel. There's a reason for the OrdersendAsync's existance, that I intend to explore.