//+------------------------------------------------------------------+ //| osfx.RMI_HTF.v03.mq5 | //| @2017, osfx | //| https://www.forexfactory.com/osfx | //+------------------------------------------------------------------+ #property copyright "@2017, osfx" #property link "https://www.forexfactory.com/osfx" #property version "3.00" #property indicator_separate_window #property indicator_buffers 5 #property indicator_plots 3 #property indicator_type1 DRAW_NONE #property indicator_type2 DRAW_COLOR_LINE #property indicator_color2 clrGray,clrRed,clrDodgerBlue,C'96,96,96',C'160,160,160' #property indicator_width2 3 #property indicator_type3 DRAW_COLOR_ARROW #property indicator_color3 clrBlack #property indicator_width3 2 #property indicator_maximum 100 #property indicator_minimum 0 //--- #define BarsTotal rates_total #define PrevBarsTotal prev_calculated //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ input string _1 = " "; // -------------------- SOURCE -------------------- input string IndicatorPath ="osfx.RMI.v03.ex5"; // Indicator path relative to root directory (MQL5\Indicators\) input string _2 = " "; // -------------------- CACLULATION -------------------- input ENUM_TIMEFRAMES RMITimeframe = PERIOD_CURRENT; // RMI timeframe input int RMILength = 12; // RMI length input int RMIShift = 3; // RMI shift input ENUM_APPLIED_PRICE RMIAppliedPrice = PRICE_CLOSE; // RMI applied price input double RMILevel = 30.0; // RMI levels (0 to disable) input string _3 = ""; // -------------------- FILTER -------------------- input double MinChange_ = 0.0; // Minimum change filter(0 to disable) input double Acceleration_ = 0.0; // Minimum acceleration filter (0 to disable) input string _4 = ""; // -------------------- APPEARANCE -------------------- input bool DisplayCurrentBar = true; // Display data for current (=open) bar input bool Interpolation = false; // Interpolate HTF data ? //--- double Acceleration; double DisplayArrow[]; double DisplayArrowColor[]; double DisplayLine[]; double DisplayLineColor[]; double IntBuffer1[]; double MinChange; double RMI[1]; int CountFrom; int HTFFactor=(int)PeriodSeconds(RMITimeframe)/PeriodSeconds(_Period); int RMIHandle; int InterpolationStartPos=0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { RMIHandle=iCustom(_Symbol,RMITimeframe,IndicatorPath, "",RMILength,RMIShift,RMIAppliedPrice,0.0, "",0.0,0.0, "",true, "",false); if(RMIHandle==INVALID_HANDLE) { Print("Source indicator cannot be loaded - please check path/file name"); return(INIT_FAILED); } if(RMITimeframe<=_Period) { Print("Parameter error: selected timeframe must be larger than chart timeframe"); return(INIT_FAILED); } if(RMILength<=0 || RMIShift<=0) { Print("Parameter error: RMI length / shift must be at least 1"); return(INIT_FAILED); } MinChange =MinChange_; Acceleration=Acceleration_; if(Acceleration==0.0) Acceleration=-999.0; //--- indicator buffers mapping SetIndexBuffer(0,IntBuffer1,INDICATOR_DATA);//Basic calculation SetIndexBuffer(1,DisplayLine,INDICATOR_DATA); SetIndexBuffer(2,DisplayLineColor,INDICATOR_COLOR_INDEX); SetIndexBuffer(3,DisplayArrow,INDICATOR_DATA); SetIndexBuffer(4,DisplayArrowColor,INDICATOR_COLOR_INDEX); string IndicatorName; StringConcatenate(IndicatorName,MQLInfoString(MQL_PROGRAM_NAME)," (",RMILength,",",RMIShift,",",EnumToString(RMITimeframe),")"); IndicatorSetString(INDICATOR_SHORTNAME,IndicatorName); IndicatorSetInteger(INDICATOR_DIGITS,2); if(RMILevel>0.0) { IndicatorSetInteger(INDICATOR_LEVELS,2); IndicatorSetInteger(INDICATOR_LEVELCOLOR,clrDarkGray); IndicatorSetDouble(INDICATOR_LEVELVALUE,0,RMILevel); IndicatorSetDouble(INDICATOR_LEVELVALUE,1,100-RMILevel); } PlotIndexSetInteger(2,PLOT_ARROW,158); PlotIndexSetString(0,PLOT_LABEL,IndicatorName); PlotIndexSetString(1,PLOT_LABEL,"Line properties"); PlotIndexSetString(2,PLOT_LABEL,"Arrow properties"); 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[]) { //--- Init variables if(BarsTotal-PrevBarsTotal<0 || BarsTotal-PrevBarsTotal>1) { CountFrom=2; ArrayInitialize(IntBuffer1,0.0); } else CountFrom=MathMin(BarsTotal-HTFFactor-1,PrevBarsTotal-1); //--- Main loop for(int Pos=CountFrom;Pos0.0 && IntBuffer1[Pos]>RMILevel && IntBuffer1[Pos-1]>RMILevel && IntBuffer1[Pos]<100-RMILevel && IntBuffer1[Pos-1]<100-RMILevel) { if(Diff>=MinChange && Acc >=Acceleration) DisplayLineColor[Pos]=4; else { if(Diff<=MinChange*-1 && Acc <=Acceleration*-1) DisplayLineColor[Pos]=3; else DisplayLineColor[Pos]=0; } } else { if(Diff>=MinChange && Acc >=Acceleration) DisplayLineColor[Pos]=2; else { if(Diff<=MinChange*-1 && Acc <=Acceleration*-1) DisplayLineColor[Pos]=1; else DisplayLineColor[Pos]=0; } } } return(BarsTotal); } //+------------------------------------------------------------------+ void InterpolateHTFData(int iStartPos, int iPos, double &iSource[], double &iDestination[]) { int iGap=iPos-iStartPos; double iPriceDifference=(iSource[iPos]-iSource[iStartPos]); for(int i=1;i<=iGap;i++) iDestination[iStartPos+i]=iSource[iStartPos]+iPriceDifference*i/iGap; } //+------------------------------------------------------------------+