//+------------------------------------------------------------------+ //| RsiWithBands.mq4 | //| Copyright 2019, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict #property indicator_separate_window #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_buffers 4 #property indicator_plots 4 //--- plot Rsi #property indicator_label1 "Rsi" #property indicator_type1 DRAW_LINE #property indicator_color1 clrWhite #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot BandUpper #property indicator_label2 "BandUpper" #property indicator_type2 DRAW_LINE #property indicator_color2 clrDeepSkyBlue #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot BandMiddle #property indicator_label3 "BandMiddle" #property indicator_type3 DRAW_LINE #property indicator_color3 clrDeepSkyBlue #property indicator_style3 STYLE_SOLID #property indicator_width3 1 //--- plot BandLower #property indicator_label4 "BandLower" #property indicator_type4 DRAW_LINE #property indicator_color4 clrDeepSkyBlue #property indicator_style4 STYLE_SOLID #property indicator_width4 1 //--- input parameters //--- indicator buffers double RsiBuffer[]; double BandUpperBuffer[]; double BandMiddleBuffer[]; double BandLowerBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,RsiBuffer); SetIndexBuffer(1,BandUpperBuffer); SetIndexBuffer(2,BandMiddleBuffer); SetIndexBuffer(3,BandLowerBuffer); //--- 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[]) { int iLimit = MathMin(rates_total-1,rates_total-prev_calculated); for (int i=iLimit; i>=0; i--) { RsiBuffer[i] = iRSI(Symbol(),Period(),14,PRICE_CLOSE,i); BandUpperBuffer[i] = iBandsOnArray(RsiBuffer,0,20,2,0,MODE_UPPER,i); BandMiddleBuffer[i] = iMAOnArray(RsiBuffer,0,20,0,MODE_SMA,i); BandLowerBuffer[i] = iBandsOnArray(RsiBuffer,0,20,2,0,MODE_LOWER,i); } return(rates_total); } //+------------------------------------------------------------------+