Bollinger Close out/Close in indicator

 

Hello guys, i was trying to make an indicator to plot an arrow in the chart when there is a high that closes out of the bollinger band, and then a new high, that closes inside the bands.

The purpose is for counting test.

This is what i got so far, but couldnt get any  result. 

for(int i=limit; i>=0; i--)
   {
      double highclose = Close[iHighest(NULL,0,MODE_CLOSE,tempo,i)];
      double pasthighclose = Close[iHighest(NULL,0,MODE_CLOSE,tempo,i+tempo)];
      double lowclose = Close[iLowest(NULL,0,MODE_CLOSE,tempo,i)];
      double pastlowclose = Close[iLowest(NULL,0,MODE_CLOSE,tempo,i+tempo)];
      
      bbu[i] = iBands(NULL,0,bbp,bbd,0,bbpr,MODE_UPPER,iHighest(NULL,0,MODE_CLOSE,tempo,i));
      bbdw[i] = iBands(NULL,0,bbp,bbd,0,bbpr,MODE_LOWER,iLowest(NULL,0,MODE_CLOSE,tempo,i));
      bbua[i] = iBands(NULL,0,bbp,bbd,0,bbpr,MODE_UPPER,iHighest(NULL,0,MODE_CLOSE,tempo,i+tempo));
      bbdwa[i] = iBands(NULL,0,bbp,bbd,0,bbpr,MODE_LOWER,iLowest(NULL,0,MODE_CLOSE,tempo,i+tempo));
   }
      
   for(i=0;i<limit;i++)
   {         
            
      static datetime Time0;
                
      if(pastlowclose<bbdwa[i] && lowclose>bbdw[i] && lowclose<=pastlowclose)
         
         {ArrowUPBuffer[i]=Low[i]-10*Point;
            if(alertas && Time0 != Time[0])
            {Time0 = Time[0];
               Alert("CALL em: ",Symbol(),",",Period());
               }
             }
      else
         ArrowUPBuffer[i]=0;
      
      if(pasthighclose>bbua[i] && highclose<bbu[i] && highclose>=pasthighclose)
            
         {ArrowDownBuffer[i]=High[i]+10*Point;            
            if(alertas && Time0 != Time[0])
            {Time0 = Time[0];
               Alert("PUT em: ",Symbol(),",",Period());
               }   
            }
      else
         ArrowDownBuffer[i]=0;
    }

 If some who knows better could give a light on what function should be used to reach this objective. Or any indicator on codebase that I could see the use and some examples of something that is similar to this.

Thanks in advance guys.