Features of the mql5 language, subtleties and tricks - page 139

 
fxsaber:

This option does not work

Corrected the code, now it's OK.
 
Alexey Navoykov:
Corrected the code, everything is ok now.

Something you posted with an error, as it doesn't compile at all.

 
fxsaber:

Something you posted with an error, as it doesn't compile at all.

Yes, it's a typo. Corrected it.
 
Alexey Navoykov:
Yes, it's a typo. Corrected.

Thank you, it works. Remains to be seen the effect on performance.

 
For those who use dynamic resources (e.g., Kanvas), I recommend speeding up array populations in this way

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

fxsaber, 2019.07.09 18:36

void FillArray1( int &Array[] )
{
  const int Size = ArraySize(Array);
  
  for (int i = 0; i < Size; i++)
    Array[i] = i;
}

#define  ARRAY_SIZE 10000

void FillArray2( int &Array[] )
{
  int ArrayStatic[ARRAY_SIZE];
  
  const int Size = ArraySize(Array);
  
  for (int i = 0; i < Size;)
  {
    const int Size2 = i + ARRAY_SIZE < Size ? ARRAY_SIZE : Size - i;
    
    for (int j = 0; j < Size2; j++)
      ArrayStatic[j] = i++;
      
    if (Size2)
      ArrayCopy(Array, ArrayStatic, i - Size2, 0, Size2);
  }
}

#define  BENCH(A)                                                               \
{                                                                              \
  const ulong _StartTime = GetMicrosecondCount();                              \
  A;                                                                           \
  Print("Time[" + #A + "] = " + (string)(GetMicrosecondCount() - _StartTime)); \
}

void OnStart()
{
  int Array1[];
  ArrayResize(Array1, 1 e7);

  int Array2[];
  ArrayResize(Array2, 1 e7);
  
  BENCH(FillArray1(Array1));
  BENCH(FillArray2(Array2));
}
Acceleration by tens of percent.

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

fxsaber, 2019.07.09 19:40

Time[FillArray1(Array1)] = 39501
Time[FillArray2(Array2)] = 30304

Release version is running. Optimization enabled.


Found optimal static array size by experience

#define  ARRAY_SIZE 256
 
fxsaber:
For those who use dynamic resources (e.g., Kanvas), I recommend speeding up filling arrays in the following way
An acceleration of tens of percent.


I found the optimal size of a static array through experimentation.

And if you compare it withArrayFill from mql5, will there be a speed gain or not?

 

I haven't read the whole topic, maybe there is an answer to this question, MT5 doesn't understandably behave with graphical objects, the terminal is closed for some time and the objects remain attached to some obscure points. How do you deal with this? It's not difficult to do in those cases when a chart window is open. I personally add a transition to OnDeinit in OnInit(), but if the window is bookmarked it doesn't solve the problem. Maybe someone will tell us where we can "voice" the suggestions to the creators of MT5.

.

 
Alexander Lasygin:

I haven't read the whole topic, maybe there is an answer to this question, MT5 doesn't understandably behave with graphical objects, the terminal is closed for some time and the objects remain attached to some obscure points. How do you deal with it? It's not difficult to do in those cases when a chart window is open. I personally add a transition to OnDeinit in OnInit(), but if the window is bookmarked it doesn't solve the problem. Maybe someone will tell us where we can "voice" the suggestions to the creators of MT5.

.

Provide exact data to reproduce: e.g. a chart template with objects.

I suspect that the objects are drawn by the indicator, and it is the indicator that incorrectly tracks prev_calculated.

 
Konstantin:

and if you compare it toArrayFill from mql5, will there be a speed gain or not?

I don't think there will be.

 
fxsaber:

I don't think it will.

so why reinvent your own lisepad when there is already a productive function?

Reason: