How do I move the global variable structure in the indicator when moving to another timeframe? - page 5

 
fxsaber:

If you write a performance measurement, it would be interesting to compare.

Okay. Go ahead. Just implement your part yourself.
Here is my part.
I suggest the following test indicator from the ball (marked yellow is what is responsible for saving and restoring the array structure between TFs):
When first called, the array of random nodes (100 by default) within the window is generated and connected by Bezier curve.
When the TF is changed, the nodes linked to time and price are saved and not changed.
For better metering, it is better to make the number of nodes 1000

#property indicator_chart_window
#include <Canvas\iCanvas.mqh> //https://www.mql5.com/ru/code/22164
#include <CVar\StructArr.mqh>
#define  SIZE 100

struct Node {
   datetime time;
   double price;
};
Node line[];

ulong t0 = GetMicrosecondCount();
CStructArr<Node> Var("Bezier",line);
ulong t1=GetMicrosecondCount()-t0;

int OnInit() {
   if (ArraySize(line) == 0) GenerateLine();
   else {
      Print("Востановление данных - " + string(t1)+ " микросекунд");
      Print("Время uint[] -> T[] - " + string(Var.uint_to_t)+ " микросекунд");
   }
   DrawBezier(line);
   return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[]) {
   return(rates_total);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void GenerateLine() {
   ArrayResize(line,SIZE);
   for (int i = 0; i<SIZE; i++) {
      line[i].time = Canvas.TimePos(double(rand() % W.Width));
      line[i].price = Canvas.Price(rand() % W.Height);
   }
   t0 = GetMicrosecondCount();
   Var.Set(line);
   t0 = GetMicrosecondCount()-t0;
   Print("Сохранение данных - " + string(t0)+ " микросекунд");
   Print("Время T[] -> uint[] - " + string(Var.t_to_uint)+ " микросекунд");
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DrawBezier(Node &arr[]) {
   int size = ArraySize(arr);
   if (size>1) {
      Canvas.Erase(0x00FFFFFF);
      int X[],Y[];
      ArrayResize(Y,size);
      ArrayResize(X,size);
      for(int i=0; i<size; i++) {
         X[i] = (int)Canvas.X(line[i].time);
         Y[i] = (int)Canvas.Y(line[i].price);
      }
      Canvas.PolylineSmooth(X,Y,0xFFFF00FF,3);
      Canvas.Update();
   }
}
//+------------------------------------------------------------------+

2021.07.11 04:41:02.705 TestVar (EURUSD,M6)     Сохранение данных - 15 микросекунд
2021.07.11 04:41:02.705 TestVar (EURUSD,M6)     Время T[] -> uint[] - 4 микросекунд
2021.07.11 04:42:03.085 TestVar (EURUSD,M10)    Востановление данных - 317 микросекунд
2021.07.11 04:42:03.085 TestVar (EURUSD,M10)    Время uint[] -> T[] - 4 микросекунд
2021.07.11 04:42:10.012 TestVar (EURUSD,M12)    Востановление данных - 878 микросекунд
2021.07.11 04:42:10.012 TestVar (EURUSD,M12)    Время uint[] -> T[] - 4 микросекунд
2021.07.11 04:42:44.235 TestVar (EURUSD,M30)    Востановление данных - 1061 микросекунд
2021.07.11 04:42:44.235 TestVar (EURUSD,M30)    Время uint[] -> T[] - 8 микросекунд
2021.07.11 04:43:20.556 TestVar (EURUSD,M20)    Востановление данных - 303 микросекунд
2021.07.11 04:43:20.556 TestVar (EURUSD,M20)    Время uint[] -> T[] - 4 микросекунд
2021.07.11 04:43:25.339 TestVar (EURUSD,M15)    Востановление данных - 443 микросекунд
2021.07.11 04:43:25.339 TestVar (EURUSD,M15)    Время uint[] -> T[] - 5 микросекунд


with SIZE = 1000:

2021.07.11 05:01:32.602 TestVar (EURUSD,M5)     Сохранение данных - 41 микросекунд
2021.07.11 05:01:32.602 TestVar (EURUSD,M5)     Время T[] -> uint[] - 26 микросекунд
2021.07.11 05:01:36.541 TestVar (EURUSD,M6)     Востановление данных - 586 микросекунд
2021.07.11 05:01:36.541 TestVar (EURUSD,M6)     Время uint[] -> T[] - 64 микросекунд
2021.07.11 05:01:38.317 TestVar (EURUSD,M10)    Востановление данных - 648 микросекунд
2021.07.11 05:01:38.317 TestVar (EURUSD,M10)    Время uint[] -> T[] - 35 микросекунд
2021.07.11 05:01:40.534 TestVar (EURUSD,M12)    Востановление данных - 567 микросекунд
2021.07.11 05:01:40.534 TestVar (EURUSD,M12)    Время uint[] -> T[] - 36 микросекунд
2021.07.11 05:01:42.814 TestVar (EURUSD,M15)    Востановление данных - 449 микросекунд
2021.07.11 05:01:42.814 TestVar (EURUSD,M15)    Время uint[] -> T[] - 44 микросекунд
2021.07.11 05:01:45.015 TestVar (EURUSD,M20)    Востановление данных - 728 микросекунд
2021.07.11 05:01:45.015 TestVar (EURUSD,M20)    Время uint[] -> T[] - 59 микросекунд
2021.07.11 05:01:47.536 TestVar (EURUSD,M30)    Востановление данных - 2349 микросекунд
2021.07.11 05:01:47.536 TestVar (EURUSD,M30)    Время uint[] -> T[] - 45 микросекунд
Files:
TestVar.mq5  6 kb
StructArr.mqh  3 kb
 

For MQL it would be great to have some kind of pointer for global indicator variables. They would be initialized once and only when installing the indicator.

For example:
int global Var;

. In this case we won't need all these resources. Let's stop dreaming and move on.

 
Nikolai Semko:

Here's my piece.

        array out of range in 'iCanvas.mqh' (114,55)
 
Mikhail Nazarenko:

For MQL it would be great to have some kind of pointer for global indicator variables. They would be initialized once and only when installing the indicator.

For example:
int global Var;

. In this case we won't need all these resources. Let's stop dreaming and move on.

Besides PersistentStorage, ServerSideStorage would be nice (to store even little things on server side) and AuthorOwnedCloud (to let some data be managed by author)... but it's something from 21st century :-).

Dream on, that's enough...

 
Nikolai Semko:

When the TF changes, the nodes linked to time and price are retained and do not change.

Is this a statistically significant measure of array casting?

 
Taras Slobodyanik:

:)

It's strange that no one writes about "crutches", "reinvention of a wheel", "difficulties of data transfer to another terminal","the problem must be solved by MQL means "...
It turns out that metaquot solutions are crutches and mauvais ton)


Where is this solution from MQ ?
 

fxsaber:

  array out of range in 'iCanvas.mqh' (114,55)


You seem to have an outdated version.
latest version 1.43
https://www.mql5.com/ru/code/22164

Files:
iCanvas.mqh  52 kb
 
fxsaber:

Is this a statistically significant measure of array casting?

no one is stopping you from making your own adjustments.

HH
And please don't start talking about strings.
In this type of tasks they are irrelevant, that's why they are not implemented in my class and my structure cannot contain string type.
I know they are implemented in your class. But we are talking about something else.

 
PapaYozh:

Where is this solution from MQ ?

Yes, of course, these solutions don't exist at all.

So users invent "crutch-bikes" -FileWriteStruct and GlobalVariableSet.
And the most crutch-free solutions, of course, are writing variables to resources, plus writing structures to global variables)

 
Nikolai Semko:

You seem to have an outdated version.
latest version 1.43
https://www.mql5.com/ru/code/22164

This version is the one that gave you the error.