//+------------------------------------------------------------------+
//|                                               KG_Auto_BB_123.mq4 |
//|                      Copyright © 2009, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "CopyLeft © 2009, AmTwoXtwo Industries,Inc."
#property link      ""

#property indicator_chart_window
#property indicator_buffers 7
/*#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 Blue
#property indicator_color5 Blue
#property indicator_color6 Blue
#property indicator_color7 Gold
#property indicator_color8 Gold
#property indicator_color9 Gold
*/
//---- input parameters
extern int       BB_Period=48;
extern int       BB_Shift=0;
extern color     SD1_Colour=Red;
extern color     SD2_Colour=Blue;
extern color     SD3_Colour=Gold;

//---- buffers
double SD1_Buff_A[];
double SD1_Buff_T[];
double SD1_Buff_B[];
double SD2_Buff_A[];
double SD2_Buff_B[];
double SD3_Buff_A[];
double SD3_Buff_B[];
//+------------------------------------------------------------------+
//| KG_Auto_BB_123                                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators SD1
   SetIndexStyle(0,DRAW_LINE,0,1,SD1_Colour);
   SetIndexBuffer(0,SD1_Buff_A);
   SetIndexStyle(1,DRAW_LINE,0,1,SD1_Colour);
   SetIndexBuffer(1,SD1_Buff_T);
   SetIndexStyle(2,DRAW_LINE,0,1,SD1_Colour);
   SetIndexBuffer(2,SD1_Buff_B);
   //---- indicators SD2
   SetIndexStyle(3,DRAW_LINE,0,1,SD2_Colour);
   SetIndexBuffer(3,SD2_Buff_A);
   SetIndexStyle(4,DRAW_LINE,0,1,SD2_Colour);
   SetIndexBuffer(4,SD2_Buff_B);
   //---- indicators SD2
   SetIndexStyle(5,DRAW_LINE,0,1,SD3_Colour);
   SetIndexBuffer(5,SD3_Buff_A);
   SetIndexStyle(6,DRAW_LINE,0,1,SD3_Colour);
   SetIndexBuffer(6,SD3_Buff_B);
//----
   SetIndexDrawBegin(0,BB_Period+BB_Shift);
   SetIndexDrawBegin(1,BB_Period+BB_Shift);
   SetIndexDrawBegin(2,BB_Period+BB_Shift);
   SetIndexDrawBegin(3,BB_Period+BB_Shift);
   SetIndexDrawBegin(4,BB_Period+BB_Shift);
   SetIndexDrawBegin(5,BB_Period+BB_Shift);
   SetIndexDrawBegin(6,BB_Period+BB_Shift);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
int    counted_bars=IndicatorCounted();
   int limit, i;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//----
for(i = 0; i <= limit; i++)
{
//SD1
double bb_sd1_up = iBands(NULL,0,BB_Period,1,BB_Shift,PRICE_CLOSE,MODE_UPPER,i);
double bb_sd1_dwn = iBands(NULL,0,BB_Period,1,BB_Shift,PRICE_CLOSE,MODE_LOWER,i);
double bb_sd1_md = iBands(NULL,0,BB_Period,1,BB_Shift,PRICE_CLOSE,MODE_MAIN,i);
//SD2
double bb_sd2_up = iBands(NULL,0,BB_Period,2,BB_Shift,PRICE_CLOSE,MODE_UPPER,i);
double bb_sd2_dwn = iBands(NULL,0,BB_Period,2,BB_Shift,PRICE_CLOSE,MODE_LOWER,i);
//SD3
double bb_sd3_up = iBands(NULL,0,BB_Period,3,BB_Shift,PRICE_CLOSE,MODE_UPPER,i);
double bb_sd3_dwn = iBands(NULL,0,BB_Period,3,BB_Shift,PRICE_CLOSE,MODE_LOWER,i);

SD1_Buff_A[i]=bb_sd1_up;
SD1_Buff_T[i]=bb_sd1_md;
SD1_Buff_B[i]=bb_sd1_dwn;
SD2_Buff_A[i]=bb_sd2_up;
SD2_Buff_B[i]=bb_sd2_dwn;
SD3_Buff_A[i]=bb_sd3_up;
SD3_Buff_B[i]=bb_sd3_dwn;
}
//----
   return(0);
  }
//+------------------------------------------------------------------+