//+------------------------------------------------------------------+
//|                                                      BB_Diff.mq4 |
//|                                       Copyright © 2006, Akuma99. |
//|                                    http://www.beginnertrader.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Akuma99."
#property link      "http://www.beginnertrader.com"

#property indicator_separate_window

#property indicator_buffers 3
#property indicator_color1 FireBrick
#property indicator_width1 2
#property indicator_color2 DarkGoldenrod
#property indicator_width2 2
#property indicator_color3 Green
#property indicator_width3 2

extern double bbPeriod=20;
extern double bbDev=2.0;
extern double thresh1=50.0;
extern double thresh2=75.0;
extern string displayText="Bollinger Band Width:";

double bbw[];
double bbw1[];
double bbw2[];

int init() {

   SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,2,FireBrick);
   SetIndexBuffer(0,bbw);
   SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,2,DarkGoldenrod);
   SetIndexBuffer(1,bbw1);
   SetIndexStyle(2,DRAW_HISTOGRAM,EMPTY,2,Green);
   SetIndexBuffer(2,bbw2);
   
   return(0);

}

int start() {

   int    counted_bars=IndicatorCounted();
   
   double upperBand,lowerBand,bandDifference;

   int   limit = Bars-counted_bars;
   int   i;
   
   for (i=limit; i>=0; i--) {
   
      upperBand = iBands(NULL,0,bbPeriod,bbDev,0,PRICE_CLOSE,MODE_UPPER,i);
      lowerBand = iBands(NULL,0,bbPeriod,bbDev,0,PRICE_CLOSE,MODE_LOWER,i);
      
      bandDifference = (upperBand-lowerBand) / Point;

      if ( bandDifference >= thresh2 ) 
        bbw[i] = bandDifference;
      else
        if ( bandDifference >= thresh1 )    
        bbw1[i] = bandDifference;
      else
        bbw2[i] = bandDifference;
      
   }
   
//   Comment("\n",displayText," ", bandDifference, " (", bandDifference/Point," Pips)");
   
   return(0);

}

