//+------------------------------------------------------------------+
//|                                                Composite RSI.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//+------------------------------------------------------------------+
#property indicator_separate_window

#include <hanover --- function header (np).mqh>

#property indicator_buffers 1
#property indicator_color1 Yellow
#property indicator_levelcolor Silver
#property indicator_levelstyle STYLE_DOT
#property indicator_level1 30
#property indicator_level2 50
#property indicator_level3 70
#property indicator_minimum 0
#property indicator_maximum 100

extern   string   RSI_TFs             = "H4,D1,W1,MN";
extern   string   RSI_periods         = "2,9";
extern   int      RSI_applied_price   = PRICE_CLOSE;

double buffer0[];

datetime   prev_time;
string     arr[20], IndiName, RSITF[9];
int        vis, RefreshEveryXMins, nRSIP, nRSITF, RSIP[10];
bool       FirstTime;

//+------------------------------------------------------------------+
int init() {
//+------------------------------------------------------------------+
  IndiName = "Composite RSI";
  IndicatorShortName(IndiName);

  SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,Yellow);
  SetIndexShift(0,0);
  SetIndexDrawBegin(0,0);
  SetIndexBuffer(0,buffer0);

  nRSITF = StrToStringArray(RSI_TFs,RSITF);
  nRSIP  = StrToIntegerArray(RSI_periods,RSIP);

  return(0);
}

//+------------------------------------------------------------------+
int deinit()   {
//+------------------------------------------------------------------+
   return(0);
}

//+------------------------------------------------------------------+
int start()  {
//+------------------------------------------------------------------+
  int limit;
  int counted_bars=IndicatorCounted();
  if(counted_bars<0) return(-1);
  if(counted_bars>0) counted_bars--;
  limit=Bars-counted_bars;
  
  for (int x=0; x<limit; x++)  {
    double RSItotal=0;
    for (int j=0; j<nRSITF; j++)  {
      for (int k=0; k<nRSIP; k++)   {
        datetime x_dt = Time[x];
        int x_shift   = iBarShift(Symbol(),StrToTF(RSITF[j]),x_dt,false);
        RSItotal += iRSI(Symbol(), StrToTF(RSITF[j]), RSIP[k], RSI_applied_price, x_shift);
    } }
    double RSI = DivZero(RSItotal,nRSITF*nRSIP);
    buffer0[x] = RSI;
  }
  return(0);
}

//+------------------------------------------------------------------+
#include <hanover --- extensible functions (np).mqh>

