//+------------------------------------------------------------------ #property copyright "mladen" #property link "mladenfx@gmail.com" #property link "https://www.mql5.com" #property description "RSI of average" //+------------------------------------------------------------------ #property indicator_separate_window #property indicator_buffers 2 #property indicator_plots 1 #property indicator_label1 "RSI of average" #property indicator_type1 DRAW_COLOR_LINE #property indicator_color1 clrDarkGray,clrDeepSkyBlue,clrLightSalmon #property indicator_width1 2 //--- input parameters input int inpRsiPeriod = 14; // RSI period input int inpMaPeriod = 32; // Average period input ENUM_MA_METHOD inpMaMethod = MODE_EMA; // Average method input ENUM_APPLIED_PRICE inpPrice = PRICE_CLOSE; // Price //--- buffers declarations double val[],valc[]; //--- indicator handles int _maHandle,_rsiHandle; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,val,INDICATOR_DATA); SetIndexBuffer(1,valc,INDICATOR_COLOR_INDEX); //--- indicator short name assignment _maHandle=iMA(_Symbol,0,inpMaPeriod,0,inpMaMethod,inpPrice); if(_maHandle==INVALID_HANDLE) { return(INIT_FAILED); } _rsiHandle=iRSI(_Symbol,0,inpRsiPeriod,_maHandle); if(_rsiHandle==INVALID_HANDLE) { IndicatorRelease(_maHandle); return(INIT_FAILED); } IndicatorSetString(INDICATOR_SHORTNAME,"RSI of "+StringSubstr(EnumToString(inpMaMethod),5,-1)+" ("+(string)inpRsiPeriod+","+(string)inpMaPeriod+")"); //--- return (INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator de-initialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { } //+------------------------------------------------------------------+ //| 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[]) { if(Bars(_Symbol,_Period)0) ? (val[i]>val[i-1]) ? 1 :(val[i]