//+------------------------------------------------------------------+
//|                                           RSI_MA Cross Histo.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 SteelBlue
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
#property indicator_color2 Crimson 
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2

//---- input parameters
extern int      RSI_Period = 21;
extern int      MinRSIcross = 0;
extern int      FastMaPeriod = 5;
extern int      SlowMaPeriod = 12;
extern int      MaType = 1; 
extern int      MinMAcross = 0;
extern int      shift = 1;

//---- indicator buffers
double UpHisto[];
double DnHisto[];

double points;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexBuffer(0,UpHisto);
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(1,DnHisto);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   
//----
   if(Digits==3 || Digits==5)
      points = Point*10;
  else points = Point;
  
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   if (Bars <= RSI_Period+1) return (0);
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
//----
   for (int i = limit; i >= 0; i--) {
   double RSI = iRSI(NULL,0,RSI_Period,PRICE_CLOSE,i+shift);
   double FastMa = iMA(NULL,0,FastMaPeriod,shift,MaType,PRICE_CLOSE,i);
   double SlowMa = iMA(NULL,0,SlowMaPeriod,shift,MaType,PRICE_CLOSE,i);
   
           UpHisto[i] = 0;
           DnHisto[i] = 0;
     if(RSI>50+MinRSIcross){
       if(FastMa>SlowMa+MinMAcross*points)
           UpHisto[i] = 1;
           }
     if(RSI<50-MinRSIcross){
       if(FastMa<SlowMa-MinMAcross*points)
           DnHisto[i] = 1;
           }
         }
   
//----
   return(0);
  }
 
//+------------------------------------------------------------------+