Buffers recalculation

 
I have a bit modified code of the fractals indi and it shows only those ones that've never "met" the price.
//----Fractals up
      bFound=false;
      dCurrent=High[i];
      if(dCurrent>High[i+1] && dCurrent>High[i+2] && dCurrent>High[i-1] && dCurrent>High[i-2])
        {
            int higherhighs=0;
            for(int h=i;h>=0;h--)
               {
                  if(High[h]>High[i])higherhighs++;
               }
                  if(higherhighs==0)
                  {
                        bFound=true;
                        ExtUpFractalsBuffer[i]=dCurrent;
                  }

that's the part, for example. The idea is to recalculate all the values when the last fractal is "broken". I can't make it work automatically though while manual recompile and re-attaching it works ok of course. So how could the recalculation of buffers be launched after that event?

p.s. I've tried to zeroize buffers using the SetIndexEmptyValue() but nothing's changed.

 
.roman.: p.s. I've tried to zeroize buffers using the SetIndexEmptyValue() but nothing's changed.
  1. Perhaps you should stop using functions when you don't know what they do and read the documentation. SetIndexEmptyValue tells mt4 what specific value is used to not display the line. It doesn't "zeroize any buffers."
  2. Why you think you need "to recalculate all values" when older bars haven't changed?
 

Thank you for hints. There's no need to recalculate everything. Added this code and it works ok so far.

 for(int b=0;b<=Bars;b++)
         {
            if(ExtUpFractalsBuffer[b] && High[0]>ExtUpFractalsBuffer[b])
               {
               ExtUpFractalsBuffer[b]=0.0;
               SetIndexEmptyValue(0,0.0);  
               }
         }

But not everything looks that simple.

While loading bars from history(by manual dragging chart to the left) the indicator starts to "shift" the fractals and the charts looks like that. The same problems stays but the fractals are moved in the opposite direction when a certain timeframe of an instrument that has not been loaded for a while is opened). It affects as well the initial idea to display on chart only "non-crossed by price" fractals as far as the old one calculated values are not recalculated when new bars are loaded. How could that be fixed in code?


 

The problem stays and there appeared another one. When having the indi on many charts and trying to load low TFs it takes quite a long time and in case of opening m1-m5 may take minutes. I was trying to optimize it because I don't need really to know the number of higherhighs, I just need to stop the iteration and to calculate next i. I know that to stop the cycle I need to put break in it (when the terms missmatch) but my brain already gave up on possible solutions, I have no more ideas.

P.S. the only way to get rid of useless iterations that came into my head was to put in the for() the condition of higherhighs to be equal to 0. But still looks ugly though and with break operator may be better.

if(dCurrent>High[i+1] && dCurrent>High[i+2] && dCurrent>High[i-1] && dCurrent>High[i-2])
        {
            int higherhighs=0;
            for(int h=i;higherhighs==0 && h>=0;h--)
Reason: