Single array calculation during optimisation - page 7

 
forexman77:

Tried to declare an array at global level (mql4 code)

fill it in the inite

When unset at start, it prints date 1971, i.e. array is empty

If I fill the array in the start, the values appear. May be the reason, that the array is re-initialized datetaime, but without it the code won't compile?

The array disappears. What I'm doing wrong?

Here I have an idea, if someone needs it too. I copied one array into another.

datetime T_[];//на глобальном уровне
//////////////////////////////////////////////////////////////////
int init()
  {
   ArraySetAsSeries(T_,true);
   massiv();

   return(0);
  }
/////////////////////////////////////////////////////////////////
int start()
  {
   if(ArraySize(T_)==0)
   massiv();

  return(0);  
  }
////////////////////////////////////////////////////////////////
void massiv()
  {
   datetime T[40]=
   {
   1262731020,1262735700,1262821920,1262903400,1262989740,1263247200,1263339060,1263420000,1263507480,1263595500,
   1265324700,1265407200,1265752980,1265926500,1265930820,1267657200,1267740300,1267826460,1268175840,1268346360,
   1270504920,1270684140,1270768500,1272924180,1273011720,1273097100,1273272240,1273528800,1273617180,1275344100,
   1275516000,1275602400,1275689160,1276034400,1276124580,1276208700,1276211640,1278027960,1278369780,1278373920
   };
   ArraySetAsSeries(T,true);
   ArrayInitialize(T_,0);
   ArrayResize(T_,40);
   ArrayCopy(T_,T,0,0,WHOLE_ARRAY);
   ArrayFree(T);
  }
 
forexman77:

Here's an idea, if anyone needs it too. Copying one array into another.

What is this for?

The original question was so that the array would not be recalculated in subsequent iterations of optimization. Now it is simply filled and copied into the other one. It won't do any good. I take it that this array T[40] is represented in this way only for illustration purposes, while it should in fact be calculated and filled sequentially. Each next optimization run will recalculate this array as before, the only difference is that it is organized differently.

 
Alexey Viktorov:

What is it for?

The original question was so that the array would not be recalculated in subsequent iterations of optimization. And now it is simply filled and copied into another one. It won't do any good. I take it that this array T[40] is represented in this way only for illustration purposes, while it should in fact be calculated and filled sequentially. With each next optimization run, this array will be recalculated the way it was before, the only difference being that it is arranged differently.

The array declared through curly braces was not saved; it could not be declared globally and then filled in the inite (the array was not saved inside one run).

Between iterations of optimization, as I understand it, the array is not saved, that is, the program resets everything that was.

 
forexman77:

The array declared with curly braces was not saved, it could not be declared globally and then filled in the inite (the array was not saved within one run).

Between iterations of optimization, as I understand it, the array is not saved, that is, the program resets everything that was.

It won't take long to fill it in the loop like that. But it's another issue, if calculating array items takes a long time. If that's the case, it won't help. The array elements will still be recalculated at each iteration. And if the array is filled this way, you can also globally enumerate all elements in curly brackets. I don't understand the point of this wizardry...
 
Alexey Viktorov:
And if the array is filled in this way, you can also list all elements in curly brackets at global level. something I don't understand the point of this wizardry...
You can do it globally too. But, I don't like to have a tower of several thousand elements on top there)
 
forexman77:
You could do it on a global one. But I didn't like the idea of building a tower of several thousand elements on top of it.)

Thank God it all worked out the way you wanted it to.

Has the speed gone up?

 
Alexey Viktorov:

Thank God it all worked out the way you wanted it to.

Has the speed gone up?

It's getting faster.
 

I didn't create a new topic.

Now I'm trying to do the following: there is an array with first value date, second and third numbers double. I need to sort the array by date, but I want the second and third values to be bound to the date.

Then I plan to clump several arrays into one and sort them by date.

I tried to do it this way, but as far as I understand, sorting is performed by array index, i.e. by i.

double m[215][3];
m[i][0]=Data;
m[i][1]=f1;
m[i][2]=f2;
 
forexman77:

I didn't create a new topic.

Now I'm trying to do the following: there is an array with first value date, second and third numbers double. Need to sort the array by date value, but have the second and third values tied to the date.

...

See here:https://www.mql5.com/ru/forum/42036
Сортировка двухмерного массива.
Сортировка двухмерного массива.
  • www.mql5.com
Форум трейдеров MQL5.community
 
Anatoli Kazharski:
Look here:https://www.mql5.com/ru/forum/42036

It's mostly all on classes, which are a dark forest to me. But, some thoughts have come up. Make an array with dates and numbers separately. Only, how to get the index number where the dates are after sorting, i.e. get the i which is in the second dimension?

datetime m[215][1];
double d[215][2];

m[0][i]=Dat_DtTm;
d[i][0]=f1;
d[i][1]=f2;
Reason: