//+------------------------------------------------------------------+
//|                                      smAverageTrueRange.mq4 
//+------------------------------------------------------------------+
#property copyright "Copyright 09.02.2016, SwingMan"
#property version   "1.00"
#property strict

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1 clrDodgerBlue

#property indicator_width1 3


//------- external parameters ---------------------------------------+
extern int                ATR_period         = 34;
//+------------------------------------------------------------------+

//---- constants

//---- buffers
double bufATR[],bufATRMA[];

//---- variables

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorDigits(0);
   IndicatorShortName(WindowExpertName()+" ("+ATR_period+")");
   
   IndicatorBuffers(2);
//--- indicator buffers mapping
   SetIndexBuffer(0,bufATR); SetIndexStyle(0,DRAW_LINE); SetIndexLabel(0,"ATR");
      
   //-- new buffers
   //SetIndexBuffer(1,bufATR); 
   
   SetIndexDrawBegin(0,ATR_period-1);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   
   int limit=rates_total-prev_calculated;
//---
   if(rates_total<=10)
      return(0);
//--- indicator values
   if(prev_calculated>0)
      limit++;
   for(int i=0; i<limit; i++)
     {           
      bufATR[i]=iATR(Symbol(),Period(),ATR_period,i)/Point;
     }
   //for(int i=0; i<limit; i++)
   //  {           
   //   bufATRMA[i]=iMAOnArray(bufATR,0,ATR_slowing,0,MODE_SMA,i);
   //  }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
