MT5 and speed in action - page 54

 
Roman:

OK, let me rephrase. Within mql is roughly possible, depending on processor clock speed.
What about PWM? -A pulse signal of constant frequency and variable duty cycle.
Doesn't it set a constant?

First, read what the WinAPI Sleep function is, and what it actually does

PS Windows is not a real time system

 
Slava:

First, read up on what the WinAPI Sleep function is and what it actually does

PS Windows is not a real time system

Ahem, what does WinAPI Sleep have to do with it?
When we're talking about microsecond slip
Individually, for your processor you can determine the timer frequency and calculate the number of repetitions.
So, you can write your own MicrosecondCount in mql, but what is the point? The standard one is enough.

MT5 и скорость в боевом исполнении
MT5 и скорость в боевом исполнении
  • 2020.10.10
  • www.mql5.com
MT5 - шустрая платформа. Но есть узкие горлышки, которые сводят на нет все старания быстрой торговли...
 
Roman:

Ahem, I'm embarrassed to ask, what does WinAPI Sleep have to do with it?
When we're talking about microsecond slip
Individually, for your processor, you can define the timer frequency and calculate the number of repetitions.
So, you can write your own MicrosecondCount in mql, but what is the point? The standard one is enough.

Your own pending slip without context switching will eat up your core 100%.

This is a creepy programming method. God forbid such code leaks into the marketplace.

 
Renat Fatkhullin:

Your waiting slip without context switching will eat up your core 100%.

It's a horrible programming method. God forbid such code leaks into the marketplace.

And no one denied that hardcore ))
If you show an example of context switching, maybe you can improve?

Here's the CPU load for µsSLEEP (µsRange), on VirtualBox with only 2 cores, 4 threads.
Miners do worse than that ))

cp

 

Forum on trading, automated trading systems and strategy testing

Libraries: Sequence

fxsaber, 2020.10.13 12:54

An example of an EA that will kill most VPS.
#include <fxsaber\Sequence.mqh> // https://www.mql5.com/ru/code/31446

#define  PRINT(A) Print(#A + " = " + (string)(A))

input datetime inFrom = D'2020.09.01'; // С какой даты анализировать историю

void OnInit()
{
  SEQUENCE Sequence; // Последовательный запуск расчетов
  
//  if (Sequence.Init()) // Раскомментируйте для последовательного выполнения.
  {
    MqlTick Ticks[];
    
    PRINT(CopyTicksRange(_Symbol, Ticks, COPY_TICKS_ALL, (long)inFrom * 1000));
    PRINT(TerminalInfoInteger(TERMINAL_MEMORY_USED));
    
    Sleep(10000); // Ждем освобождения CopyTicks-данных.
  }
}


I am running it on few charts of different symbols. I have used this script with inAmount = 5 to automate this action.


Result.

2020.10.13 13:26:53.199 Test9 (AUDCAD,H1)       CopyTicksRange(_Symbol,Ticks,COPY_TICKS_ALL,(long)inFrom*1000) = 5406953
2020.10.13 13:26:53.326 Test9 (AUDCAD,H1)       TerminalInfoInteger(TERMINAL_MEMORY_USED) = 2838
2020.10.13 13:26:53.528 Test9 (EURCHF,H1)       CopyTicksRange(_Symbol,Ticks,COPY_TICKS_ALL,(long)inFrom*1000) = 3430958
2020.10.13 13:26:53.807 Test9 (EURCHF,H1)       TerminalInfoInteger(TERMINAL_MEMORY_USED) = 3144
2020.10.13 13:26:53.924 Test9 (EURUSD,H1)       CopyTicksRange(_Symbol,Ticks,COPY_TICKS_ALL,(long)inFrom*1000) = 4244747
2020.10.13 13:26:54.214 Test9 (EURUSD,H1)       TerminalInfoInteger(TERMINAL_MEMORY_USED) = 3464
2020.10.13 13:26:54.344 Test9 (AUDCHF,H1)       CopyTicksRange(_Symbol,Ticks,COPY_TICKS_ALL,(long)inFrom*1000) = 4327679
2020.10.13 13:26:54.702 Test9 (AUDCHF,H1)       TerminalInfoInteger(TERMINAL_MEMORY_USED) = 3797
2020.10.13 13:26:54.864 Test9 (GBPCHF,H1)       CopyTicksRange(_Symbol,Ticks,COPY_TICKS_ALL,(long)inFrom*1000) = 5340006
2020.10.13 13:26:55.457 Test9 (GBPCHF,H1)       TerminalInfoInteger(TERMINAL_MEMORY_USED) = 4308
2020.10.13 13:26:55.666 Test9 (EURAUD,H1)       CopyTicksRange(_Symbol,Ticks,COPY_TICKS_ALL,(long)inFrom*1000) = 7730155
2020.10.13 13:26:55.756 Test9 (EURAUD,H1)       TerminalInfoInteger(TERMINAL_MEMORY_USED) = 4316

The Terminal requires more than 4 Gb of memory to run these six Expert Advisors. Please note that it is only needed for initialization, not for operation of these EAs. Imagine that you start the terminal with Expert Advisors dangling in it. If you don't have honest 4 Gb of RAM available - it's almost a disaster.


Now let's remove the comment of this line in the source code.

  if (Sequence.Init()) // Раскомментируйте для последовательного выполнения.

Thus, we have enabled sequential initialization of Expert Advisors.


Let's look at the result (after recompiling).

2020.10.13 13:27:24.002 Test9 (AUDCAD,H1)       CopyTicksRange(_Symbol,Ticks,COPY_TICKS_ALL,(long)inFrom*1000) = 5406980
2020.10.13 13:27:24.021 Test9 (AUDCAD,H1)       TerminalInfoInteger(TERMINAL_MEMORY_USED) = 1234
2020.10.13 13:27:35.407 Test9 (EURUSD,H1)       CopyTicksRange(_Symbol,Ticks,COPY_TICKS_ALL,(long)inFrom*1000) = 4244772
2020.10.13 13:27:35.422 Test9 (EURUSD,H1)       TerminalInfoInteger(TERMINAL_MEMORY_USED) = 1095
2020.10.13 13:27:46.886 Test9 (GBPCHF,H1)       CopyTicksRange(_Symbol,Ticks,COPY_TICKS_ALL,(long)inFrom*1000) = 5340072
2020.10.13 13:27:46.905 Test9 (GBPCHF,H1)       TerminalInfoInteger(TERMINAL_MEMORY_USED) = 1224
2020.10.13 13:27:58.293 Test9 (AUDCHF,H1)       CopyTicksRange(_Symbol,Ticks,COPY_TICKS_ALL,(long)inFrom*1000) = 4327724
2020.10.13 13:27:58.310 Test9 (AUDCHF,H1)       TerminalInfoInteger(TERMINAL_MEMORY_USED) = 1114
2020.10.13 13:28:09.683 Test9 (EURCHF,H1)       CopyTicksRange(_Symbol,Ticks,COPY_TICKS_ALL,(long)inFrom*1000) = 3430999
2020.10.13 13:28:09.696 Test9 (EURCHF,H1)       TerminalInfoInteger(TERMINAL_MEMORY_USED) = 1015
2020.10.13 13:28:21.339 Test9 (EURAUD,H1)       CopyTicksRange(_Symbol,Ticks,COPY_TICKS_ALL,(long)inFrom*1000) = 7730313
2020.10.13 13:28:21.363 Test9 (EURAUD,H1)       TerminalInfoInteger(TERMINAL_MEMORY_USED) = 1519


On the start of the Expert Advisors we have managed to reduce the Terminal memory consumption by more than 2.5 Gb. The probability of VPS crashes (and weak home computers) has decreased significantly.


This is how both runs look in dynamics.

The sequential launch stretched the overall initialization in time, but managed to keep the Terminal from consuming huge amounts of RAM.


Theupper and lower graphs clearly show the process of parallel initialization (left high peak) and six consecutive initializations (six middle peaks).


SZY During the experiments an unpleasant nuance with Sleep came to light - see source code.


I ask to somehow allow freeing memory by force after using CopyTicks. Not to create such Sleep crutches.

 
Please recommend the cheapest memory-consuming way to query the tick history at a given interval.
 
fxsaber:
Please recommend the cheapest way to request tick history at a given interval.

it sounds to me like you are not looking for a cheap one, but a way to free up memory quickly

as an option to check:

- wrap dynamic array MqlTick Ticks[] in class and create object with new (i.e. also dynamic object), delete it when you don't need it

- the same, but with structure, but in local scope ( or function or local block { } - or loop with one iteration ? ), structures do not work as well as classes - I rewrote most of my EA code moving away from classes and replacing them with data structures, optimization speed increased significantly - maybe it's a subjective effect - maybe new builds are faster

- try adding ArrayFree() to the destructor

 
Igor Makanu:

I don't think you're looking for a cheap one, but a way to free up memory quickly

The Terminal does not free up memory. MQL variables have nothing to do with it.

 
fxsaber:

The terminal is not freeing up memory. MQL variables have nothing to do with it.

What if you force size = 1 ?

what if you do^

MqlTick  Tick[];
MqlTick  ZeroTick[1] = {0};
.....
ArrayResize(Tick,1);
ArrayCopy(Tick,ZeroTick)
 
Igor Makanu:

and if

After calling CopyTicks, the terminal holds all data in memory for a few seconds. Just in case someone wants to re-read a piece of tick history.

I.e., the amount of memory so consumed by the Terminal does not depend on the size of MQL variables.


The task is to force the Terminal to release the memory.