//+------------------------------------------------------------------+
//|                                                     ATR Pips.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Joshua Jones"
#property link      "http://www.forexfactory.com"

#property indicator_chart_window


extern ENUM_TIMEFRAMES  AtrTimeFrame  = PERIOD_CURRENT;    // Time frame
input string            inpObjID      = "atr o1";          // Objects Id
extern int              periods       = 14;
extern double           multiplier    = 1;
extern ENUM_BASE_CORNER CommentCorner = CORNER_RIGHT_LOWER;
extern int              xDistance     = 5;
extern int              yDistance     = 5;
extern color            LabelColor    = clrGray;

int timeFrame;

string prefix = "";
struct sGlobalStruct { string name; }; sGlobalStruct glo;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
 {
   glo.name = inpObjID+":"+"label_ATRinPips";
   if(ObjectFind(glo.name)==-1)
     ObjectCreate(glo.name, OBJ_LABEL, 0, 0, 0);
     
   ObjectSet(glo.name,OBJPROP_CORNER, CommentCorner);
   ObjectSet(glo.name,OBJPROP_XDISTANCE, xDistance);
   ObjectSet(glo.name,OBJPROP_YDISTANCE, yDistance);
return(0);
}
void OnDeinit(const int reason) {  ObjectsDeleteAll(0,inpObjID+":");  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
{
   double pip  = 1/(_Point*pow(10,fmod(_Digits,2)));
   double atr  = ceil(pip*multiplier*(iATR(_Symbol,AtrTimeFrame,periods,0)));
   string text = prefix+ timeFrameToString(AtrTimeFrame)+" ATR ("+(string)periods+ "): "+ DoubleToStr(atr,0)+" pips";
   ObjectSetText(glo.name,text, 7, "Arial", LabelColor);
 
return(0);
}

//
//
//

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

string timeFrameToString(int tf)
{
   for (int i=ArraySize(iTfTable)-1; i>=0; i--) 
         if (tf==iTfTable[i]) return(sTfTable[i]);
                              return("");
}