//+------------------------------------------------------------------+
//|                                           ATR Value Indicator.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Hossein Nouri."
#property link      "https://www.mql5.com/en/users/hsnnouri"
#property version   "1.00"
#property description "Displaying ATR(Average True Range) value in pips or points." 
#property strict
#property indicator_chart_window
//--- input parameters
enum valueType
{
   Points=0, // Points
   Pips=1, // Pips
};


input string A = "ATR 1 Parameters"; // ATR 1 Parameters
input int      ATRPeriod1=14;
input double   Multiplier1=1.0;
input valueType display1=0; // Points or Pips
input color    labelColor1=clrRed; // Font Color
input string  B= "ATR 2 Parameters"; // ATR 2 Parameters
input int      ATRPeriod2=14;
input double   Multiplier2=2.0;
input valueType display2=0; // Points or Pips
input color    labelColor2=DodgerBlue; // Font Color
input string C = "ATR 1 & 2 Parameters"; // ATR 1 & 2 Parameters
input int      FS=10;
input bool     FB = false; // Font Bold
input ENUM_BASE_CORNER BC = CORNER_RIGHT_UPPER; // Corner
input int LR = 50; // Left-Right
input int UD = 50; // Up-Down

#define OBJ_NAME_1 "ATRIndicatorObj_1"
#define OBJ_NAME_2 "ATRIndicatorObj_2"

string FBx;

int x1,x2,y1,y2;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
    switch(FB)
    {
       case 0: FBx = "Arial"; break;
       case 1: FBx = "Arial Bold";
    }   
    
    if(BC == 0 || BC == 1)
    {
       x1 = LR; x2 = LR;
       y1 = UD; y2 = UD + 2*FS;
    }
    else
    {
       x1 = LR; x2 = LR;
       y1 = UD + 2*FS; y2 = UD;
    }       
   
   ShowATR1();
   ShowATR2();
//---
   return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
{
   ObjectDelete(OBJ_NAME_1);
   ObjectDelete(OBJ_NAME_2);
}
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   ShowATR1();
   ShowATR2();
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
void ShowATR1()
{
   static double ATR1;
   
   ATR1 = iATR(Symbol(),0,ATRPeriod1,0);
   ATR1 = (ATR1 * Multiplier1) * MathPow(10,Digits - display1);
   DrawATROnChart1(ATR1);
}
void DrawATROnChart1(double ATR1)
{
   string Dis;
   if(display1==0) Dis=" Points";
   if(display1==1) Dis=" Pips";
   string s1 = (string)(Multiplier1 * 100) + "% of ATR1 ("+(string)ATRPeriod1+"):"+DoubleToStr(ATR1,0)+ Dis;
 
   if(ObjectFind(OBJ_NAME_1) < 0)
   {
      ObjectCreate(OBJ_NAME_1, OBJ_LABEL, 0, 0, 0);
      ObjectSet(OBJ_NAME_1, OBJPROP_CORNER, BC);
      ObjectSet(OBJ_NAME_1, OBJPROP_XDISTANCE, x1);
      ObjectSet(OBJ_NAME_1, OBJPROP_YDISTANCE, y1);
      ObjectSet(OBJ_NAME_1,OBJPROP_SELECTABLE,false);
      ObjectSetText(OBJ_NAME_1, s1, FS, FBx, labelColor1);
   }
   
   ObjectSetText(OBJ_NAME_1, s1);
   WindowRedraw();
}

void ShowATR2()
{
   static double ATR2;
   
   ATR2 = iATR(Symbol(),0,ATRPeriod2,0);
   ATR2 = (ATR2 * Multiplier2) * MathPow(10,Digits - display2);
   DrawATROnChart2(ATR2);
}
void DrawATROnChart2(double ATR2)
{
   string Dis2;
   if(display2==0) Dis2=" Points";
   if(display2==1) Dis2=" Pips";
   string s2 = (string)(Multiplier2 * 100) + "% of ATR2 ("+(string)ATRPeriod2+"):"+DoubleToStr(ATR2,0)+ Dis2;
 
   if(ObjectFind(OBJ_NAME_2) < 0)
   {
      ObjectCreate(OBJ_NAME_2, OBJ_LABEL, 0, 0, 0);
      ObjectSet(OBJ_NAME_2, OBJPROP_CORNER, BC);
      ObjectSet(OBJ_NAME_2, OBJPROP_XDISTANCE, x2);
      ObjectSet(OBJ_NAME_2, OBJPROP_YDISTANCE, y2);
      ObjectSet(OBJ_NAME_2,OBJPROP_SELECTABLE,false);
      ObjectSetText(OBJ_NAME_2, s2, FS, FBx, labelColor2);
   }
   
   ObjectSetText(OBJ_NAME_2, s2);
   WindowRedraw();
}