iFractals jumping values randomly

 

I'm having a weird problem with the value from iFractals jumping to a wrong value randomly. First, the code, then the problem:

int start()
  {
   CurrTime = iTime(NULL,0,1);
   if (PrevTime==CurrTime) return(0); //check for new bar
   int ns = 0;
   for (int shift = 1; shift < Bars; shift++) {
      if (iFractals(NULL,0,MODE_UPPER,shift)!=0) {
         ns = shift;
         break;
      }
   }
   if (last==iFractals(NULL,0,MODE_UPPER,ns)) { //last found fractal is same fractal as this one
      PrevTime = CurrTime;
      return(0);
   }
   
   Alert(last," ",iFractals(NULL,0,MODE_UPPER,ns)," ",ns); //found a new fractal?
   ObjectCreate(DoubleToStr(ID,1),OBJ_ARROW,0,iTime(NULL,0,1),iFractals(NULL,0,MODE_UPPER,ns));
   ID++;
   
   //update vars
   last = iFractals(NULL,0,MODE_UPPER,ns);
   PrevTime = CurrTime;
   return(0);
  }

Problem: finds a fractal change just fine (one bar afterwards). A random number of bars later (sometimes!) between this fractal and the next, the value will jump randomly up or down then immediately jump back to the proper value. Looking at the code above, this means that I get an arrow after a fractal, an arrow at a random place, then an arrow at the fractal value right after the random arrow.

EDIT: Does this with the lower fractals too.

Reason: