//+------------------------------------------------------------------+
//|                                                       RSI_MA.mq4 |
//|                                   Copyright © 2008, Robert Hill. |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Robert Hill."
#property link      ""

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
//---- input parameters
extern int RSI_Period = 8;
extern int RSI_MA_Period = 8;    // MA on RSI period to use
extern int MA_Mode = MODE_EMA;
//---- buffers
double RSI[];
double MA[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;

   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(0,RSI);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(1,MA);
//---- name for DataWindow and indicator subwindow label
   short_name="RSI_MA("+RSI_Period+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----
   SetIndexDrawBegin(0,RSI_Period);

   if (MA_Mode > 3) MA_Mode = MODE_EMA;

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Relative Strength Index                                          |
//+------------------------------------------------------------------+
int start()
  {
   int    i,limit,counted_bars=IndicatorCounted();
   double temp;

//----
   if(counted_bars<0) return(-1);
//----
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   for( i=0; i<limit; i++)
     {
      RSI[i] = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i);
     }
   for( i=0; i<limit; i++)
     {

       MA[i] = iMAOnArray(RSI,Bars,RSI_MA_Period,0,MA_Mode,i);
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+