//+------------------------------------------------------------------+
//|                                                          ATR.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property description "Volatility"
#property strict

//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1  DodgerBlue

extern bool hl = true;
extern double x = 0.0004;
//--- buffers
double ExtATRBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   string short_name;
//--- 1 additional buffer used for counting.
   IndicatorBuffers(1);
   IndicatorDigits(Digits);
//--- indicator line
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtATRBuffer);
//--- name for DataWindow and indicator subwindow label
   short_name="Volatility";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Average True Range                                               |
//+------------------------------------------------------------------+
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 i,limit = Bars-1;
//--- counting from 0 to rates_total
   //ArraySetAsSeries(ExtATRBuffer,false);

//--- the main loop of calculations
   for(i = limit; i >= 0; i--)
     {
      if (hl) ExtATRBuffer[i] = (iHigh(Symbol(),Period(),i) - iLow(Symbol(),Period(),i));// * 10*Period()*Period();// + 
                        //iVolume(Symbol(),Period(),i);
      else    ExtATRBuffer[i] = MathAbs(iOpen(Symbol(),Period(),i) - iClose(Symbol(),Period(),i));// * 10*Period()*Period();
      
      if (ExtATRBuffer[i] < x) ExtATRBuffer[i] = 0;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
