//+------------------------------------------------------------------+
//|                                                     BB cloud.mq4 |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 3

#property indicator_color1 C'80,80,80'
#property indicator_color2 C'40,40,40'
#property indicator_color3 Blue
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 1
#property indicator_style3 0

extern int    MAperiod   = 20;
extern int    StdDevs    = 2;
extern int    MAmethod   = 0;
extern int    PriceType  = 0;
extern color  cBand1     = C'80,80,80';
extern color  cBand2     = C'40,40,40';
extern int    BandWidth  = 2;
extern color  cMedian    = Blue;
extern int    LineWidth  = 1;
extern int    LineStyle  = 0;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];

int ExtCountedBars=0;

//+------------------------------------------------------------------+
int init()  {
//+------------------------------------------------------------------+
  SetIndexStyle(0,DRAW_LINE, 0, BandWidth, cBand1);
  SetIndexBuffer(0, ExtMapBuffer1);
  SetIndexEmptyValue(0,0.0);
  ArrayInitialize(ExtMapBuffer1,0.0);

  SetIndexStyle(1,DRAW_LINE, 0, BandWidth, cBand2);
  SetIndexBuffer(1, ExtMapBuffer2);
  SetIndexEmptyValue(1,0.0);
  ArrayInitialize(ExtMapBuffer2,0.0);

  SetIndexStyle(2,DRAW_LINE, LineStyle, LineWidth, cMedian);
  SetIndexBuffer(2, ExtMapBuffer3);
  SetIndexEmptyValue(2,0.0);
  ArrayInitialize(ExtMapBuffer3,0.0);

  return(0);
}

//+------------------------------------------------------------------+
int deinit()   {
//+------------------------------------------------------------------+
  return(0);
}

//+------------------------------------------------------------------+
int start()   {
//+------------------------------------------------------------------+
  if(Bars<=10) return(0);
  ExtCountedBars=IndicatorCounted();
  if (ExtCountedBars<0) return(-1);
  if (ExtCountedBars>0) ExtCountedBars--;
  int pos=Bars-ExtCountedBars-1;
  while(pos>=0) {
    ExtMapBuffer1[pos]=iBands(NULL,0,MAperiod,StdDevs,0,PriceType,2,pos);
    ExtMapBuffer2[pos]=iBands(NULL,0,MAperiod,StdDevs,0,PriceType,1,pos);
    ExtMapBuffer3[pos]=iMA(NULL,0,MAperiod,0,MAmethod,PriceType,pos);
    pos--;
  }
  return(0);
}
//+------------------------------------------------------------------+