//+------------------------------------------------------------------+ //| miniATR.mq4 | //| Copyright 2014, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2014, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" #property strict #property indicator_chart_window extern int size=12; extern color col=clrYellow; extern int ATRperiod=14; string name1="DAILY 14"; string name2="WEEKLY 14"; string name3="MONTHLY 14"; string name4="Spread"; string name5="TV"; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { ObjectDelete(name1);ObjectDelete(name2); ObjectDelete(name3);ObjectDelete(name4); ObjectDelete(name5); } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { ObjectCreate(0,name1,OBJ_LABEL,0,0,0); ObjectSetInteger(0,name1,OBJPROP_XDISTANCE,20); ObjectSetInteger(0,name1,OBJPROP_YDISTANCE,20); ObjectSetInteger(0,name1,OBJPROP_CORNER,0); ObjectCreate(0,name2,OBJ_LABEL,0,0,0); ObjectSetInteger(0,name2,OBJPROP_XDISTANCE,20); ObjectSetInteger(0,name2,OBJPROP_YDISTANCE,20+2*size); ObjectSetInteger(0,name2,OBJPROP_CORNER,0); ObjectCreate(0,name3,OBJ_LABEL,0,0,0); ObjectSetInteger(0,name3,OBJPROP_XDISTANCE,20); ObjectSetInteger(0,name3,OBJPROP_YDISTANCE,20+4*size); ObjectSetInteger(0,name3,OBJPROP_CORNER,0); ObjectCreate(0,name4,OBJ_LABEL,0,0,0); ObjectSetInteger(0,name4,OBJPROP_XDISTANCE,20); ObjectSetInteger(0,name4,OBJPROP_YDISTANCE,20+6*size); ObjectSetInteger(0,name4,OBJPROP_CORNER,0); ObjectCreate(0,name5,OBJ_LABEL,0,0,0); ObjectSetInteger(0,name5,OBJPROP_XDISTANCE,20); ObjectSetInteger(0,name5,OBJPROP_YDISTANCE,20+8*size); ObjectSetInteger(0,name5,OBJPROP_CORNER,0); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 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[]) { double atr1=ATR(1),atr2=ATR(2),atr3=ATR(3); int DayHL=int((iHigh(Symbol(),PERIOD_D1,0)-iLow(Symbol(),PERIOD_D1,0))/Point); int WeekHL=int((iHigh(Symbol(),PERIOD_W1,0)-iLow(Symbol(),PERIOD_W1,0))/Point); int MonthHL=int((iHigh(Symbol(),PERIOD_MN1,0)-iLow(Symbol(),PERIOD_MN1,0))/Point); if(atr1==0||atr2==0||atr3==0)return(rates_total); int perc1=int((DayHL*100)/atr1); int perc2=int((WeekHL*100)/atr2); int perc3=int((MonthHL*100)/atr3); ObjectSetText(name1,"DAILY(ATR"+string(ATRperiod)+"): "+DoubleToStr(atr1/10,0)+" ïï("+(string)perc1+"%)",size,NULL,col); ObjectSetText(name2,"WEEKLY(ATR"+string(ATRperiod)+"): "+DoubleToStr(atr2/10,0)+" ïï("+(string)perc2+"%)",size,NULL,col); ObjectSetText(name3,"MONTHLY(ATR"+string(ATRperiod)+"): "+DoubleToStr(atr3/10,0)+" ïï("+(string)perc3+"%)",size,NULL,col); ObjectSetText(name4,"Spread: "+(string)SymbolInfoInteger(Symbol(),SYMBOL_SPREAD),size,NULL,col); ObjectSetText(name5,"PntValue: "+DoubleToStr(SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)*10,1)+" $",size,NULL,col); return(rates_total); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double ATR(int type) { double res=0;int hl=0; double pnt=SymbolInfoDouble(Symbol(),SYMBOL_POINT); for(int i=1;i<=14;i++)hl+=int((high(type,i)-low(type,i))/pnt); res=hl/14; return(NormalizeDouble(res,1)); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double high(int type,int bar) { switch(type) { case 1:return(iHigh(Symbol(),PERIOD_D1,bar)); case 2:return(iHigh(Symbol(),PERIOD_W1,bar)); case 3:return(iHigh(Symbol(),PERIOD_MN1,bar)); default:return(0); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double low(int type,int bar) { switch(type) { case 1:return(iLow(Symbol(),PERIOD_D1,bar)); case 2:return(iLow(Symbol(),PERIOD_W1,bar)); case 3:return(iLow(Symbol(),PERIOD_MN1,bar)); default:return(0); } } //+------------------------------------------------------------------+