OrderSend vs OrderSendAsynch

 

OrderSendAsynch has any disadvantage compared to OrderSend?

Why it is not used by default?

 
Narek Kamalyan:

OrderSendAsynch has any disadvantage compared to OrderSend?

Why it is not used by default?

The advantage is that you code is not halted for the response from the trade server. Contrary to common believe, it is not faster. The time you will get to know the ticket is exactly the same as with Ordersend. So it is beneficial only if there is a reason to *not* wait for response. Sending a batch of orders for example.

 
Narek Kamalyan:

OrderSendAsynch has any disadvantage compared to OrderSend?

Why it is not used by default?

Have you ever been dealing with async processing? The async method forces you to completely separate the processes of sending orders and managing the positions. In case of doubts you have no clue after you sent the order if it was executed or not, you have to catch it at another location in your code and translate/combine the incoming messages to what happened whenever before in your code. After sending an async order, all testing (opened positions, floating volume, pending orders etc.) you do immediately afterwards provide wrong results, in case of doubts. 

 
Exactly. Hence it is not default. Even MQ is not able to provide a working example.
 
Doerk Hilger:

The async method forces you to completely separate the processes of sending orders and managing the positions. 

In Asynch mode response from trade server will not arrive to MqlTradeRequest for further processing?
I am making trading panel and it will freeze in normal mode so I am considering to use Asynch mode
 

I use the async mode.

The EA waits (and freezes) until the server has responded upon your order. That makes the control part easier as you can put that in an if-clause.

The async order you fire and forget and e.g. after the next tick you have to check how your order was executed - it means you have to write an extra part in your code for this.

 
Carl Schreiber:

I use the async mode.

In Asynch mode, how I can get the ticket number of the order?

In normal mode terminal waits and after execution it makes the order ticket available in MqlTradeResult, so it can be processed immediately.

But in Asynch mode, as you said, I have to go back and search where is it and get its ticket. 

In my case I need to capture each ticket after position opening  and store it into array along with trailing distance, which is specific for each order. 

Is there any way to do it in Asynch mode?

 
Narek Kamalyan:
In Asynch mode response from trade server will not arrive to MqlTradeRequest for further processing?
I am making trading panel and it will freeze in normal mode so I am considering to use Asynch mode

The freeze is probably not caused by synced processing. 

Narek Kamalyan:

In Asynch mode, how I can get the ticket number of the order?


In the end it does not matter, cause transaction results can be delayed anytime, no matter if you use sync or async processing. The way you choose, storing tickets etc. will not work proper, when you don´t synchronize your signal flow with OnTradeTransaction(). It´s not that easy, but with enough effort it can be solved properly. 

Have a look at:

https://www.mql5.com/en/forum/357245

OnTrade/OnTradeTransaction - Are deal results always async?
OnTrade/OnTradeTransaction - Are deal results always async?
  • 2020.12.05
  • www.mql5.com
Hi, since some time I am facing the issue, that after a position was closed/partially closed the deal database does not provide valid results - and...
 
Narek Kamalyan:

In Asynch mode, how I can get the ticket number of the order?

In normal mode terminal waits and after execution it makes the order ticket available in MqlTradeResult, so it can be processed immediately.

But in Asynch mode, as you said, I have to go back and search where is it and get its ticket. 

In my case I need to capture each ticket after position opening  and store it into array along with trailing distance, which is specific for each order. 

Is there any way to do it in Asynch mode?

I do it with this structure:

...
   bool oOk=true;
...

//--- action and return the result
      if ( !OrderSendAsync(m_request,m_result) ) { // order arrived?
         Print(__FUNCTION__,"(",__LINE__,") FAILED: ",sym," T #",t," mag: ",OrderGetInteger(ORDER_MAGIC)," (",EnumToString(oTyp),
                  ") cmt: ",m_result.comment,", retcode = ",sErr(m_result.retcode)," e: ",sErr()); // error
         oOk = false;
      } else { this.PrintResult(); }

   if ( !oOk ) {
      // set some variables to repeat the order after some time waiting and not later than ...
      if ( sig == ORDER_TYPE_SELL ) { LimitReTriesOrdSE++; TimeRetriesPosSE = TimeCurrent()+LimitReTriesOrdSE*60; }
      if ( sig == ORDER_TYPE_BUY  ) { LimitReTriesOrdBU++; TimeRetriesPosBU = TimeCurrent()+LimitReTriesOrdBU*60; }
   } else { // all is ok
      // disable class variables
      if ( sig == ORDER_TYPE_SELL ) { LimitReTriesOrdSE = 0; TimeRetriesOrdSE = MaxDate; }
      if ( sig == ORDER_TYPE_BUY  ) { LimitReTriesOrdBU = 0; TimeRetriesOrdBU = MaxDate; }
      sig = WRONG_VALUE;
   }
   // return the need of repetition, WRONG_VALUE=no repetition
   return(sig); 
}
 
Narek Kamalyan:

OrderSendAsynch has any disadvantage compared to OrderSend?

Why it is not used by default?

It doesn't make a difference because there is no synchronous function in mql5. OrderSend is NOT synchronous even if Metaquotes doesn't want to recognize it.
 
So I general it is going to Sleep() until respond from server will confirm position and the code will run forward. I am right?
Reason: