//+------------------------------------------------------------------+ //| Expected Rate of Return.mq4 | //| Copyright © 2010, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #property indicator_separate_window #property indicator_color1 Red //---- input parameters extern int ExtERRPeriod=20; extern int ExtERRMAMethod=0; extern int ExtERRAppliedPrice=0; extern int ExtERRShift=0; double ExtERRBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators string sShortName; //---- indicator buffer mapping SetIndexBuffer(0,ExtERRBuffer); //---- indicator line SetIndexStyle(0,DRAW_LINE); //---- line shifts when drawing SetIndexShift(0,ExtERRShift); //---- name for DataWindow and indicator subwindow label sShortName="ERR("+ExtERRPeriod+")"; IndicatorShortName(sShortName); SetIndexLabel(0,sShortName); //---- first values aren't drawn SetIndexDrawBegin(0,ExtERRPeriod); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i,nCountedBars; double Vf,Vi,Err; //---- insufficient data if(Bars<=ExtERRPeriod) return(0); //---- bars count that does not changed after last indicator launch. nCountedBars=IndicatorCounted(); //---- // ERR = (Vf - Vi) / Vi for (i=ExtERRPeriod; i <=Bars; i++) { Err = MathAbs(Close[i] - Close[i-ExtERRPeriod]) / Close[i-ExtERRPeriod]; ExtERRBuffer[i] = Err; } //---- return(0); } //+------------------------------------------------------------------+