//+------------------------------------------------------------------+
//|			                                    TDI-RT-H-RSI.mq4     |
//|         						          Copyright © 2012 Zoidy |
//+------------------------------------------------------------------+

#property indicator_buffers 4
#property indicator_color1 Green
#property indicator_color2 Yellow
#property indicator_color3 Red
#property indicator_color4 Blue
#property indicator_width1  4
#property indicator_width2  4
#property indicator_width3  4
#property indicator_width4  4
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100

extern int signal_level = 50;

extern string TDI_RT_Indicator_Name = "TDI_RT";

double longAboveTSL[];
double longBelowTSL[];
double shortBelowTSL[];
double shortAboveTSL[];

int init()
  {
   IndicatorShortName("TDI RT RSI");
   SetIndexBuffer(0,longAboveTSL);
   SetIndexBuffer(1,longBelowTSL);
   SetIndexBuffer(2,shortBelowTSL);
   SetIndexBuffer(3,shortAboveTSL);
   
   SetIndexStyle(0,DRAW_HISTOGRAM); 
   SetIndexStyle(1,DRAW_HISTOGRAM); 
   SetIndexStyle(2,DRAW_HISTOGRAM); 
   SetIndexStyle(3,DRAW_HISTOGRAM); 
   
   SetIndexLabel(0, "RSI Up - Above TSL - Long" ); 
   SetIndexLabel(1, "RSI Up - Below TSL" ); 
   SetIndexLabel(2, "RSI Down - Below TSL - Short" ); 
   SetIndexLabel(3, "RSI Down - Above TSL" );

   return(0);
  }

double rsiPriceLine0, rsiPriceLine1, tradeSignalLine0;

int start()
  {
   int counted_bars=IndicatorCounted();
   int limit = Bars-counted_bars-1;

   for (int i=limit;i>=0;i--)  
      {
		/*
		   SetIndexBuffer(1,UpZone); SetIndexLabel(1,"VB High"); 
		   SetIndexBuffer(2,marketBaseLineBuf); SetIndexLabel(2,"Market Base Line"); 
		   SetIndexBuffer(3,DnZone); SetIndexLabel(3,"VB Low"); 
		   SetIndexBuffer(4,rsiPriceLineBuf); SetIndexLabel(4,"RSI Price Line");
		   SetIndexBuffer(5,tradeSignalLineBuf); SetIndexLabel(5,"Trade Signal Line");
		*/
      	
      rsiPriceLine0 = iCustom(NULL, 0, TDI_RT_Indicator_Name, 4, i);
      rsiPriceLine1 = iCustom(NULL, 0, TDI_RT_Indicator_Name, 4, i+1);
      tradeSignalLine0 = iCustom(NULL, 0, TDI_RT_Indicator_Name, 5, i);
       
	  // work out histograms
	  longAboveTSL[i] = 0;
	  longBelowTSL[i] = 0;
	  shortBelowTSL[i] = 0;
	  shortAboveTSL[i] = 0;
	  
	  // RSI going up
	  if(rsiPriceLine0 > rsiPriceLine1) {
	  	if(rsiPriceLine0 > tradeSignalLine0) {
	      longAboveTSL[i] = signal_level;
	  	}
	  	else {
	      longBelowTSL[i] = signal_level;
	  	}
	  }
	  // RSI going down
	  else if(rsiPriceLine0 < rsiPriceLine1) {
	  	if(rsiPriceLine0 < tradeSignalLine0) {
	      shortBelowTSL[i] = signal_level;
	  	}
	  	else {
 	      shortAboveTSL[i] = signal_level;
 	   	}
 	  }
    } 
//----
   return(0);
  }

//+------------------------------------------------------------------+