Discussion of article "MQL5 vs QLUA - Why trading operations in MQL5 are up to 28 times faster?" - page 5

 

There was strong movement on Brent today

And at this moment MT5 took care of these delays.

 
Renat Fatkhullin:

You don't need to adjust anything. My phrase was for a general case "in your internet and your ping can be anything and in reality depending on your network you will get a transaction in 0-N ms". And it's more likely to be 0 ms than more.

Here is the verification code with control of all transactions in asynchronous mode:

Here is its output on a real account just now:

You should read it from bottom to top.

It shows all stages of transactions with the cumulative total of time spent from the start. By transaction types you can see what was added to the terminal and when.

The total time is 11.45 ms.

Thank you very much for the clear code! According to your results, there is really nothing to correct. I made a mistake.
 
prostotrader:

Today there was a strong movement on Brent.

And at this moment MT5 took care of these delays.

Keep hotkeys ready for instant screen recording. Or record everything around the clock. You can always cut out a problematic piece and present it as a proof. For now, just words.
 
prostotrader:

What are you talking about, Renate?

That's an extract from the Temninal's log, not my own log!

Yes, that's right. Sorry, I confused it with a mate who was counting timings incorrectly.

Here's what happened at the time: it's a question for the exchange - why does it always behave like that on minimal movements and considers it normal to execute orders in such a time.

You wanted to place a limit order at 47.56 close to the market and it is likely that the exchange slowed down accepting orders for a close price interval on purpose, so that there would be no surprises for it:


From the performance point of view there can be no questions, as the volume there was ridiculous, 320 lots per minute.

I have shown my performance in a calm market above.

 
fxsaber:
Keep hotkeys at the ready for instant screen recording. Or record everything around the clock. You can always cut out the problematic part and present it as evidence. For now, just words.
prostotrader:

Today there was a strong movement on Brent.

And at this moment MT5 took care of these delays.

Only MT5 has nothing to do with these delays.

It was the exchange that responded for so long.

 
Renat Fatkhullin:

Only MT5 has nothing to do with these delays.

It was the exchange that took so long to respond.

Can you please highlight the lines in your example-log where the exchange's brakes will be visible when it behaves like this?

2016.09.14 18:32:53.234 Test (BR-12.16,H1)      TRADE_TRANSACTION_HISTORY_ADD BR-12.16: 0.0 0 time: 11.455 ms
2016.09.14 18:32:53.232 Test (BR-12.16,H1)      TRADE_TRANSACTION_DEAL_ADD BR-12.16: 47.13 0 time: 8.778 ms
2016.09.14 18:32:53.231 Test (BR-12.16,H1)      TRADE_TRANSACTION_ORDER_DELETE BR-12.16: 0.0 0 time: 8.457000000000001 ms
2016.09.14 18:32:53.231 Test (BR-12.16,H1)      TRADE_TRANSACTION_ORDER_UPDATE BR-12.16: 0.0 0 time: 8.202999999999999 ms
2016.09.14 18:32:53.231 Test (BR-12.16,H1)      TRADE_TRANSACTION_REQUEST : 0.0 44326441 time: 8.151 ms
2016.09.14 18:32:53.228 Test (BR-12.16,H1)      TRADE_TRANSACTION_ORDER_UPDATE BR-12.16: 0.0 0 time: 5.196 ms
2016.09.14 18:32:53.228 Test (BR-12.16,H1)      TRADE_TRANSACTION_REQUEST : 0.0 44326441 time: 5.171 ms
2016.09.14 18:32:53.227 Test (BR-12.16,H1)      TRADE_TRANSACTION_ORDER_ADD BR-12.16: 0.0 0 time: 4.184 ms
2016.09.14 18:32:53.223 Test (BR-12.16,H1)      Start...
2016.09.14 18:32:49.753 Test (BR-12.16,H1)      AsyncTradesTest: last ping 2.15 ms, build 1417
 

It will most likely become noticeable from here, but will definitely be visible on the last two transactions:

2016.09.14 18:32:53.234 Test (BR-12.16,H1)      TRADE_TRANSACTION_HISTORY_ADD BR-12.16: 0.0 0 time: 11.455 ms
2016.09.14 18:32:53.232 Test (BR-12.16,H1)      TRADE_TRANSACTION_DEAL_ADD BR-12.16: 47.13 0 time: 8.778 ms
2016.09.14 18:32:53.231 Test (BR-12.16,H1)      TRADE_TRANSACTION_ORDER_DELETE BR-12.16: 0.0 0 time: 8.457000000000001 ms
2016.09.14 18:32:53.231 Test (BR-12.16,H1)      TRADE_TRANSACTION_ORDER_UPDATE BR-12.16: 0.0 0 time: 8.202999999999999 ms
2016.09.14 18:32:53.231 Test (BR-12.16,H1)      TRADE_TRANSACTION_REQUEST : 0.0 44326441 time: 8.151 ms
2016.09.14 18:32:53.228 Test (BR-12.16,H1)      TRADE_TRANSACTION_ORDER_UPDATE BR-12.16: 0.0 0 time: 5.196 ms
2016.09.14 18:32:53.228 Test (BR-12.16,H1)      TRADE_TRANSACTION_REQUEST : 0.0 44326441 time: 5.171 ms
2016.09.14 18:32:53.227 Test (BR-12.16,H1)      TRADE_TRANSACTION_ORDER_ADD BR-12.16: 0.0 0 time: 4.184 ms
2016.09.14 18:32:53.223 Test (BR-12.16,H1)      Start...
2016.09.14 18:32:49.753 Test (BR-12.16,H1)      AsyncTradesTest: last ping 2.15 ms, build 1417
 
Renat Fatkhullin:

It will most likely become noticeable from here, but will definitely be visible on the last two transactions:

Thanks. The help and the article are rather sparse on the internal processes behind each type of trade transaction.

In your clarification it appears that the first four lines (8ms) are not an exchange yet. Where is it possible to read what actually happens? Because there is no understanding and it is not clear where to get it.

 
fxsaber:

Thanks. The help and the article are rather sparse on the internal processes behind each type of trade transaction.

In your clarification it turns out that the first four lines (8ms) are not an exchange yet. Where is it possible to read what actually happens? Because there is no understanding and it is not clear where to emphasise it.

No, I didn't say that.

I sketched the code hastily and did not describe all the fields. Check yourself in the debugger each input to the function of my script and print out more fields, please.

 
fxsaber:

Thanks. The help and the article are rather poorly written about the internal processes behind each type of trading transaction.

An example of a possible listener of trading events is given in the article Where to start when creating a trading robot for the Moscow Exchange MOEX

//+------------------------------------------------------------------+
//|TradeTransactionListener.mq5 |
//| Copyright 2016, MetaQuotes Software Corp. | |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialisation function|
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   PrintFormat("LAST PING=%.f ms",
               TerminalInfoInteger(TERMINAL_PING_LAST)/1000.);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function|
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+
//| TradeTransaction function|
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {
//---
   static int counter=0;   // counter of OnTradeTransaction() calls
   static uint lasttime=0; // time of the last call OnTradeTransaction()
//---
   uint time=GetTickCount();
//--- if the last transaction was more than 1 second ago
   if(time-lasttime>1000)
     {
      counter=0; // it means that this is a new trade operation and you can reset the counter
      if(IS_DEBUG_MODE)
         Print(" New Trade Operation");
     }
   lasttime=time;
   counter++;
   Print(counter,". ",__FUNCTION__);
//--- result of trade request execution
   ulong            lastOrderID   =trans.order;
   ENUM_ORDER_TYPE  lastOrderType =trans.order_type;
   ENUM_ORDER_STATE lastOrderState=trans.order_state;
//--- the name of the character on which the transaction occurred
   string trans_symbol=trans.symbol;
//--- transaction type
   ENUM_TRADE_TRANSACTION_TYPE  trans_type=trans.type;
   switch(trans.type)
     {
      case  TRADE_TRANSACTION_POSITION:   // change position
        {
         ulong pos_ID=trans.position;
         PrintFormat("MqlTradeTransaction: Position  #%d %s modified: SL=%.5f TP=%.5f",
                     pos_ID,trans_symbol,trans.price_sl,trans.price_tp);
        }
      break;
      case TRADE_TRANSACTION_REQUEST:     // sending a trade request
         PrintFormat("MqlTradeTransaction: TRADE_TRANSACTION_REQUEST");
         break;
      case TRADE_TRANSACTION_DEAL_ADD:    // adding a transaction
        {
         ulong          lastDealID   =trans.deal;
         ENUM_DEAL_TYPE lastDealType =trans.deal_type;
         double        lastDealVolume=trans.volume;
         //--- transaction identifier in the external system - ticket assigned by the Moscow Exchange
         string Exchange_ticket="";
         if(HistoryDealSelect(lastDealID))
            Exchange_ticket=HistoryDealGetString(lastDealID,DEAL_EXTERNAL_ID);
         if(Exchange_ticket!="")
            Exchange_ticket=StringFormat("(MOEX deal=%s)",Exchange_ticket);

         PrintFormat("MqlTradeTransaction: %s deal #%d %s %s %.2f lot   %s",EnumToString(trans_type),
                     lastDealID,EnumToString(lastDealType),trans_symbol,lastDealVolume,Exchange_ticket);
        }
      break;
      case TRADE_TRANSACTION_HISTORY_ADD: // adding an order to the history
        {
         //--- order identifier in the external system - ticket assigned by the Moscow Exchange
         string Exchange_ticket="";
         if(lastOrderState==ORDER_STATE_FILLED)
           {
            if(HistoryOrderSelect(lastOrderID))
               Exchange_ticket=HistoryOrderGetString(lastOrderID,ORDER_EXTERNAL_ID);
            if(Exchange_ticket!="")
               Exchange_ticket=StringFormat("(MOEX ticket=%s)",Exchange_ticket);
           }
         PrintFormat("MqlTradeTransaction: %s order #%d %s %s %s   %s",EnumToString(trans_type),
                     lastOrderID,EnumToString(lastOrderType),trans_symbol,EnumToString(lastOrderState),Exchange_ticket);
        }
      break;
      default: // other transactions 
        {
         //--- order identifier in the external system - ticket assigned by the Moscow Exchange
         string Exchange_ticket="";
         if(lastOrderState==ORDER_STATE_PLACED)
           {
            if(OrderSelect(lastOrderID))
               Exchange_ticket=OrderGetString(ORDER_EXTERNAL_ID);
            if(Exchange_ticket!="")
               Exchange_ticket=StringFormat("MOEX ticket=%s",Exchange_ticket);
           }
         PrintFormat("MqlTradeTransaction: %s order #%d %s %s   %s",EnumToString(trans_type),
                     lastOrderID,EnumToString(lastOrderType),EnumToString(lastOrderState),Exchange_ticket);
        }
      break;
     }
//--- order ticket 
   ulong orderID_result=result.order;
   string retcode_result=GetRetcodeID(result.retcode);
   if(orderID_result!=0)
      PrintFormat("MqlTradeResult: order #%d retcode=%s ",orderID_result,retcode_result);
//--- 
  }
//+------------------------------------------------------------------+
//| translates numeric answer codes into string mnemocodes |
//+------------------------------------------------------------------+
string GetRetcodeID(int retcode)
  {
   switch(retcode)
     {
      case 10004: return("TRADE_RETCODE_REQUOTE");             break;
      case 10006: return("TRADE_RETCODE_REJECT");              break;
      case 10007: return("TRADE_RETCODE_CANCEL");              break;
      case 10008: return("TRADE_RETCODE_PLACED");              break;
      case 10009: return("TRADE_RETCODE_DONE");                break;
      case 10010: return("TRADE_RETCODE_DONE_PARTIAL");        break;
      case 10011: return("TRADE_RETCODE_ERROR");               break;
      case 10012: return("TRADE_RETCODE_TIMEOUT");             break;
      case 10013: return("TRADE_RETCODE_INVALID");             break;
      case 10014: return("TRADE_RETCODE_INVALID_VOLUME");      break;
      case 10015: return("TRADE_RETCODE_INVALID_PRICE");       break;
      case 10016: return("TRADE_RETCODE_INVALID_STOPS");       break;
      case 10017: return("TRADE_RETCODE_TRADE_DISABLED");      break;
      case 10018: return("TRADE_RETCODE_MARKET_CLOSED");       break;
      case 10019: return("TRADE_RETCODE_NO_MONEY");            break;
      case 10020: return("TRADE_RETCODE_PRICE_CHANGED");       break;
      case 10021: return("TRADE_RETCODE_PRICE_OFF");           break;
      case 10022: return("TRADE_RETCODE_INVALID_EXPIRATION");  break;
      case 10023: return("TRADE_RETCODE_ORDER_CHANGED");       break;
      case 10024: return("TRADE_RETCODE_TOO_MANY_REQUESTS");   break;
      case 10025: return("TRADE_RETCODE_NO_CHANGES");          break;
      case 10026: return("TRADE_RETCODE_SERVER_DISABLES_AT");  break;
      case 10027: return("TRADE_RETCODE_CLIENT_DISABLES_AT");  break;
      case 10028: return("TRADE_RETCODE_LOCKED");              break;
      case 10029: return("TRADE_RETCODE_FROZEN");              break;
      case 10030: return("TRADE_RETCODE_INVALID_FILL");        break;
      case 10031: return("TRADE_RETCODE_CONNECTION");          break;
      case 10032: return("TRADE_RETCODE_ONLY_REAL");           break;
      case 10033: return("TRADE_RETCODE_LIMIT_ORDERS");        break;
      case 10034: return("TRADE_RETCODE_LIMIT_VOLUME");        break;
      case 10035: return("TRADE_RETCODE_INVALID_ORDER");       break;
      case 10036: return("TRADE_RETCODE_POSITION_CLOSED");     break;
      default:
         return("TRADE_RETCODE_UNKNOWN="+IntegerToString(retcode));
         break;
     }
//---
  }
//+------------------------------------------------------------------+