//+------------------------------------------------------------------+
//|                                                       MA rsi.mq4 |
//|                                      Copyright © 2006, Eli hayun |
//|                                                                  |
//+------------------------------------------------------------------+
//mod2009fxtsd ki
#property copyright "Copyright © 2006, Eli hayun"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Orange
#property indicator_color2 RoyalBlue
#property indicator_color3 Red

#property indicator_width1     2
#property indicator_width2     2
#property indicator_width3     2

//---- input parameters
extern int       maPeriod =50;
extern int       maMethod =MODE_EMA;
extern int       maPrice  =PRICE_CLOSE;
extern int       rsiPeriod =40;
extern int       rsiPrice  =PRICE_CLOSE;
extern int       rsiUpperLevel =50;
extern int       rsiLowerLevel =50;



//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

   int limit;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- main loop
   
   for (int i =limit; i>= 0; i--)
   
     {
         double ma =  iMA(NULL,0,maPeriod, 0, maMethod, maPrice, i);
         double rsi= iRSI(NULL,0,rsiPeriod, rsiPrice, i);
        
               ExtMapBuffer1[i] = ma;  
               ExtMapBuffer2[i] = EMPTY_VALUE;  ExtMapBuffer3[i]=EMPTY_VALUE;

            if (rsi >rsiUpperLevel)
               ExtMapBuffer2[i] = ma; else      ExtMapBuffer2[i]=EMPTY_VALUE;
            
            if (rsi <rsiLowerLevel)
               ExtMapBuffer3[i] = ma; else      ExtMapBuffer3[i]=EMPTY_VALUE;
     

     }
     
   return(0);
  }
//+------------------------------------------------------------------+