//+------------------------------------------------------------------+
//|                                               written by Piccolo |
//|                                             piccolo@forexfix.com |
//|                                          http://www.forexfix.com |
//+------------------------------------------------------------------+ 
#property copyright "Piccolo"
#property link      "http://www.forexfix.com"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 SteelBlue
#property indicator_color2 SteelBlue
#property indicator_color3 SteelBlue

double MA[];
double Up[];
double Down[];
extern int MA_Period = 60; // MA period for calculation
extern int MA_Mode = 0; // 0=sma, 1=ema, 2=smma, 3=lwma
extern int MA_PriceType = 0; // 0:Close 1:Open 2:High 3:Low 4:Median 5:Typical 6:Weighted
extern int ATR_Period = 14; // ATR period for calculation
extern int ATR_Multiplier = 3; // ATR multiplier value for bands
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, MA);
   SetIndexStyle(1, DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(1, Up);
   SetIndexStyle(2, DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(2, Down);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;
   double MAnow, MAprevious, MAafter;
   double Range, AvgRange;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;
   
   for(i = limit; i >= 0; i--) {
        
      MA[i] = iMA(NULL, 0, MA_Period, 0, MA_Mode, MA_PriceType, i);
      double ATR = iATR(NULL,0,ATR_Period,i);
    
      Up[i] = MA[i] + ATR_Multiplier * ATR;
      Down[i] = MA[i] - ATR_Multiplier * ATR;
   }
   return(0);
}

