How does OrderSend return order id?

 

When looking at the OrderSend function documentation, i notice that it will return an int with the order number.

But I'm actually curious to how this is done. When you send an order no order id is known initially, how does the function know what ID is being corresponded to the function call?

 
lukas:

When looking at the OrderSend function documentation, i notice that it will return an int with the order number.

But I'm actually curious to how this is done. When you send an order no order id is known initially, how does the function know what ID is being corresponded to the function call?

It auto hyper linked to the mt5 function, but im talking about the mql4 one https://docs.mql4.com/trading/ordersend
 
Your topic has been moved to the section: MQL4 and MetaTrader 4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
lukas: When looking at the OrderSend function documentation, i notice that it will return an int with the order number. But I'm actually curious to how this is done. When you send an order no order id is known initially, how does the function know what ID is being corresponded to the function call?


Did you not read the documentation you referenced? ... OrderSend - Trade Functions - MQL4 Reference

What does it state about the return value?

Returned value

Returns number of the ticket assigned to the order by the trade server or -1 if it fails. To get additional error information, one has to call the GetLastError() function.

The function sends the request to the broker's trade server, which then sends back the ticket for it. It is a synchronous function which blocks any further execution for a certain amount of time, while it waits for the response.