MT5 and speed in action - page 44

 
fxsaber:

More than once I've seen situations when Terminal loads the CPU 100% so much that it doesn't react to anything.

Then I looked at the logs and saw that there were wild skips of ticks in OnTick. However, if I correctly write an EA, this disastrous situation will not affect the trading results. I analyzed it specifically, everything is clear.

I wonder how widespread mechanisms for dealing with delays in Market Products are. I've never once seen any mention of machine power to run. Minimum ping is a yes.

Where were you launching them?

If on VPS for 2-5 dollars, then delays in tens and hundreds of milliseconds are easily caught in any hardly serious WinAPI function. Everything slows down starting from hypervisor level, turning a virtual machine into a slide show.

Explained above.

 
Renat Fatkhullin:

It is not GetMicrosecondsCount that is slowing down, it is the OS that is quantifying CPU resources for any thread in your strangled VPS. For any function, any action, any program inside your UPU.

Well, no CPU shell can slice and allocate resources fairly when it has 20 (that's still respectable) operating systems with 1500 threads of execution per copy. Take 8-16 cores and distribute them over 20 * 1,500 = 30,000 (thirty thousand physical tracks).

In my case (virtual box with vin7 + 2 cores + 16 GB of RAM on entirely my own hardware with nothing else running), where does periodic 2-3 µs come from?

Forum on trading, automated trading systems and trading strategy testing

MT5 and Speed in Combat

Andrey Khatimlianskii, 2020.10.05 10:19

Not really a UPU, but a virtual machine on rented hardware:

2020.09.29 00:11:11.350 Terminal        MetaTrader 5 x64 build 2615 started for MetaQuotes Software Corp.
2020.09.29 00:11:11.352 Terminal        Windows 7 Service Pack 1 build 7601 on Virtual Box, Intel Core i7-4770  @ 3.40 GHz, 14 / 15 Gb memory, 4 / 31 Gb disk, IE 11, Admin, GMT+2
2020.10.05 11:11:25.340 test (GBPUSD,M15)       Alert: Time[test.mq5 7 in OnTimer: GetMicrosecondCount()] = 2 mсs.
2020.10.05 11:11:31.308 test (GBPUSD,M15)       Alert: Time[test.mq5 7 in OnTimer: GetMicrosecondCount()] = 2 mсs.
2020.10.05 11:12:34.699 test (GBPUSD,M15)       Alert: Time[test.mq5 7 in OnTimer: GetMicrosecondCount()] = 3 mсs.
2020.10.05 11:13:04.388 test (GBPUSD,M15)       Alert: Time[test.mq5 7 in OnTimer: GetMicrosecondCount()] = 2 mсs.
2020.10.05 11:13:58.116 test (GBPUSD,M15)       Alert: Time[test.mq5 7 in OnTimer: GetMicrosecondCount()] = 2 mсs.
2020.10.05 11:14:08.388 test (GBPUSD,M15)       Alert: Time[test.mq5 7 in OnTimer: GetMicrosecondCount()] = 2 mсs.
2020.10.05 11:14:14.975 test (GBPUSD,M15)       Alert: Time[test.mq5 7 in OnTimer: GetMicrosecondCount()] = 2 mсs.
2020.10.05 11:14:19.095 test (GBPUSD,M15)       Alert: Time[test.mq5 7 in OnTimer: GetMicrosecondCount()] = 2 mсs.
2020.10.05 11:15:28.814 test (GBPUSD,M15)       Alert: Time[test.mq5 7 in OnTimer: GetMicrosecondCount()] = 2 mсs.
2020.10.05 11:15:55.814 test (GBPUSD,M15)       Alert: Time[test.mq5 7 in OnTimer: GetMicrosecondCount()] = 2 mсs.
2020.10.05 11:15:56.814 test (GBPUSD,M15)       Alert: Time[test.mq5 7 in OnTimer: GetMicrosecondCount()] = 2 mсs.
2020.10.05 11:16:27.818 test (GBPUSD,M15)       Alert: Time[test.mq5 7 in OnTimer: GetMicrosecondCount()] = 9 mсs.
2020.10.05 11:16:35.275 test (GBPUSD,M15)       Alert: Time[test.mq5 7 in OnTimer: GetMicrosecondCount()] = 2 mсs.
2020.10.05 11:16:45.775 test (GBPUSD,M15)       Alert: Time[test.mq5 7 in OnTimer: GetMicrosecondCount()] = 27 mсs.
2020.10.05 11:16:51.715 test (GBPUSD,M15)       Alert: Time[test.mq5 7 in OnTimer: GetMicrosecondCount()] = 2 mсs.
2020.10.05 11:17:30.477 test (GBPUSD,M15)       Alert: Time[test.mq5 7 in OnTimer: GetMicrosecondCount()] = 5 mсs.
2020.10.05 11:18:25.081 test (GBPUSD,M15)       Alert: Time[test.mq5 7 in OnTimer: GetMicrosecondCount()] = 2 mсs.

 
Andrey Khatimlianskii:

In my case (virtual box with win7 + 2 cores + 16GB of RAM on its own hardware with nothing else spinning), where does the periodic 2-3 µs come from?

That's the price of dual virtualisation.

Especially since VirtualBox is not a full-fledged Hyper-V type hypervisor, but lives on top of your current desktop operating system (Windows 7 also?) which has a CPU shell ground up for a different use case.

So, you have: Windows 7/10 -> VirtualBox -> Windows 7. Essentially, two levels of virtualization, with the first being unaware of VirtualBox's aspirations, seeing it as just a regular program. The CPU resource allocation(the threadsheduler) is clearly screwed up.

It should be: Hyper-V 2016/2019 -> Windows 2016/2019

 
Renat Fatkhullin:

It is not GetMicrosecondsCount that is slowing down, it is the OS that is quantifying CPU resources for any thread in your strangled VPS. For any function, any action, any program inside your UPU.

I think an argument like this will get you thinking. Advisor.

#include <fxsaber\Benchmark\Benchmark.mqh> // https://www.mql5.com/ru/code/31279

// Сделал действия по этой ссылке: https://www.mql5.com/ru/forum/342090/page41#comment_18597040

void OnStart()
{
  _BV(
  for (int i = 0; i < 1 e6; i++)
    GetMicrosecondCount();
      , 1)
      
  _BV(
  for (int i = 0; i < 1 e6; i++)
    GetTickCount();
      , 1)      
}



2020.10.06 00:24:26.779 Alert: Time[Test6.mq5 52: for(inti=0;i<1 e6;i++)GetMicrosecondCount();] = 16289902 mсs.
2020.10.06 00:24:26.784 Alert: Time[Test6.mq5 57: for(inti=0;i<1 e6;i++)GetTickCount();] = 4300 mсs.


So far from slowing everything down. That's why I was able to change to winmm::timeBeginPeriod(1)+winmm::timeGetTime() quite harmlessly, getting speed like GetTickCount, but without the dreaded 16 ms limit. However, Market-producers are not allowed to do this, as it's a DLL. You're unlikely to make a millisecond regular version.

 
Renat Fatkhullin:

The MQL5 function to minimise all windows and the application itself is a great idea. We will work on that.

Here's another thing.

terminal on a VPS, then he will be strongly opposed to having everything abruptly rolled over. He can and should minimize windows himself if he leaves the RDP session.

I am currently using WinAPI to minimize by hotkey. Very convenient and much more harmless than the standard TerminalClose.
 
Renat Fatkhullin:


Here is an example of what I wanted to say.
Both servers are different brokers, are in the same area, can be in the same location.
The service card suggests for AMP to be located in the UK.
And for Just for some reason offers in NL.
Why? If there is a closer vpc.

dfgh

jt

 
fxsaber:

I think you'll find that's an argument that will get you thinking. Counsellor.


So far from slowing things down. That's why I was able to change to winmm::timeBeginPeriod(1)+winmm::timeGetTime() quite harmlessly, getting speed like GetTickCount, but without the dreaded 16ms limit. However, Market-producers are not allowed to do this, as it's a DLL. It's unlikely you'll be doing a millisecond regular version.

Well you're a master of racing stress tests with no correlation or reasonableness control.

Of course microsecond metering requires resources to be able to measure intervals 1000 times smaller than a millisecond.

If you occasionally need to measure intervals extra accurately, then use microseconds. And it will cost you 0 microseconds.

If you're set up to call millions of times self-measurement, you're probably engaging in self-delusion.


On a stifled VPS, overclocking the system timer via timeBeginPeriod is risky. You'll just increase your CPU overhead:

This function affects a global Windows setting. Windows uses the lowest value (that is, highest resolution) requested by any process. Setting a higher resolution can improve the accuracy of time-out intervals in wait functions. However, it can also reduce overall system performance, because the thread scheduler switches tasks more often. High resolutions can also prevent the CPU power management system from entering power-saving modes. Setting a higher resolution does not improve the accuracy of the high-resolution performance counter.

Otherwise, the operating system would have long ago made GetTickCount/GetTickCount64 precise and rejoiced at free precision. But no, you will have to pay for the accuracy of this timer.

 
Please remove theCHART_IS_MAXIMIZED brakes. The WinAPI solution is now not an order of magnitude faster than the stock solution.
 
Roman:

Here is an example of what I wanted to say.
Both servers are from different brokers, are in the same area, may be in the same location.
The service card suggests for AMP to be located in the UK.
And for Just for some reason offers in NL.
Why? If there is a PSTN closer.

We know geo-points of the servers, and here positions of broker servers build from GeoIP bases.

And it often happens that the information does not correspond to reality. Therefore we should never assume that the broker's position is accurate.

We will look into this in more detail tomorrow, because we need to manually double-check and re-scan everything to answer the question.

 
Renat Fatkhullin:

That's the price of dual virtualisation.

Especially since VirtualBox is not a full Hyper-V type hypervisor, but lives on top of your current desktop operating system (Windows 7 as well?) which has a CPU shell tailored for a different use case.

So, you have: Windows 7/10 -> VirtualBox -> Windows 7. Essentially, two levels of virtualization, with the first being unaware of VirtualBox's aspirations, seeing it as just a regular program. The CPU resource allocation(the threadsheduler) is clearly screwed up.

It should be: Hyper-V 2016/2019 -> Windows 2016/2019

No, I've got virtualisers spinning around on my CentOS. But I'm not competent to continue this dialogue.