//+------------------------------------------------------------------+ //| ABR.mq4 | //| Copyright 2017, nicholishen | //| https://www.forexfactory.com/nicholishen | //+------------------------------------------------------------------+ #property copyright "Copyright 2017, nicholishen" #property link "https://www.forexfactory.com/nicholishen" #property version "1.00" #property strict //--- indicator settings #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 clrViolet //--- input parameter input int AbrPeriod=14; // ABR Period //--- buffers double ABRBuffer[]; double ExtTRBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit(void) { string short_name; //--- 1 additional buffer used for counting. IndicatorBuffers(2); IndicatorDigits(Digits); //--- indicator line SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,ABRBuffer); SetIndexBuffer(1,ExtTRBuffer); //--- name for DataWindow and indicator subwindow label short_name="ABR("+IntegerToString(AbrPeriod)+")"; IndicatorShortName(short_name); SetIndexLabel(0,short_name); //--- check for input parameter if(AbrPeriod<=0) { Print("Wrong input parameter ABR Period=",AbrPeriod); return(INIT_FAILED); } //--- SetIndexDrawBegin(0,AbrPeriod); //--- 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; //--- check for bars count and input parameter if(rates_total<=AbrPeriod || AbrPeriod<=0) return(0); //--- counting from 0 to rates_total ArraySetAsSeries(ABRBuffer,false); ArraySetAsSeries(ExtTRBuffer,false); ArraySetAsSeries(open,false); ArraySetAsSeries(high,false); ArraySetAsSeries(low,false); ArraySetAsSeries(close,false); //--- preliminary calculations if(prev_calculated==0) { ExtTRBuffer[0]=0.0; ABRBuffer[0]=0.0; //--- filling out the array of True Range values for each period for(i=1; i