return value of upper bollinger band when High[i] crosses

 

Hi Fellow coding enthusiasts,

I am trying to return the value of the upper bollinger band when the price last crossed it using a function (below) I am checking the code by getting it to comment on the chart what should be the price. not sure were I am going wrong any help appreciated thanks. 

double highBollingerCross()
{
double highBollingerCross = 0;
   for(int i=Bars-1;i>=0;i--)
    {
    if(High[i] > (iBands(NULL,0,21,2,0,PRICE_CLOSE,MODE_UPPER,i)))
      highBollingerCross = (iBands(NULL,0,21,2,0,PRICE_CLOSE,MODE_UPPER,
i ));
      }
      return(highBollingerCross);
      Comment(highBollingerCross);
      }
 
Adam Woods:

Hi Fellow coding enthusiasts,

I am trying to return the value of the upper bollinger band when the price last crossed it using a function (below) I am checking the code by getting it to comment on the chart what should be the price. not sure were I am going wrong any help appreciated thanks. 

I guess you should also check if High[i-1] is less than the band so that you could say that a cross. I never tried this indicator so I am not sure. But I use this logic to determine the MA crosses.

 
  1. Check for a cross.
  2. You are returning the oldest cross, not the newest.