//+------------------------------------------------------------------+
//|                                                     BB cloud.mq4 |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 C'60,155,255'
#property indicator_color2 C'255,95,175'
#property indicator_color3 clrNONE
#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'60,155,255';
extern color  cBand2     = C'255,95,175';
extern int    BandWidth  = 2;
extern color  cMedian    = clrNONE;
extern int    LineWidth  = 1;
extern int    LineStyle  = 0;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];

int ExtCountedBars=0;
//+------------------------------------------------------------------+
int init() 
  {
//+------------------------------------------------------------------+
//SetIndexStyle(0,DRAW_HISTOGRAM, 0, BandWidth, cBand1);
   SetIndexStyle(0,DRAW_LINE,0,BandWidth,cBand1);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   ArrayInitialize(ExtMapBuffer1,0.0);

//SetIndexStyle(1,DRAW_HISTOGRAM, 0, BandWidth, cBand2);
   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() 
  {
  	ObjectsDeleteAll(0,OBJ_TRIANGLE);
   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--;
     }

   for(int i=1000; i>=0; i--)
     {
      string obj_name="BB_cloud-"+IntegerToString((int)Time[i])+"-1";

      if(ObjectFind(obj_name)==-1)
        {
         ObjectCreate(obj_name,OBJ_TRIANGLE,0,Time[i+1],ExtMapBuffer1[i+1],Time[i+1],ExtMapBuffer2[i+1],Time[i],ExtMapBuffer2[i]);
         ObjectSet(obj_name,OBJPROP_COLOR,C'52,88,88');
         ObjectSet(obj_name,OBJPROP_BACK,true);
        }

      obj_name="BB_cloud-"+IntegerToString((int)Time[i])+"-2";

      if(ObjectFind(obj_name)==-1)
        {
         ObjectCreate(obj_name,OBJ_TRIANGLE,0,Time[i+1],ExtMapBuffer1[i+1],Time[i],ExtMapBuffer1[i],Time[i],ExtMapBuffer2[i]);
         ObjectSet(obj_name,OBJPROP_COLOR,C'52,88,88');
         ObjectSet(obj_name,OBJPROP_BACK,true);
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+
