//+------------------------------------------------------------------+
//|                                               ATR_Volatility.mq4 |
//+------------------------------------------------------------------+
#property description "ATR Period Volatility"
#property version   "1.0"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots 3
//---- input parameters
extern int ATR_Period=21;
extern  ENUM_MA_METHOD ATR_Smoothing_Method =MODE_LWMA;
extern int ATR_Smoothing=3;
extern int ATR_MA=21;
extern int MA_Shift=0;
double ATR[];
double Smth_ATR[];
double MA_ATR[];

//--- plot ATR
#property indicator_label1  "ATR"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrNONE
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Smth_ATR
#property indicator_label2  "Smth_ATR"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrGold
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot MA_ATR
#property indicator_label3  "MA_ATR"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrSilver
#property indicator_style3  STYLE_DOT
#property indicator_width3  1

//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

//---- drawing settings
   SetIndexBuffer(0,ATR);
   SetIndexBuffer(1,Smth_ATR);
   SetIndexBuffer(2,MA_ATR);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- indicator short name
   IndicatorShortName("ATR Volatility");
   SetIndexLabel(0,"ATR");
   SetIndexLabel(1,"Smth ATR");
   SetIndexLabel(2,"MA ATR");
   ArraySetAsSeries(ATR,true);
   ArraySetAsSeries(Smth_ATR,true);
   ArraySetAsSeries(MA_ATR,true);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
   int    pos=Bars-2;
   int i;   
   if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1;
//---- main calculation loop
   for(i=0;i<Bars;i++) {ATR[i] = iATR(Symbol(),Period(),ATR_Period,i);}
   for(i=0;i<Bars;i++) {Smth_ATR[i] = iMAOnArray(ATR,0,ATR_Smoothing,MA_Shift,ATR_Smoothing_Method,i);}
   for(i=0;i<Bars;i++) {MA_ATR[i]= iMAOnArray(ATR,0,ATR_MA,MA_Shift,ATR_Smoothing_Method,i);}
   
   return(0);
   }

//+------------------------------------------------------------------+