MT4 iMAOnArray and iBandsOnArray effect of number of elements on calculations

 

This is the question. If I don't need to calculate the whole array, but only the last N elements.

I don't quite understand the logic of calculating these functions when limiting. I have a timeseries array (one of the indicator buffers), if I leave the number of elements equal to 0, no questions, everything is counted and calculated, but if I decrease the number of elements involved in the calculation by the same offsets, I get only the primary ones. Simply speaking there is an array 5000 elements (bars on the chart), to save time I need to calculate only last 300, but when I specified the value 300 in the second parameter I got primary 5000-4700 elements, but on offset 300-0, and further values at a call don't change. What is the point of using this parameter?

 
Sergey Efimenko:

This is the question. If I don't need to calculate the whole array, but only the last N elements.

I don't quite understand the logic of calculating these functions when limiting. I have a timeseries array (one of the indicator buffers), if I leave the number of elements equal to 0, no questions, everything is counted and calculated, but if I decrease the number of elements involved in the calculation by the same offsets, I get only the primary ones. Simply speaking there is an array 5000 elements (bars on the chart), to save time I need to calculate only last 300, but when I specified the value 300 in the second parameter I got primary 5000-4700 elements, but on offset 300-0, and further values at a call don't change. What is the point of using this parameter?

Give me a code example to fully understand the question.
 
Alexander Voronkov:
Give me an example code to fully understand the question.

this works fine:

Buffer[i]=GetValue(i);
BufferMA=iMAOnArray(Buffer,0,PeriodMA,0,MethodMA,i);
BufferBMA[i]=iBandsOnArray(Buffer,0,PeriodBands,DevBands,0,MODE_MAIN,i)

this doesn't work well:

Buffer[i]=GetValue(i);
BufferMA=iMAOnArray(Buffer,300,PeriodMA,0,MethodMA,i);
BufferBMA[i]=iBandsOnArray(Buffer,300,PeriodBands,DevBands,0,MODE_MAIN,i);

 
Sergey Efimenko:

this works fine:

Buffer[i]=GetValue(i);
BufferMA=iMAOnArray(Buffer,0,PeriodMA,0,MethodMA,i);
BufferBMA[i]=iBandsOnArray(Buffer,0,PeriodBands,DevBands,0,MODE_MAIN,i);

this doesn't work ok:

Buffer[i]=GetValue(i);
BufferMA=iMAOnArray(Buffer,300,PeriodMA,0,MethodMA,i);
BufferBMA[i]=iBandsOnArray(Buffer,300,PeriodBands,DevBands,0,MODE_MAIN,i);

To savetime and count only the last 300(bars on the chart) use for() or if() operators.
 
Alexander Voronkov:
To savetime and count only last 300(bars on the chart) use values of for() or if() operators.

How can I put this delicately... Do you have any idea what you're talking about? Have you ever used the functions mentioned in the title in your code and tried to calculate part of an array instead of the whole array? Well, try it and maybe you will "visually" understand what we're talking about. Your offer is relevant when calculating bars or other situations where you can explicitly specify how much to count, but not for an array using these functions. The part of the code above is absolutely identical, the only difference is that in the first case I'm counting the whole array, and in the second I'm only counting 300 of its values, but the values are counted at the end of the array, while references are used to the beginning. Maybe I'm not describing the situation clearly, but the code will help to see this if you attach it to some indicator and compare the result...

PS About the "self-written" version of alternative function analogues is clear, but I would like to get the required result by means of a language.

 
Sergey Efimenko:

How can I put this delicately... Do you have any idea what you're talking about? Have you ever used the functions mentioned in the title in your code and tried to calculate part of an array instead of the whole array? Well, try it and maybe you will "visually" understand what we're talking about. Your offer is relevant when calculating bars or other situations where you can explicitly specify how much to count, but not for an array using these functions. The part of the code above is absolutely identical, the only difference is that in the first case I'm counting the whole array, and in the second I'm only counting 300 of its values, but the values are counted at the end of the array, while references are used to the beginning. Maybe I'm not describing the situation clearly, but the code will help to see this if you attach it to some indicator and compare the result...

PS About the "self written" version of alternative function analogues is clear, but I would like to get the desired result by means of a language.

Just tell it as it is, it's OK.

So I misunderstood you.

 
Doesn't anyone use these functions and face this situation?
 
Sergey Efimenko:

this works fine:

Buffer[i]=GetValue(i);
BufferMA=iMAOnArray(Buffer,0,PeriodMA,0,MethodMA,i);
BufferBMA[i]=iBandsOnArray(Buffer,0,PeriodBands,DevBands,0,MODE_MAIN,i);

this doesn't work normally:

Buffer[i]=GetValue(i);
BufferMA=iMAOnArray(Buffer,300,PeriodMA,0,MethodMA,i);
BufferBMA[i]=iBandsOnArray(Buffer,300,PeriodBands,DevBands,0,MODE_MAIN,i);

What do you expect the result to be and how should it work normally?
 
Alexey Viktorov:
What do you expect the result to be and how should it work normally?
What do you mean, what do I expect? I wrote above, that I need last (current) 300 actual values, and not 300 first (initial), moreover, that I access an array at offset 299-0, but I get data at offset from "end of array" to "end of array - 300" values (in my case from 4999 to 4700), which means, at offset 299 is value that should be at offset 4999 and similarly at offset 0 is value, which should be at offset 4700. When reducing the number of array calculations, it is important to get current data instead of initial historical data, the question is what is the purpose of calculating the oldest values when current values are not calculated?
 
Sergey Efimenko:
What do you mean what do I expect? I wrote that I need 300 latest (current) actual values, not 300 first (initial), moreover, that I access an array at offset 300-0, but get data at offset from "end of array" to "end of array - 300" values (in my case from 4999 to 4700), that is, at offset 300 is the value which should be at offset 4999 and in the same way at offset 0 is the value which should be at offset 4700. When reducing the number of array calculations, it is important to get current data instead of initial historical data, the question is what is the purpose of calculating the oldest values when current values are not calculated?

DoesArraySetAsSeries() help?

I faced such a thing once - couldn't win, so I gave up. I did it without iMAOnArray().

 
Artyom Trishkin:

Does ArraySetAsSeries() help?

I faced such a thing once - couldn't win, so I gave up. I did it without iMAOnArray().

That's the problem - the array is initially a "serial" buffer. The problem is in limiting the number of calculations, as I already wrote, the data is normal when using the calculation of the whole array but it slows down the terminal during initialization and even harder when using several indicators for different timeframes, let alone optimizing an EA for such an indicator; the problem is of an internal MT4 nature, i.e. the only solution is to use their own analog of the specified functions but I want to avoid them

PS I also use my own analogue of iMAOnArray, but it will be not only me who will have the source code. Although it is possible to use libraries, iBands is also necessary, but the calculation of deviations will have to be done. In general it's a pity that this is the situation with standard functions.

Reason: