Average True Range ATR Indicator For MT5
Table Of Contents:
- Average True Range ATR Indicator For MT5
- Installing the Average True Range ATR Indicator For MT5
- Parameters of the Average True Range ATR Indicator For MT5
- Buffers of the Average True Range ATR Indicator For MT5
- Main Parts Of The Code
The Average True Range ATR Indicator For MT5 is one of the very famous standard indicators in nearly every trading platform. It is used as the basis for many other indicators which use his values as input for further calculation. The ATR indicator calculates the average size of the recent X candles. The values allow you to see an increasing or decreasing of volatility in the market.
Installing the Average True Range ATR Indicator For MT5
After you downloaded the indicator via the form above you need to unzip the zip-file. Then you need to copy the file atr.mq5 into the folder MQL5\Indicators of your MT5 installation. After that please restart MT5 and then you will be able to see the indicator in the list of indicators.
Parameters of the Average True Range ATR Indicator For MT5
The Average True Range ATR Indicator For MT5 has 1 parameters to configure.
input int InpAtrPeriod=14; // ATR period
Buffers of the Average True Range ATR Indicator For MT5
The Average True Range ATR Indicator For MT5 provides 2 buffers.
SetIndexBuffer(0,ExtATRBuffer,INDICATOR_DATA); SetIndexBuffer(1,ExtTRBuffer,INDICATOR_CALCULATIONS);
Main Parts Of The Code
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 &TickVolume[], const long &Volume[], const int &Spread[]) { int i,limit; //--- check for bars count if(rates_total lt =ExtPeriodATR) return(0); // not enough bars for calculation //--- preliminary calculations if(prev_calculated==0) { ExtTRBuffer[0]=0.0; ExtATRBuffer[0]=0.0; //--- filling out the array of True Range values for each period for(i=1;i lt rates_total && !IsStopped();i++) ExtTRBuffer[i]=MathMax(High[i],Close[i-1])-MathMin(Low[i],Close[i-1]); //--- first AtrPeriod values of the indicator are not calculated double firstValue=0.0; for(i=1;i lt =ExtPeriodATR;i++) { ExtATRBuffer[i]=0.0; firstValue+=ExtTRBuffer[i]; } //--- calculating the first value of the indicator firstValue/=ExtPeriodATR; ExtATRBuffer[ExtPeriodATR]=firstValue; limit=ExtPeriodATR+1; } else limit=prev_calculated-1; //--- the main loop of calculations for(i=limit;i lt rates_total && !IsStopped();i++) { ExtTRBuffer[i]=MathMax(High[i],Close[i-1])-MathMin(Low[i],Close[i-1]); ExtATRBuffer[i]=ExtATRBuffer[i-1]+(ExtTRBuffer[i]-ExtTRBuffer[i-ExtPeriodATR])/ExtPeriodATR; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+