Single array calculation during optimisation

 

There is an array that does not change during the whole optimisation. Is it possible to calculate it once and only refer to it on each pass during the whole optimization without calculating it again?

 
So calculate it in OnInint()
 
Alexey Viktorov:
So calculate it in OnInint()

In MQL4 I was reading data from file in the inite, but it took a very long time. I don't know if the initeis used with each new pass or not?

I found it on the forum, each time the inite is used, i.e. the array will be recalculated.

https://www.mql5.com/ru/forum/104222

 

Of course not.

Oops... Didn't read carefully and misunderstood the question.

 
forexman77:

In MQL4 I was reading data from file in the inite, but it took a very long time. I don't know if the initeis used with each new pass or not?

I found it on the forum, each time the inite is used, i.e. the array will be recalculated.

https://www.mql5.com/ru/forum/104222

It's elementary. You check the size of the array at each run. If the array is empty or the calculation flag is false, you recalculate it:

if(ArraySize(optimize_array) == 0)
   CalculateArray();
 
Vasiliy Sokolov:

It's elementary. You check the size of the array every time you run it. If the array is empty or the calculation flag is false, you recalculate it:

I haven't checked it yet, though. But, I ask and that the array will be saved from the first pass (where it will be calculated) and will be available in subsequent passes?

 
forexman77:

I haven't tested it yet, though. But, I will ask and that the array will be saved from the first pass (where it will be calculated) and will be available for subsequent passes?

It will not. You have to recalculate it, or save it to a file and read it out.
 
Dmitry Fedoseev:
It won't. You have to recalculate it, or save it to a file and read it out.

So I have a dilemma: how to make it possible to read from a file once, fill an array with it and use this array on all passes.

I need it to reduce the optimization time, because the array will always remain unchanged and it will be expensive to read it every time.

 
forexman77:

So I have a dilemma: how to make it possible to read from a file once, fill an array with it and use this array on all passes.

I need this to reduce the optimization time, because the array will always be unchanged and it is expensive to read it every time.

In MT5 there is an event to start optimization, calculate array in it, save it to file and read it in the EA's init.
 

Resource attachment. Don't ask how. I didn't write the source code.

It will have to be read in the inite. But it won't be read from disk, but from memory. So, in fact, the array will be in memory.

 
Dmitry Fedoseev:
In MT5 there is an event to start optimization, in it calculate the array, save it to a file, and in the init of the EA read it.
Will I need to read it in the init on every pass?
Reason: