//+------------------------------------------------------------------+
//| TMS RSI.mq4  Tekkies                                             |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 clrRed
#property indicator_width1 2
#property indicator_color2 clrGreen
#property indicator_width2 2
#property indicator_color3 CLR_NONE
#property indicator_width3 1
#property indicator_level1 32
#property indicator_level2 50
#property indicator_level3 68
#property indicator_levelstyle STYLE_DOT
#property indicator_levelcolor DimGray
#define INDICATOR_NAME "TMS RSI"
// Indicator parameters
extern int RSI_Period    = 13;            
extern int RSI_Price     =  0;    
extern int Green_Period  =  2;   
extern int Green_Mode    =  0;
extern int Red_Period    =  7;      
extern int Red_Mode      =  0; 
//extern int Yellow_Period = 34;      
//extern int Yellow_Mode   =  0;
// Global module varables
double RSIline[];
double Greenline[];
double Redline[];
//-----------------------------------------------------------------------------
// function: init()
// Description: Custom indicator initialization function.
//-----------------------------------------------------------------------------
int init()
{
  SetIndexStyle(0, DRAW_LINE);
  SetIndexBuffer(0, Redline);
  SetIndexLabel(0,"Red");
  
  SetIndexStyle(1, DRAW_LINE);
  SetIndexBuffer(1, Greenline);
  SetIndexLabel(1,"Green");
  
  SetIndexStyle(2, DRAW_NONE);
  SetIndexBuffer(2, RSIline);
  SetIndexLabel(2,NULL);
  
  IndicatorDigits(1);
  IndicatorShortName(INDICATOR_NAME);
  return(0);
}
//-----------------------------------------------------------------------------
// function: deinit()
// Description: Custom indicator deinitialization function.
//-----------------------------------------------------------------------------
int deinit()
{
   return (0);
}
///-----------------------------------------------------------------------------
// function: start()
// Description: Custom indicator iteration function.
//-----------------------------------------------------------------------------
int start()
{
  int iNewBars;
  int iCountedBars; 
  int i;  
  // Get unprocessed ticks
  iCountedBars=IndicatorCounted();
  if(iCountedBars < 0) return (-1); 
  if(iCountedBars>0) iCountedBars--;
  iNewBars=Bars-iCountedBars;
  // Calc TDI data
  for(i=iNewBars-1; i>=0; i--)
  {
    RSIline[i] = iRSI(NULL,0,RSI_Period,RSI_Price,i); 
  }
  for(i=iNewBars-1; i>=0; i--)
  {  
    Greenline[i]=iMAOnArray(RSIline,0,Green_Period,0,Green_Mode,i);
    Redline[i]=iMAOnArray(RSIline,0,Red_Period,0,Red_Mode,i);  
  } 
  return(0);
}
//+------------------------------------------------------------------+