Here is an example of writing and reading an array
Run it twice in debug mode and see how long it takes to write and read the array. The first run will write the array to file, and the second will read it and start printing dates from the array. Then figure out the highlighted part, if IS_DEBUG_MODE should be removed, and if IsOptimization() should be inserted in the condition.
There is a function, something like FileWriteInteger(). Identify by location, the variable must be at the beginning of the file, after reading it the pointer will move to its end, i.e. to the beginning of the array, after reading the array the pointer will be before the next variable...
An article on working with files will be published soon.
I wanted to write you that there is no article on file operations. You make them informative and lucid. I'll certainly read them when they appear.
When unset at start, it prints date 1971, i.e. array is empty
for (int x=0;x<=39;x++)
{
Print("T[x]=",T[x],"x=",x);
}
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?
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 do wrong?
Look what the compiler says.
ArrayResize(T,40);
datetime T[40]=
With such an easy move, you have defined a local array T that will vanish on exit of OnInit...
With such an easy move, you have defined a local array T that will be lost when you exit OnInit...
It says there is already a global declaration)
declaration of 'T' hides global declaration at line 40
But, how to do it right. I had never declared an array using curly brackets before. I initialized it with zero and set its size and then filled it with the loop. Is there some other way to do it?
If I clear the datetime in the inite, the code does not compile, but writes two errors:
declaration of 'T' hides global declaration at line 40
But, how to do it right. I had never declared an array using curly brackets before. I initialized it with zero and set its size and then filled it with the loop. Is there some other way to do it?
If I clear the datetime in the inite, the code does not compile, but writes two errors:
'{' - expression expected
'=' - illegal operation use
The array declaration together with constant initialization could (and should) be done at the global level.
declaration of 'T' hides global declaration at line 40
But, how to do it right. I had never declared an array using curly brackets before. I initialized it with zero and set its size and then filled it with the loop. Is there some other way to do it?
If I clear the datetime in the inite, the code does not compile, but writes two errors:
'{' - expression expected
'=' - illegal operation use
With '=' you may initialize arrays only when declaring them. It seems to be a remnant of C, but that's how it is done here :-)
The array declaration along with constant initialization could (and should) have been done at the global level.
Yes, I tried it and it works. And you can't do it without global level, I just did it to reduce the computational cost, to fill the array once in the init and then use the array values?
Although logically, the variables on the global level are always constant, so the calculation is performed once at the beginning of the program?
Yes, I tried it and it works. And you can't do it without global level, I just did it to reduce the computational cost, to fill the array once in the init and then use the array values?
Although logically the variables on the global level are always constant, so the calculation is performed once at the beginning of the program?
Yes, when preparing an ex4 ex5 binary for execution by the terminal. You can think that it's just links to the data array described (and saved inside ex4/5 at compile time), and that's very fast...
declaration of 'T' hides global declaration at line 40
But, how to do it right. I had never declared an array using curly brackets before. I initialized it with zero and set its size and then filled it with the loop. Is there some other way to do it?
If I clear the datetime in the inite, the code does not compile, but writes two errors:
'{' - expression expected
'=' - illegal operation use
It doesn't really matter how the array is filled. You simply have to set a condition whereby if the array's size is zero, it should be evaluated, filled and written into a file. And in OnInit(), try to read into the declared array using my example. Accordingly, if there is a file array, it is read, and the array is filled, the array will not be recalculated and filled again.
Here is an example of writing and reading an array
Run it twice in debug mode and see how long it takes to write and read the array. The first run will write the array to file, and the second will read it and start printing dates from the array. Then figure out the highlighted part, if IS_DEBUG_MODE should be removed, and if IsOptimization() should be inserted in the condition.
There is a function, something like FileWriteInteger(). Identify by location, the variable must be at the beginning of the file, after reading it the pointer will move to its end, i.e. to the beginning of the array, after reading the array the pointer will be before the next variable...
An article on working with files will be published soon.
I wanted to write you that there is no article on file operations. You make them informative and lucid. I'll certainly read them when they appear.
Tried to declare an array at global level (mql4 code)
datetime T[];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 do wrong?
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 do wrong?
Look what the compiler says.
With such an easy move, you have defined a local array T that will vanish on exit of OnInit...
check the warning that the compiler generates.
With such an easy move, you have defined a local array T that will be lost when you exit OnInit...
It says there is already a global declaration)
declaration of 'T' hides global declaration at line 40
But, how to do it right. I had never declared an array using curly brackets before. I initialized it with zero and set its size and then filled it with the loop. Is there some other way to do it?
If I clear the datetime in the inite, the code does not compile, but writes two errors:
'{' - expression expected
'=' - illegal operation use
It says there is already a global declaration)
declaration of 'T' hides global declaration at line 40
But, how to do it right. I had never declared an array using curly brackets before. I initialized it with zero and set its size and then filled it with the loop. Is there some other way to do it?
If I clear the datetime in the inite, the code does not compile, but writes two errors:
'{' - expression expected
'=' - illegal operation use
The array declaration together with constant initialization could (and should) be done at the global level.
It says there is already a global declaration)
declaration of 'T' hides global declaration at line 40
But, how to do it right. I had never declared an array using curly brackets before. I initialized it with zero and set its size and then filled it with the loop. Is there some other way to do it?
If I clear the datetime in the inite, the code does not compile, but writes two errors:
'{' - expression expected
'=' - illegal operation use
The array declaration along with constant initialization could (and should) have been done at the global level.
Yes, I tried it and it works. And you can't do it without global level, I just did it to reduce the computational cost, to fill the array once in the init and then use the array values?
Although logically, the variables on the global level are always constant, so the calculation is performed once at the beginning of the program?
Yes, I tried it and it works. And you can't do it without global level, I just did it to reduce the computational cost, to fill the array once in the init and then use the array values?
Although logically the variables on the global level are always constant, so the calculation is performed once at the beginning of the program?
It says there is already a global declaration)
declaration of 'T' hides global declaration at line 40
But, how to do it right. I had never declared an array using curly brackets before. I initialized it with zero and set its size and then filled it with the loop. Is there some other way to do it?
If I clear the datetime in the inite, the code does not compile, but writes two errors:
'{' - expression expected
'=' - illegal operation use