//+------------------------------------------------------------------+ //| AtrIndicator.mq4 | //| Copyright © 2010 Robert Hill | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010 Robert Hill ajka MrPip" #property link "www.mrpipforex.com" #property indicator_chart_window //#property indicator_buffers 0 #define OBJ_NAME "Atr" extern int ATR_Period = 20; extern string C = "---Corner Position---"; extern string c0 = " 0 = Upper left"; extern string c1 = " 1 = Upper right"; extern string c2 = " 2 = Lower left"; extern string c3 = " 3 = Lower right"; extern int myCorner = 3; extern color LabelColor = Red; double myPoint; datetime last_bar; int init() { myPoint = SetPoint(); ShowAtr(); } int start() { if (Time[0] == last_bar) return(0); // Calculate once per bar last_bar = Time[0]; ShowAtr(); } int deinit() { ObjectDelete(OBJ_NAME); } void ShowAtr() { static double Atr; Atr = iATR(NULL, 0, ATR_Period, 1) / myPoint; DrawAtrOnChart(Atr); } void DrawAtrOnChart(double Atr) { string s; s = "ATR: "+DoubleToStr(Atr, 1)+" pips"; if(ObjectFind(OBJ_NAME) < 0) { ObjectCreate(OBJ_NAME, OBJ_LABEL, 0, 0, 0); ObjectSet(OBJ_NAME, OBJPROP_CORNER, myCorner); ObjectSet(OBJ_NAME, OBJPROP_YDISTANCE, 12); ObjectSet(OBJ_NAME, OBJPROP_XDISTANCE, 3); ObjectSetText(OBJ_NAME, s, 10, "FixedSys", LabelColor); } ObjectSetText(OBJ_NAME, s); WindowRedraw(); } double SetPoint() { double mPoint, mDigits; mDigits = MarketInfo(Symbol(), MODE_DIGITS); if (mDigits < 4) mPoint = 0.01; else mPoint = 0.0001; return(mPoint); }