MT4 iMAOnArray and iBandsOnArray effect of number of elements on calculations - page 6

 

I didn't suggest a calculator or Excell for nothing. It helps to understand how this shit works. You can only use a number of elements other than zero to calculate if you already have a ready array. Suppose you have an array of 1000 elements, and you need to average only the last 100. We have two choices: to convert these 100 elements into a custom array and recalculate them, or to use the loop from 100 to 0 and not to convert the number of elements into 0, but into 100.

But here we face the problem of changing the size of the array, which is inevitable in indicators.

Again, I was talking about other ways to limit the number of elements for calculation. Well, you can set condition iMAOnArray() only if(rates_total-i >= rates_total-100); and only the last 100 bars will be recalculated and everything will be fine when a new bar arrives.

int i, limit;
   limit = prev_calculated == 0 ? rates_total-1 : rates_total-prev_calculated;

   for(i = limit; i >= 0; i--)
     {
      Buffer[i]=open[i];
      if(rates_total-i >= rates_total-100)
      BufferMA[i] = NormalizeDouble(iMAOnArray(Buffer, 0, 5, 0, MODE_LWMA, i), _Digits);
      
     }

return(rates_total);


 
Alexey Viktorov:

I didn't suggest a calculator or Excell for nothing. It helps to understand how this shit works. You can only use a number of elements other than zero to calculate if you already have a ready array. Suppose you have an array of 1000 elements, and you want to average only the last 100. We have two choices: to convert these 100 elements into a custom array and recalculate them, or to use the loop from 100 to 0 and not to convert the number of elements into 0, but into 100.

But here we face the problem of changing the size of the array, which is inevitable in indicators.

Again, I was talking about other ways to limit the number of elements for calculation. Well, set the condition to read iMAOnArray() only if(rates_total-prev_calculated-i >= 100); and only the last 100 bars will be recalculated and everything will be fine when a new bar arrives.


Tell me, are you a programmer or do you do it as a hobby, or out of necessity? I don't need an excel or a piece of paper to understand how it works, and Barabashka demonstrated all the "difficulties" on the screenshot earlier. Let's go in order.

1. iMAOnArray (as well as iBandsOnArray) may work in two versions, it may read the entire array and do it correctly (but it has slows down during primary calculation) or it may read a part of the array, but it will do it only for the initial elements, despite the fact that the shift is specified for the final ones. That is however I tried to limit calculation to bars I still need to calculate either all array (i.e. initial version of "braking"), or to make up variant similar to yours with copying of buffer and recalculation of all elements of this buffer, that, as described in my posts earlier, does not give right result for complex smoothing methods and also increase time of data processing in general.

2. the problem, described by you in indicators with the array resizing, occurs only if the array is not one of the indicator buffers, that is, your described "dancing around" also has a negative effect, because going back to the primary source code the problem was only in slow calculation and only at first step.

3. The variant offered by you with recalculation of only part of arrays on 100 (N) bars, gives again loss of general productivity and unnecessary troubles of implementation with array copying or unnecessary recalculation. Besides on your screenshot and in the code above all the calculations are done (I suspect somewhere in the internal array, that's most likely why the primary lags occur), otherwise this kind of smoothing would have made first filled results different, and you just haven't filled the buffer array with them. Because 0 in the array size parameter for calculating the function explicitly tells it to read all data, that's the catch.

The only way to get it right is to use my own function, which will work the way it should and won't recalculate all data (N part of it) when new bar comes, but will only read it, especially as I have and use such an averaging function in many of my products. The question of this forum topic was how to "beat" standard functions of MT4, without worsening the speed of processing and the result. If I believe the message above,the "standard deviation" on the array is calculated without brakes, or as a fallback I can write my own deviation calculation, especially as the formulas for calculation are available to everyone here in the documentation.

 

So many letters... And it's all aimed solely at disagreeing with the proposed option.

Thanks for the idea, at least I've figured out how it works, otherwise I didn't get into the intricacies of these functions as I didn't need to.

If you don't like it, use self-written ones.

 
Alexey Viktorov:

So many letters... And everything is aimed solely at disagreement with the proposed option.

Thanks for the idea, at least I've figured out how it works, otherwise I didn't get into the intricacies of these functions because I didn't need to.

If you don't like it, use self-written ones.

Well, why on disagreement, on explanation, why it is not necessary to do so, because to write the code bound to braking functions or code creating additional loops of copying - is not always the correct option, though, sometimes, and less laborious :)
And it's not about "like"/"dislike", but in the fact that the functions do not work exactly as it should, because in fact, creating analogues is like reinventing the wheel, but in this particular case we can not do without it.

I've made conclusions for myself several pages ago, but your way, perhaps, will help someone to understand that this situation has already been solved here, and what I need to do to solve this problem, so many letters :)

 

There is no copying or extra cycles in the latter variant. And the MODE_LWMA calculation method that you and Dimitri were talking about before cannot be recalculated correctly.

Look at the code and screenshot. In the screenshot, MA period 5 as in the code, MODE_LWMA method and pay attention to the number of calculated bars, to the coincidence of MA and indicator values with iMAOnArray() in the basement. If you want to re-calculate all of the bars or only recalculate 100. If there are no changes, it means that other calculations are slow.

 
A total bummer!
 
Sergey Efimenko:

Tell me, are you a programmer or do you do it as a hobby, or out of necessity...?

In the past, he used to start babbling himself that he wasn't a programmer, but an amateur and so he could be bullied.
 
Alexey Viktorov:

There is no copying or extra cycles in the latter variant. And the MODE_LWMA calculation method that you and Dimitri were talking about before cannot be recalculated correctly.

Look at the code and screenshot. In the screenshot, MA period 5 as in the code, MODE_LWMA method and pay attention to the number of calculated bars, to the coincidence of MA and indicator values with iMAOnArray() in the basement. If you want to re-calculate all of the bars or only recalculate 100. If there are no changes, it means that other calculations are slow.

The latter variant is essentially the same as the original one. As I wrote before with array size 0, it's still counted as a whole. My first solution to reduce calculation time, even before creation of the forum thread, was to limit the number of bars but, unfortunately, it didn't affect productivity; then I started to experiment with the length of the array for iMAOnArray and this is when I understood the complexity of the situation. It was then and only then, having tried almost all the easy variants, including changing the array indexing for different combinations, I created this topic. Well, after that I got some answers, some of them confirming that others had also tried them and all of them had come up with their own function. That's why I asked for your code, initially knowing that it would work out :) No offence :) Maybe some of the users will get over this "rake" by reading this thread. :)
 
Dmitry Fedoseev:
In the past, he himself would begin to babble that he was not a programmer, but an amateur, and therefore he could be bullied.

It was more of a rhetorical question :)

PS Gentlemen, let's be tolerant of each other. After all, we are all here for one reason - to "rip off" the market. :) So let's go towards that goal without any distractions. Each of us has its own difficulties, and features perception, but only in a dispute born truth, though as they say like Napoleon: "To argue, knowing that you're wrong - stupid, to argue, knowing that you are right mean. That's why I never argue."

 
Sergey Efimenko:
The latter option is essentially no different from the original. As I've already written, when the array size is 0, it's still counted in its entirety. My first solution, even before creation of the forum thread, was to limit the number of bars, but unfortunately it didn't affect productivity; then I started to experiment with the length of array for iMAOnArray and that's when I saw the complexity of the situation. It was then and only then, having tried almost all the easy variants, including changing the array indexing for different combinations, I created this topic. Well, after that I got some answers, some of them confirming that others had also tried them and all of them had come up with their own function. That's why I asked for your code, initially knowing that it would work out :) No offence :) Maybe some of the users will get over this "rake" by reading this thread. :)

Are you saying that after if(rates_total-i >= rates_total-100);, when there are only 100 bars left to calculate, the iMAOnArray() function first recalculates the WHOLE array?