Problems with custom indicator afer changing time interval on chart

 
I've got problem with indicator that is searching for candlestick pattern - shooting star. Everything goes correct until I change time interval on chart - arrows are in bad places.
Can someone help me and tell where is the bug?



#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red


extern double max_corpus_percent = 30;
extern double max_lower_shadow =10;

//--- buffers
double Buffer[];

int init()
{

//---- indicators
SetIndexStyle (0,DRAW_ARROW, 3, 5, Red);
SetIndexArrow(0,217);
SetIndexBuffer(0,Buffer);
SetIndexEmptyValue(0,0.0);
SetIndexLabel(0,"Shooting Star");
//----
//----
return(0);
}

int start()
{
int counted_bars=IndicatorCounted();
int i=Bars-counted_bars-1;





while(i>=0){


//calculate lenght of whole candlestick
double wholeCandlestick = High[i] - Low[i];

//calculate body
double body=0;
double lowerShadow = 0;

double bodyPercentValue= max_corpus_percent / 100;
double shadowPercentValue= max_lower_shadow / 100;

if (Close[i] > Open[i]) {

body = Close[i] - Open[i];
lowerShadow = Open[i] - Low[i];


}

if (Close[i] < Open[i]) {

body = Open[i] - Close[i];
lowerShadow = Close[i] - Low [i];
}




if (body > 0)
{

if ((body <= bodyPercentValue * wholeCandlestick)&&( lowerShadow <= shadowPercentValue * wholeCandlestick ))
{

Buffer[i]=Low[i];


}
}//


i--;

}//
return;
}
//+------

 
RychuPeja: I change time interval on chart - arrows are in bad places.

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. I would have thought that after a deinit/init cycle the buffer would have been reset to all EMPTY_VALUE's. Try resetting it specifically.
    Buffer[i]=EMPTY_VALUE;
    if (body > 0){
       if(body <= bodyPercentValue * wholeCandlestick
    
       && lowerShadow <= shadowPercentValue * wholeCandlestick ){
          Buffer[i]=Low[i];
       }
    }//
    And report back (with terminal version.)
Reason: