When investigating TP order execution, I noticed that some TP orders were created with a significant lag from the ticks that accepted them.
The debriefing showed that this situation is repeated not only on different brokers, but also in the situation when trading is done on the Terminal, which is on the same machine as the Trading Server. I.e. with a very low ping and the only trading account for the Trading Server.
Writing theGetAcceptedTick function allowed us to thoroughly investigate the issue and constructively demonstrate the problem.
Script.
So, the following script is located in the trailer.
// Скрипт выводит самое длительное или конкретное акцептирование SL/TP-ордера. #property script_show_inputs input datetime inFrom = D'2020.01.01'; // С какого времени проверять ордера input ulong inTicket = 0; // Отдельно проверяемый тикет // Возвращает самый медленный TP/SL-ордер с определенной даты. ulong GetSlowestOrder( const datetime From ); // Распечатывает подробности акцепта SL/TP-ордера. void PrintOrder( const ulong MaxTicket ); void OnStart() { Print("\n\nStart " + MQLInfoString(MQL_PROGRAM_NAME) + TOSTRING(inFrom) + TOSTRING(inTicket) + "\n"); PrintOrder(inTicket ? inTicket : GetSlowestOrder(inFrom)); }
The result of running it on the MQ-Demo.
Total Orders (from 2020.09.01 00:00:00) = 58493, calculated = 439 Calculation time = 00:00:11.328, Performance = 38.0 orders/sec. ServerName: MetaQuotes-Demo Last Tick 2020.09.30 19:07:32.917 1.80181 1.80205 Accepted Tick 2020.09.30 19:07:32.716 1.80178 1.80202 Accepted Length = 357 ms. Order 726444166 ORDER_TYPE_BUY GBPAUD 2020.09.30 19:07:33.073 1.80206 ORDER_REASON_TP ORDER_STATE_FILLED 2020.09.30 19:07:33.082, Position created 2020.09.30 17:21:17.933, StopLevel = 0 Orders (2) before 726444166 with PositionID = 725926764: ------------------------ Checked Orders = 0 ------------------------
The script claims to have found a TP order and a tick which was the trigger for its creation (highlighted in colour in the text). It would seem that if the price has reached the TP level of an open position on the trade server (especially on the demo), the corresponding TP order should be created (not necessarily executed) immediately. However, in this situation, it happened not immediately, but after 357 milliseconds!
Let me say upfront that even a one-millisecond delay is not too little. To be in time is a meaningful verb in algotrading.
Verification.
Let's not blindly trust the script and check this situation manually. So, here is our order.
The corresponding accepting tick found by the script can be seen here.
The arrow shows between the ticks the TP order was born. The screenshots clearly show that the script was right and the TP order creation happened with a huge lag on the trade server's side.
Bottom line.
There is now a tool that shows the lag values on the Trade Server side when trading via TP/SL levels. At the moment they are enormous. And this is definitely a serious disadvantage of the platform which needs to be corrected.
Unfortunately, it is impossible to register the acceptance of pending orders as this information is not available on the Terminal side. But almost invariably, the presence of significant lags on the TP/SL order side cannot but affect the lags when executing the orders. As the cause seems to be of the same nature.
All in all, the MT5 platform is currently lagging 100% specifically in these situations. And requires fixes until there is zero lag.
I encourage you to share the results from your accounts. Contribute to improving MT5!
Encourage you to share the results from your accounts. Help improve MT5!
Total Orders (from 2020.11.01 00:00:00) = 21725, calculated = 10465 Calculation time = 00:04:33.609, Performance = 38.0 orders/sec. ServerName: RannForex-Server Last Tick 2020.11.16 00:34:35.201 104.630 104.640 Accepted Tick 2020.11.16 00:34:06.309 104.627 104.639 Accepted Length = 28894 ms. Order 1715452 ORDER_TYPE_SELL USDJPY 2020.11.16 00:34:35.203 104.627 ORDER_REASON_TP ORDER_STATE_REJECTED 2020.11.16 00:34:35.217, Position created 2020.11.16 00:33:51.196, StopLevel = 0 Orders (4) before 1715452 with PositionID = 1715287: ----------------------- Last Tick 2020.11.16 00:34:06.309 104.627 104.639 Accepted Tick 2020.11.16 00:34:06.309 104.627 104.639 Accepted Length = 3 ms. Order 1715425 ORDER_TYPE_SELL USDJPY 2020.11.16 00:34:06.312 104.625 ORDER_REASON_TP ORDER_STATE_REJECTED 2020.11.16 00:34:06.327, Position created 2020.11.16 00:33:51.196, StopLevel = 0 Checked Orders = 1 ------------------------
28 second lag! Probably best to contact the broker in these situations already.
2020.11.25 02:42:17.718 CheckOrders (EURUSD,H1) ServerName: ICMarkets-MT5 2020.11.25 02:42:17.718 CheckOrders (EURUSD,H1) 2020.11.25 02:42:17.718 CheckOrders (EURUSD,H1) Last Tick 2020.11.24 23:00:49.327 1.33569 1.33570 2020.11.25 02:42:17.718 CheckOrders (EURUSD,H1) Accepted Tick 2020.11.24 23:00:49.327 1.33569 1.33570 2020.11.25 02:42:17.718 CheckOrders (EURUSD,H1) Accepted Length = 7 ms. 2020.11.25 02:42:17.718 CheckOrders (EURUSD,H1) Order 106887648 ORDER_TYPE_BUY GBPUSD 2020.11.24 23:00:49.334 1.33572 ORDER_REASON_TP ORDER_STATE_FILLED 2020.11.24 23:00:49.830, Position created 2020.11.24 22:57:47.071, StopLevel = 0 2020.11.25 02:42:17.718 CheckOrders (EURUSD,H1) 2020.11.25 02:42:17.719 CheckOrders (EURUSD,H1) Orders (2) before 106887648 with PositionID = 106886713: 2020.11.25 02:42:17.719 CheckOrders (EURUSD,H1) ------------------------ 2020.11.25 02:42:17.719 CheckOrders (EURUSD,H1) Checked Orders = 0 2020.11.25 02:42:17.719 CheckOrders (EURUSD,H1) ------------------------
2020.11.25 02:47:22.624 CheckOrders (EURUSD,H1) ServerName: ICMarkets-MT5 2020.11.25 02:47:22.624 CheckOrders (EURUSD,H1) 2020.11.25 02:47:22.633 CheckOrders (EURUSD,H1) Last Tick 2020.11.18 12:44:37.354 1.18748 1.18748 2020.11.25 02:47:22.633 CheckOrders (EURUSD,H1) Accepted Tick 2020.11.18 12:44:37.354 1.18748 1.18748 2020.11.25 02:47:22.633 CheckOrders (EURUSD,H1) Accepted Length = 17 ms. 2020.11.25 02:47:22.633 CheckOrders (EURUSD,H1) Order 105637485 ORDER_TYPE_SELL EURUSD 2020.11.18 12:44:37.371 1.18749 ORDER_REASON_SL ORDER_STATE_FILLED 2020.11.18 12:44:37.476, Position created 2020.11.17 22:24:15.116, StopLevel = 0 2020.11.25 02:47:22.633 CheckOrders (EURUSD,H1) 2020.11.25 02:47:22.634 CheckOrders (EURUSD,H1) Orders (2) before 105637485 with PositionID = 105516718: 2020.11.25 02:47:22.634 CheckOrders (EURUSD,H1) ------------------------ 2020.11.25 02:47:22.634 CheckOrders (EURUSD,H1) Checked Orders = 0 2020.11.25 02:47:22.634 CheckOrders (EURUSD,H1) ------------------------
2020.11.25 02:50:58.687 CheckOrders (EURUSD,H1) ServerName: OctaFX-Real 2020.11.25 02:50:58.687 CheckOrders (EURUSD,H1) 2020.11.25 02:50:58.687 CheckOrders (EURUSD,H1) Last Tick 2020.11.23 18:14:35.081 1.18108 1.18115 2020.11.25 02:50:58.687 CheckOrders (EURUSD,H1) Accepted Tick 2020.11.23 18:14:35.081 1.18108 1.18115 2020.11.25 02:50:58.687 CheckOrders (EURUSD,H1) Accepted Length = 11 ms. 2020.11.25 02:50:58.687 CheckOrders (EURUSD,H1) Order 8950107 ORDER_TYPE_SELL EURUSD 2020.11.23 18:14:35.092 1.18105 ORDER_REASON_TP ORDER_STATE_FILLED 2020.11.23 18:14:35.104, Position created 2020.11.23 18:11:38.678, StopLevel = 20 2020.11.25 02:50:58.687 CheckOrders (EURUSD,H1) 2020.11.25 02:50:58.688 CheckOrders (EURUSD,H1) Orders (2) before 8950107 with PositionID = 8950014: 2020.11.25 02:50:58.688 CheckOrders (EURUSD,H1) ------------------------ 2020.11.25 02:50:58.688 CheckOrders (EURUSD,H1) Checked Orders = 0 2020.11.25 02:50:58.688 CheckOrders (EURUSD,H1) ------------------------
2020.11.25 02:54:37.912 CheckOrders (EURUSD,H1) ServerName: Pepperstone-MT5-Live01 2020.11.25 02:54:37.912 CheckOrders (EURUSD,H1) 2020.11.25 02:54:37.934 CheckOrders (EURUSD,H1) Last Tick 2020.09.03 01:00:02.426 106.199 106.199 2020.11.25 02:54:37.934 CheckOrders (EURUSD,H1) Accepted Tick 2020.09.03 01:00:02.426 106.199 106.199 2020.11.25 02:54:37.934 CheckOrders (EURUSD,H1) Accepted Length = 4 ms. 2020.11.25 02:54:37.934 CheckOrders (EURUSD,H1) Order 18982771 ORDER_TYPE_SELL USDJPY 2020.09.03 01:00:02.430 106.191 ORDER_REASON_TP ORDER_STATE_FILLED 2020.09.03 01:00:02.466, Position created 2020.09.02 22:57:47.081, StopLevel = 0 2020.11.25 02:54:37.934 CheckOrders (EURUSD,H1) 2020.11.25 02:54:37.935 CheckOrders (EURUSD,H1) Orders (2) before 18982771 with PositionID = 18975080: 2020.11.25 02:54:37.935 CheckOrders (EURUSD,H1) ------------------------ 2020.11.25 02:54:37.935 CheckOrders (EURUSD,H1) Checked Orders = 0 2020.11.25 02:54:37.935 CheckOrders (EURUSD,H1) ------------------------
another brain blast from fxsaber. i don't even know what to say.
I think the only workable solution is to find the bottleneck together with the broker and, if possible, try to fix it.
for an in-house fix, you'll have to
- withstand a barrage of criticism from developers and prove that the lag has occurred (taking into account things you may not know, for example, server hardware of the broker)
- convince you that it is critical
- wait for a fix
- zealously pushing the broker to upgrade to the latest build, which may be much harder than all of the previous items.
ServerName: RannForex-Server
Accepted Length = 28894 ms.
There's a strong suspicion here of the very cool technology of the broker you're trading for.
Something is slowing down in the custom limit processing plugins.
This is where there is a strong suspicion of the very cool technology of the broker for which you are trading.
... The broker's servers can be anything you want, or it may be a link to a thread about lags in the exchange section, we can only guess.
For an in-house fix, you'll have to
- You will have to suffer a barrage of criticism from the developers and prove that the lag takes place (considering the nuances you may not know, for example, the hardware of the server part of the broker).
Forum on trading, automated trading systems and testing trading strategies
fxsaber, 2020.11.25 00:47
Result of running it on MQ-Demo.
Total Orders (from 2020.09.01 00:00:00) = 58493, calculated = 439 Calculation time = 00:00:11.328, Performance = 38.0 orders/sec. ServerName: MetaQuotes-Demo
It has been repeatedly stated in another thread that even the Terminal is slowing down from a huge number of factors. As a consequence, the much more complex Trading Server is bound to slow down even more. I still hope that algorithmic optimisation is still possible. Even a 5 ms lag is already very bad. Let alone hundreds of milliseconds.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
This branch will deal with orders which are created as a result of triggering of SL/TP levels of open positions.
I wrote a complicated but useful function of getting a tick which serves as a trigger for a specified SL/TP order.
The application of this great function is the reason for creating this branch. I am sure I did not catch all bugs in the code, but for the sake of history and understanding that it is really difficult, I have given full listing.