Русский 中文 Español Deutsch 日本語 Português
MQL5 vs QLUA - Why trading operations in MQL5 are up to 28 times faster?

MQL5 vs QLUA - Why trading operations in MQL5 are up to 28 times faster?

MetaTrader 5Examples | 21 September 2016, 09:20
20 980 69
MetaQuotes
MetaQuotes

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.

September 12, 2016 we simultaneously run three speed tests on a real account with the "Otkrytie" broker in MetaTrader 5 build 1415 and Quik 7.2.23. Each test was aimed to measure specific speed characteristics, which is important for algorithmic trading:
  1. 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.
  2. 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.
  3. 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:

  1. Trading operations were performed on the same real account
  2. The same financial instrument Si-9.16 was traded
  3. The same computer was used
  4. Trading operations were performed in the same time
  5. The same market conditions
  6. The speed of Market Depth (order book) update was measured on the same instrument in the same time
  7. 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 ms277.80 ms28.96 times
The average time of an asynchronous operation0.09 ms0.30 ms 3.33 times
Market Depth update speed
42.7 times per second8.4 times per second5.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.
Measurement results show that MetaTrader 5 executed synchronous operations up to 28 times faster.


#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
The results showed that MetaTrader 5 executed asynchronous operations 3.33 times faster.


#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.

All the source code files are attached to the article, so anybody can reproduce these tests and check the results for themselves.


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

Attached files |
Last comments | Go to discussion (69)
s_mike
s_mike | 5 Sep 2017 at 16:04
Renat Fatkhullin:

You first prove your words with your code as opposed to our proofs.

Why are you throwing words around on the level of banal erudition and not knowing what LUA is?


There are two languages that have been compared.

And one loses to the other in 50-600 times in terms of speed, and in conjunction with a trading platform on pure trading transactions, where the minimum of language wrapping in 28 times.

Quick itself has no deep integration with the language, which is just tacked on the side. And MetaTrader 5 is built around meeting the needs of MQL5, when all the data is ready to be used in MQL5. Moreover, the LUA language was created as a binding between high-level calls, but not for calculation operations.


Write modules in C++ and then distribute them? Who will risk installing someone else's EXE/DLL in the trading environment?

But in MQL5 it is safe, because in MQL5 you get a safe code and almost the same speed as in C++.


Those who live in Quick do not know the concepts of real data.

When you can repeat the following code in LUA, come back to discuss "huge arrays":

Running cold, 17 million real RTS-9.17 ticks and 60,278 minute bars were produced in 2.6 seconds.

Unlimited data limits are used within the platform. This data is used for building indicators, analyses, etc.

This is exactly the data that MQL programmes operate with. And the terminal itself operates with such data in its work.

And you are talking about some tables.


You just do not know the language and its insides. That's why all languages are the same for you.

Do you realise that you are talking to a person who creates programming languages and fights for efficiency and productivity?

Do you realise who you are talking to?

When you were not even in the plans, the person you are talking to sported ansi C vax compiler on pdp-11.

I can't help myself: sheep.

You are paid money for writing all these tests and blowing snot in the ears of unsophisticated users. I will not write texts and participate in this show for free. 600 times faster. Hands wide, hands wide.

The fact that the loupe support is attached to the terminal on the side is right. It should be so (though we cannot say that the developers of Quick planned it: they had no other way). And the way your company is going - everything should be colourful, blinking, and closed in one ball - is doubtful. And the main thing - ponts, ponts...

"We wrote a tester, now you don't need amibroker and welslab." 600 times faster, too? Clowns.

"We can send 28 times more transactions than Quick. What the fuck for? For.
There's fix, it's also 28 times faster.

We can add 1+1 100 times faster. Even if that's the case (and it's not) why? Infrastructure bandwidth is still the determining factor. Do you drive a Ferrari faster from Khimki to Vidnoye than a Solaris?

All this is bubbles and chatter. PR to attract suckers. That's your target audience, though.



Block me already. Poetry writers.
MetaQuotes
Renat Fatkhullin | 5 Sep 2017 at 16:06

I guess you're too old to compete. Words don't win here.

Godspeed.

prostotrader
prostotrader | 5 Sep 2017 at 16:23

Shit, what does it matter how many times faster? !!!!

On FORTS, for example, for one login 30 transactions per second!!!!

It doesn't matter what MT5, what KVIC + brokers' networks leave much to be desired!

But what does not matter is the possibility of FULL-fledged trading on the exchange - Options + Futures + Currency + Spot!!!!.

There is not a single software on the market for full-fledged exchange trading by robots (LUA, QLUA - JUST BAD)!

MetaQuotes
Renat Fatkhullin | 5 Sep 2017 at 16:30
prostotrader:

Shit, what does it matter how many times faster? !!!!

On FORTS, for example, for one login 30 transactions per second!!!

Brokerage gateways have higher limits.

Even one broker's client can receive more than 30 transactions per second through MetaTrader 5. But it is clear that they will tolerate it up to some point.


Unfortunately, the Russian exchange cannot or does not want to radically upgrade and unify its system. Hence the dismal situation with trading technologies in the Russian sector for 20 years - no one wants to invest there.

Dmitriy Skub
Dmitriy Skub | 5 Sep 2017 at 16:34
prostotrader:

Shit, what does it matter how many times faster? !!!!

On FORTS, for example, for one login 30 transactions per second!!!

You can get up to 600 for an extra fee)))

LifeHack for trader: "Quiet" optimization or Plotting trade distributions LifeHack for trader: "Quiet" optimization or Plotting trade distributions
Analysis of the trade history and plotting distribution charts of trading results in HTML depending on position entry time. The charts are displayed in three sections - by hours, by days of the week and by months.
Cross-Platform Expert Advisor: Orders Cross-Platform Expert Advisor: Orders
MetaTrader 4 and MetaTrader 5 uses different conventions in processing trade requests. This article discusses the possibility of using a class object that can be used to represent the trades processed by the server, in order for a cross-platform expert advisor to further work on them, regardless of the version of the trading platform and mode being used.
Portfolio trading in MetaTrader 4 Portfolio trading in MetaTrader 4
The article reveals the portfolio trading principles and their application to Forex market. A few simple mathematical portfolio arrangement models are considered. The article contains examples of practical implementation of the portfolio trading in MetaTrader 4: portfolio indicator and Expert Advisor for semi-automated trading. The elements of trading strategies, as well as their advantages and pitfalls are described.
MQL5 Cookbook - Trading signals of moving channels MQL5 Cookbook - Trading signals of moving channels
The article describes the process of developing and implementing a class for sending signals based on the moving channels. Each of the signal version is followed by a trading strategy with testing results. Classes of the Standard Library are used for creating derived classes.