//+------------------------------------------------------------------+
//|                                                    MA of RSI.mq4 |
//|                                            http://forexBaron.net |
//+------------------------------------------------------------------+
/* for iCustom:
   double emaOfrsiVal = iCustom(symbol,timeFrame,"MA of RSI",rsiPeriod,MA_Period,ma_shift,ma_method,5000,0,shift);
*/

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Lime
#property indicator_level1 20
#property indicator_level2 50
#property indicator_level3 80

/*
PRICE_CLOSE 0 Close price. 
PRICE_OPEN 1 Open price. 
PRICE_HIGH 2 High price. 
PRICE_LOW 3 Low price. 
PRICE_MEDIAN 4 Median price, (high+low)/2. 
PRICE_TYPICAL 5 Typical price, (high+low+close)/3. 
PRICE_WEIGHTED 6 Weighted close price, (high+low+close+close)/4. 
*/

//---- input parameters
extern int rsiPeriod = 5;
extern int MA_Period = 9;
extern int MA_Shift = 0;
extern int MA_Method = 0;
extern int NumberOfBarsToCalculate = 5000;
 
//---- indicator buffers
double Ma[];
double RSI[];
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
  int init()
  {
   //Comment("");
   IndicatorBuffers(4);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
   SetIndexBuffer(0,Ma);
   SetIndexLabel(0,"MA");
   SetIndexBuffer(1,RSI);
   SetIndexLabel(1,"RSI");
   
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//----
 
   SetIndexEmptyValue(0,0);
   SetIndexEmptyValue(1,0);
//----
   return(0);
}
  
int start() {
 string short_name = "RSI["+rsiPeriod+"] + MA["+MA_Period+"]";
 IndicatorShortName(short_name);
 
 int shift;

 for(shift=NumberOfBarsToCalculate-1;shift>=0;shift--) {
  RSI[shift] = iRSI(NULL,0,rsiPeriod,PRICE_CLOSE,shift);    
 }
 
 for(shift=NumberOfBarsToCalculate-1;shift>=0;shift--){
  Ma[shift] = iMAOnArray(RSI,0,MA_Period,MA_Shift,MA_Method,shift);
 }
return(0);
}