//+------------------------------------------------------------------+
//|                                              RSI binary wave.mq4 |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      ""

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1  Red
#property indicator_maximum  1
#property indicator_minimum -1

//
//
//
//
//

extern int  RSIPeriod     = 10;
extern int  RSIPriceType  = PRICE_CLOSE;
extern int  RSIOverBought = 70;
extern int  RSIOverSold   = 30;

//
//
//
//
//

double ExtMapBuffer1[];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int init()
{
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexDrawBegin(0,RSIPeriod);
   IndicatorShortName("RSI b.wave ("+RSIPeriod+")");
   IndicatorDigits(0);
   return(0);
}

int deinit()
{
   return(0);
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int start()
{
   int  counted_bars=IndicatorCounted();
   int  i,limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
      limit=Bars-counted_bars;

   for(i=limit; i>=0; i--)
   {
      double rsic = iRSI(NULL,0,RSIPeriod,RSIPriceType,i);
      double rsip = iRSI(NULL,0,RSIPeriod,RSIPriceType,i+1);
         
      //
      //
      //
      //
      //
         
      ExtMapBuffer1[i] = 0;
         if (rsic>RSIOverSold   && rsip<RSIOverSold)   ExtMapBuffer1[i] =  1;
         if (rsic<RSIOverBought && rsip>RSIOverBought) ExtMapBuffer1[i] = -1;
   }                        
   return(0);
}