[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 306

 
drknn:

An "infinite" length array can be declared in an indicator. Declare it and then in the loop immediately write the found values into the array. The only question is how to transfer the necessary selection to the Expert Advisor/Script? There are some tools, but we need to assess the complexity. Maybe it would really be easier to do 2 runs - in the first one we calculate the number of filtered values, then change the dimension of the array, and in the second one we enter the values into the array?

Thanks, but the variant with the indicator is not suitable - before passing the obtained sample to the Expert Advisor, there is a problem with passing sample conditions from the Expert Advisor to the indicator.
 
PapaYozh:

Declare an array bigger than the maximum required size.


Exactly :) It will work if we increase the size many times over. For example, we know in advance that the number of filtered values cannot exceed one thousand. Let's declare array of several thousand cells and we're done :)

But it will take some of the necessary memory. :(

 
drknn:


Exactly :) It will work if we increase the size many times over. For example, we know in advance that the number of filtered values cannot exceed one thousand. Let's declare array of several thousand cells and we're done :)

But it will take some of the necessary memory. :(


If "we know beforehand that the number of filtered values can't exceed one thousand", it's enough to declare array with size 1000.
 
splxgf:

https://docs.mql4.com/ru/math/MathPow no? Or elementary operations are a condition of the problem. Then option http://bpascal.ru/download/desc/436.php if you do everything by hand, then implement exponent and logarithm with your own functions.

Yes, exactly according to the condition. Thanks for the link, that's exactly what I need!
 
Elenn:
Good afternoon, some advice: The loop searches for values that satisfy certain conditions. The found values are written to an array. It is not known in advance how many values will be found. Therefore, the size of the array to be declared is unknown. From the point of view of time and resources, I'd rather not make two runs (so that I could count the number of found values in the first run, declare the array and write data into the array in the second one). Is there any way to get the required result in one run?
You can increase the size of the array by one cell for each value found. But this is not very fast. You can optimize by increasing the size by several cells, and then skip the resizing for several iterations.
 
PapaYozh:

If you "know in advance that the number of filtered values cannot exceed one thousand", you can just declare an array of size 1000.


But what about a contingency plan in case of force majeure? Would you write code that informs about an error and blocks the Expert Advisor? Well, a person might not see it - well, he was just at work at that moment.

Yes, indeed, there is more than one solution to the problem. I think the best solution is the one suggested by Zhunko - dynamically increase the dimensionality of the array inside the filtering loop. Frankly speaking, I am delighted with this answer. It never occurred to me :)

 
drknn:


I think the best one would still be the one suggested by Zhunko - dynamically increase the dimensionality of the array inside the filtering loop. Honestly, I'm delighted with that answer. It never occurred to me :)

The solution is really original, I should try it. But when re-declaring the array, won't the data be lost due to re-initialization?
 
Elenn:
The solution is really original, we should try it. But when you re-declare the array, won't the data be lost due to re-initialization?

I often do this. I create some initial array. Then (if necessary) I maximize it by some value (one cannot, it takes too long to perform array operations) and just check the size of the actually filled array in my work. So far, there have been no problems
 
Vinin:

Array operations take too long to complete
Are any array operations long, or only certain ones?
 
Elenn:
Does it take a long time to perform any array operations or only certain ones?

Especially resizing an array. Better to do them as infrequently as possible
Reason: