//+------------------------------------------------------------------+ //| TD_REI_v1.mq4 | //| Copyright © 2016, Forex-TSD.com | //| Written by IgorAD,igorad2003@yahoo.co.uk | //| http://finance.groups.yahoo.com/group/TrendLaboratory | //+------------------------------------------------------------------+ #property copyright "Copyright © 2016, Forex-TSD.com " #property link "http://www.forex-tsd.com/" #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 LightBlue #property indicator_width1 2 #property indicator_color2 Tomato #property indicator_width2 1 #property indicator_style2 3 #property indicator_level1 60 #property indicator_level2 -60 #property indicator_level3 0 //---- input parameters extern int BarsBack = 2; extern int Length = 8; // Period of evaluation extern int Smooth = 1; // Period of smoothing extern int Signal = 5; // Period of Signal Line extern int MA_Mode = 0; // Mode of Moving Average //---- buffers double REI[]; double SigREI[]; double RE[]; double REABS[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorBuffers(4); SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,REI); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(1,SigREI); SetIndexBuffer(2,RE); SetIndexBuffer(3,REABS); //---- name for DataWindow and indicator subwindow label string short_name="TD_REI("+BarsBack+","+Length+","+Smooth+","+Signal+",,"+MA_Mode+")"; IndicatorShortName(short_name); SetIndexLabel(0,"REI"); SetIndexLabel(1,"Signal"); //---- SetIndexDrawBegin(0,Length+Smooth+Signal); SetIndexDrawBegin(1,Length+Smooth+Signal); return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int shift, limit, counted_bars=IndicatorCounted(); //---- if ( counted_bars < 0 ) return(-1); if ( counted_bars ==0 ) limit=Bars-Length+Smooth+Signal-1; if ( counted_bars < 1 ) for(int i=1;i0) limit=Bars-counted_bars; limit--; for( shift=limit; shift>=0; shift--) { double High1 = iMA(NULL,0,Smooth,0,MA_Mode,PRICE_HIGH,shift); double High2 = iMA(NULL,0,Smooth,0,MA_Mode,PRICE_HIGH,shift+BarsBack); double Low1 = iMA(NULL,0,Smooth,0,MA_Mode,PRICE_LOW,shift); double Low2 = iMA(NULL,0,Smooth,0,MA_Mode,PRICE_LOW,shift+BarsBack); RE[shift] = (High1-High2)+(Low1-Low2); REABS[shift] = MathAbs(High1-High2)+MathAbs(Low1-Low2); } for( shift=limit; shift>=0; shift--) { double AvgRE =iMAOnArray(RE,0,Length,0,MA_Mode,shift); double AvgREABS=iMAOnArray(REABS,0,Length,0,MA_Mode,shift); if(AvgREABS > 0) REI[shift] = 100*AvgRE/AvgREABS; } for( shift=limit; shift>=0; shift--) SigREI[shift] = iMAOnArray(REI,0,Signal,0,MA_Mode,shift); //---- return(0); } //+------------------------------------------------------------------+