//+------------------------------------------------------------------+
//| 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 3

#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 bool Show_vertical_lines = true;
extern color Down_color  = clrRed; 
extern color Up_color  = clrGreen; 
extern bool  Show_vertical_labels = false;
extern int Vertical_Line_style = 2;
// Global module varables
double RSIline[];
double Greenline[];
double Redline[];
double trend[];
//-----------------------------------------------------------------------------
// function: init()
// Description: Custom indicator initialization function.
//-----------------------------------------------------------------------------
int init()
{
  IndicatorBuffers(4);

  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);
  
  SetIndexBuffer(3, trend);
  
  IndicatorDigits(1);
  IndicatorShortName(INDICATOR_NAME);
  return(0);
}
//-----------------------------------------------------------------------------
// function: deinit()
// Description: Custom indicator deinitialization function.
//-----------------------------------------------------------------------------
int deinit()
{
  for (int i=0; i<Bars; i++) {
  ObjectDelete(0,"TMS1"+i);
  ObjectDelete(0,"TMS2"+i);
  }
   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);
    Greenline[i]=iMAOnArray(RSIline,0,Green_Period,0,Green_Mode,i);
    Redline[i]=iMAOnArray(RSIline,0,Red_Period,0,Red_Mode,i);  
  } 
   for ( i=0; i<Bars; i++) {
   if(Show_vertical_lines){
   if(Greenline[i]>Redline[i] && Greenline[i+1]<Redline[i+1] ){
 	if(ObjectFind("TMS1"+i) != 0) {
   ObjectCreate("TMS1"+i, OBJ_VLINE, 0,Time[i],Time[i]);
   ObjectSet("TMS1"+i, OBJPROP_COLOR,Up_color);
   ObjectSet("TMS1"+i, OBJPROP_STYLE,Vertical_Line_style);
   ObjectSet("TMS1"+i,OBJPROP_BACK,!Show_vertical_labels);
   } else{ ObjectMove("TMS1"+i, 0,Time[i],Time[i]); }}
   if(Greenline[i]<Redline[i] && Greenline[i+1]>Redline[i+1] ){
   if(ObjectFind("TMS2"+i) != 0) {
   ObjectCreate("TMS2"+i, OBJ_VLINE, 0,Time[i],Time[i]);
   ObjectSet("TMS2"+i, OBJPROP_COLOR,Down_color);
   ObjectSet("TMS2"+i, OBJPROP_STYLE,Vertical_Line_style);
   ObjectSet("TMS2"+i,OBJPROP_BACK,!Show_vertical_labels);
   } else{ ObjectMove("TMS2"+i, 0,Time[i],Time[i]); }}
  }}   
  return(0);
}


//+------------------------------------------------------------------+