//+------------------------------------------------------------------+ //| RSIMA.mq5 | //| Copyright 2020, ernst | //| https://www.mql5.com/en/users/pippod | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, ernst" #property link "https://www.mql5.com/en/users/pippod" #property version "1.00" #property indicator_separate_window #property indicator_buffers 3 #property indicator_plots 2 //--- plot RSI #property indicator_label1 "RSI" #property indicator_type1 DRAW_LINE #property indicator_color1 clrDodgerBlue #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot MA #property indicator_label2 "MA" #property indicator_type2 DRAW_LINE #property indicator_color2 clrFireBrick #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- #property indicator_maximum 100 #property indicator_level2 70 #property indicator_level1 30 #property indicator_minimum 0 //--- input parameters input int RSIPeriod=14; input ENUM_APPLIED_PRICE RSIPrice=PRICE_CLOSE; input int MAPeriod=14; input int MAShift=0; input ENUM_MA_METHOD MAMethod=MODE_EMA; input ENUM_APPLIED_PRICE MAPrice=PRICE_CLOSE; input int MARSIPeriod=14; //--- indicator buffers double RSIBuffer[]; double MABuffer[]; double MARSIBuffer[]; //--- int handleRSI=INVALID_HANDLE,handleMA=INVALID_HANDLE,handleMARSI=INVALID_HANDLE; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- if((handleRSI=iRSI(_Symbol,_Period,RSIPeriod,RSIPrice))==INVALID_HANDLE || (handleMA=iMA(_Symbol,_Period,MAPeriod,MAShift,MAMethod,MAPrice))==INVALID_HANDLE || (handleMARSI=iRSI(_Symbol,_Period,MARSIPeriod,handleMA))==INVALID_HANDLE) return(INIT_FAILED); //--- IndicatorSetString(INDICATOR_SHORTNAME,StringFormat("RSI(%d) %s(%d,%d)",RSIPeriod,StringSubstr(EnumToString(MAMethod),5),MAPeriod,MARSIPeriod)); IndicatorSetInteger(INDICATOR_DIGITS,1); //--- indicator buffers mapping SetIndexBuffer(0,RSIBuffer,INDICATOR_DATA); SetIndexBuffer(1,MARSIBuffer,INDICATOR_DATA); SetIndexBuffer(2,MABuffer,INDICATOR_CALCULATIONS); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { //--- int toCopy=(rates_total!=prev_calculated)?rates_total-prev_calculated:1; //--- if(CopyBuffer(handleRSI ,0,0,toCopy,RSIBuffer )!=toCopy || CopyBuffer(handleMA ,0,0,toCopy,MABuffer )!=toCopy || CopyBuffer(handleMARSI,0,0,toCopy,MARSIBuffer)!=toCopy) return(0); //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+