MQL5 vs QLUA - Why trading operations in MQL5 are up to 28 times faster?
Have you ever wondered how quickly your order is delivered to the exchange, how fast it is executed, and how much time your terminal needs in order to receive the operation result?
Meanwhile, there is a way to improve order execution quality by receiving a quicker response and by achieving a faster transaction speed.
- Testing of synchronous operations — a series of 10 synchronous consecutive Buy operations with a confirmation of a successful execution of each transaction on the exchange. The next operation is not executed until a response is received from the trade server confirming that the previous operation has or has not been executed on the exchange. The execution speed depends on the entire chain: the terminal — the trade server — the exchange — the trade server — the terminal. The smaller the average time of the synchronous trading operation, the better.
- Testing of asynchronous operations — a series of 10 asynchronous Buy operations without any confirmation of a successful transaction execution. It is a pure rate test, which measures how fast orders are sent to the exchange. The best terminal is the one that can execute 10 asynchronous Buy operations faster.
- Testing of order book update — measuring how fast orders in the Market Depth (order book) are updated. This is a simple counting of the number of ticks (updates) in the Market Depth per a unit of time. The more frequent quotes are received by the terminal from the exchange, the faster the order book will be updated. Therefore, the more ticks per second are received by the automated trading application, the quicker it can respond to changes in the market demand/supply structure. The best terminal is the one with the higher speed of order book update.
Test Conditions
The two terminals are installed on a hosted VPS in Moscow, like the trade servers of the "Otkryite" broker. Trading operations were performed using the same real account on Moscow Exchange's Derivatives Market; the traded instrument was Si-9.6.
We captured a video of the three tests for easier analysis:
- Trading operations were performed on the same real account
- The same financial instrument Si-9.16 was traded
- The same computer was used
- Trading operations were performed in the same time
- The same market conditions
- The speed of Market Depth (order book) update was measured on the same instrument in the same time
- The network latency to the broker's servers was 2 ms
Trading Operation Speed Results: MetaTrader 5 vs QUIK
The results of the three tests are featured in a summary table, additional detailed results of each test are available in further sections below.
Test | MetaTrader 5 | QUIK | MT5 lead |
---|---|---|---|
The average time of a synchronous operation | 9.59 ms | 277.80 ms | 28.96 times |
The average time of an asynchronous operation | 0.09 ms | 0.30 ms | 3.33 times |
Market Depth update speed | 42.7 times per second | 8.4 times per second | 5.08 times |
As you can see, MetaTrader 5 shows much better results in all tests. You can reproduce the same tests using the attached source code. The testing process is demonstrated in the video below.
Trading Speed Comparison Video
Conclusion: MetaTrader 5 performs trading operations up to 28 times faster than QUIK
These tests demonstrate that the MQL5 language is much faster than QLUA in performing trading operations on Moscow Exchange, as well as in scanning the Market Depth. In addition to performing calculations 50-600 times faster, trading robots in MQL5 also trade up to 28 times faster. Moreover, the entire arsenal of development tools is available without the need to use additional connectors, DLLs, etc. You can use ready trade classes from the Standard Library and a large number of articles on trading automation.
A robust trading robot must check trade sending results; i.e. it must wait for a response from the trade server. The tests have proven that MetaTrader 5 is significantly faster in performing synchronous operations. If you need to use asynchronous operations, you can do it 3 times faster with MetaTrader 5. Should you need to analyze the order book, MetaTrader 5 will provide you with an advantage of a 5-time faster quoting stream without snapshots.
These tests also prove that the MQL5 language is an ideal solution for creating fast performing automated trading systems. Even additional connectors or libraries for the QUIK terminal that are aimed to speed up calculations would not help much, since the bottleneck is the trade operation performance time.
Now let's analyze the boring yet important test details.
Detailed MetaTrader 5 vs QUICK Comparison Reports
An application in QLUA measures time by calling the operating system timer with the default timer resolution of 10…15.6 milliseconds (usually 15.6 ms). We had to improve the accuracy of time measurement in QLUA by simply reducing the system timer resolution to 1 ms. This is done by using the script SpeedupSystemTimer.mq5, which calls the timeBeginPeriod function of the Winmm.dll system library
#import "winmm.dll" int timeBeginPeriod(uint per); #import void OnInit() { timeBeginPeriod(1); } void OnTick() { }
We had run the script before starting tests in MetaTrader 5 additionally allowing DLL calls, which resulted in the operation measurement error in QUIK of no more than 1 ms.
The MQL5 language provides a ready function GetMicrosecondCount(), so the accuracy of speed measurement in the MetaTrader 5 terminal is 1 microsecond (1 millisecond=1000 microseconds).
#1 Synchronous Trading Operations Speed Test
The test implied measuring the speed of synchronous trading operations, i.e. a trading operation could only be executed after receiving a response from the trade server confirming that the previous operation was successfully executed with a complete confirmation from the exchange.
First, a series of trading operations was performed through the MetaTrader 5 terminal, then the same series was performed through the QUIK terminal.
The purpose of the tests was to measure the average time of 10 synchronous 1-lot market Buy operations:
- SyncTradeTest.mq5
- SyncTradeTest.lua
The time spent to execute a synchronous operation was measured as follows:
- The MQL5 language provides the synchronous OrderSend function, and the time can be easily measured at the beginning and at the end of the trade series.
- The QLUA language does not provide synchronous trading functions, and therefore the status of the transaction should be monitored separately. The time of operation start was recorded right before the call of sendTransaction() using the os.closck() function. A successful completion of the transaction was monitored in the built-in OnOrder() handler during the first call when the event about a trade execution on the exchange was received. The difference between these events is the time taken to execute a trading operation.
#2 Asynchronous Trading Operations Speed Test
This test is much easier. An order to buy one Si-9.16 futures contract was sent ten times in a row. This allowed us to measure the average time of the asynchronous transfer in QLUA with an accuracy of 1 ms / 10 = 0.10 ms. The MetaTrader 5 has no measurement error, while it uses a microsecond timer.
We did not wait for the operation result: sending an order to a trade server was immediately followed by sending the next order:
- AsyncTradeTest.mq5
- AsyncTradeTest.lua
#3 Market Depth Update Test
Some trading strategies utilize the order book analysis. In MQL5, the Market Depth change event can be tracked in the OnBookEvent() handler; QLUA provides OnQuote() for that purpose.
The speed of Market Depth change was tested using the following programs, which are available in the attached ZIP:
- MarketUpdateTest.mq5
- MarketUpdateTest.lua
After running the programs in the two terminals, we recorded that the Market Depth in MetaTrader 5 was updated about 5 times more frequently. Probably, QUIK limits the frequency of order book updates and does not show some of the changes.
Why Is the Difference So Impressive?
We passionately strive for high performance and value every microsecond while constantly optimizing the trading platform for over years.
That is why we have achieved an amazing performance of our built-in algorithmic MQL5 language and an impressive trade transaction speed.
Translated from Russian by MetaQuotes Ltd.
Original article: https://www.mql5.com/ru/articles/2635
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use