//+------------------------------------------------------------------+
//|                                                    bbsqueeze.mq4 |
//|                Copyright © 2005, Nick Bilak, beluck[AT]gmail.com |
//|           enhanced a little bit by CJ Rivas, carlos[AT]vealo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Nick Bilak"
#property link      "http://metatrader.50webs.com/"

#property indicator_separate_window
#property indicator_minimum -1
#property indicator_maximum 40

#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 DarkRed

//---- input parameters
extern int       bolPrd=20;
extern double    bolDev=2.0;
extern int       keltPrd=20;
extern double    keltFactor=1.5;
//---- buffers

double upK[];
double loK[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
  

   SetIndexStyle(0,DRAW_ARROW,EMPTY,2);
   SetIndexBuffer(0,upK);
   SetIndexEmptyValue(0,EMPTY_VALUE);
   SetIndexArrow(0,159);
   SetIndexStyle(1,DRAW_ARROW,EMPTY,2);
   SetIndexBuffer(1,loK);
   SetIndexEmptyValue(1,EMPTY_VALUE);
   SetIndexArrow(1,159);
   
   
   
   IndicatorShortName("");
   SetIndexLabel(0,NULL);
   SetIndexLabel(1,NULL);

   
   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   int shift,limit;
   double diff,dPrev, std,bbs;
   
   if (counted_bars<0) return(-1);
   if (counted_bars>0) counted_bars--;
   limit=Bars-31;
   if(counted_bars>=31) limit=Bars-counted_bars-1;

   for (shift=limit;shift>=0;shift--)   {
   
		diff = iATR(NULL,0,keltPrd,shift)*keltFactor;
		std = iStdDev(NULL,0,bolPrd,MODE_SMA,0,PRICE_CLOSE,shift);
		bbs = bolDev * std / diff;
      if(bbs<1) {
         upK[shift]=0;
         loK[shift]=EMPTY_VALUE;
      } else {
         loK[shift]=0;
         upK[shift]=EMPTY_VALUE;
      }
   }
   
   return(0);
  }
//+------------------------------------------------------------------+


