//+------------------------------------------------------------------+
//|                                              RSI binary wave.mq4 |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      ""

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1  OrangeRed 
#property indicator_color2  DodgerBlue
//#property indicator_maximum  10
//#property indicator_minimum -10

//
//
//
//
//

extern int  RSIPeriod     = 2;
extern int  RSIPriceType  = PRICE_CLOSE;
extern int  RSIOverBought = 95;
extern int  RSIOverSold   = 5;


//
//
//
//
//
double ExtMapBuffer1[];
double ExtMapBuffer2[];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int init()
{
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexDrawBegin(0,RSIPeriod);
   SetIndexStyle(0,DRAW_HISTOGRAM);

   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexDrawBegin(1,RSIPeriod);   
   SetIndexStyle(1,DRAW_HISTOGRAM);
      
   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--)
   {

     ExtMapBuffer1[i] = 0;

      double rsicM1 = iRSI(NULL,PERIOD_M1,RSIPeriod,RSIPriceType,i);
      double rsipM1 = iRSI(NULL,PERIOD_M1,RSIPeriod,RSIPriceType,i+1);
         
      if (rsicM1>RSIOverBought   && rsipM1<RSIOverBought)   ExtMapBuffer1[i] =  1;
      if (rsicM1<RSIOverSold && rsipM1>RSIOverSold) ExtMapBuffer2[i] = -1;

      double rsicM5 = iRSI(NULL,PERIOD_M5,RSIPeriod,RSIPriceType,i);
      double rsipM5 = iRSI(NULL,PERIOD_M5,RSIPeriod,RSIPriceType,i+1);
         
      if (rsicM5>RSIOverBought   && rsipM5<RSIOverBought)   ExtMapBuffer1[i] = ExtMapBuffer1[i] + 2;
      if (rsicM5<RSIOverSold && rsipM5>RSIOverSold) ExtMapBuffer2[i] = ExtMapBuffer1[i] - 2;

      double rsicM15 = iRSI(NULL,PERIOD_M15,RSIPeriod,RSIPriceType,i);
      double rsipM15 = iRSI(NULL,PERIOD_M15,RSIPeriod,RSIPriceType,i+1);
         
      if (rsicM15>RSIOverBought   && rsipM15<RSIOverBought)   ExtMapBuffer1[i] = ExtMapBuffer1[i] + 3;
      if (rsicM15<RSIOverSold && rsipM15>RSIOverSold) ExtMapBuffer2[i] = ExtMapBuffer1[i] - 3;

      double rsicM30 = iRSI(NULL,PERIOD_M30,RSIPeriod,RSIPriceType,i);
      double rsipM30 = iRSI(NULL,PERIOD_M30,RSIPeriod,RSIPriceType,i+1);
         
      if (rsicM30>RSIOverBought   && rsipM30<RSIOverBought)   ExtMapBuffer1[i] = ExtMapBuffer1[i] + 4;
      if (rsicM30<RSIOverSold && rsipM30>RSIOverSold) ExtMapBuffer2[i] = ExtMapBuffer1[i] - 4;

      double rsicH1 = iRSI(NULL,PERIOD_H1,RSIPeriod,RSIPriceType,i);
      double rsipH1 = iRSI(NULL,PERIOD_H1,RSIPeriod,RSIPriceType,i+1);
         
      if (rsicH1>RSIOverBought   && rsipH1<RSIOverBought)   ExtMapBuffer1[i] = ExtMapBuffer1[i] + 5;
      if (rsicH1<RSIOverSold && rsipH1>RSIOverSold) ExtMapBuffer2[i] = ExtMapBuffer1[i] - 5;

      double rsicH4 = iRSI(NULL,PERIOD_H4,RSIPeriod,RSIPriceType,i);
      double rsipH4 = iRSI(NULL,PERIOD_H4,RSIPeriod,RSIPriceType,i+1);
         
      if (rsicH4>RSIOverBought   && rsipH4<RSIOverBought)   ExtMapBuffer1[i] = ExtMapBuffer1[i] + 6;
      if (rsicH4<RSIOverSold && rsipH4>RSIOverSold) ExtMapBuffer2[i] = ExtMapBuffer1[i] - 6;

      double rsicD1 = iRSI(NULL,PERIOD_D1,RSIPeriod,RSIPriceType,i);
      double rsipD1 = iRSI(NULL,PERIOD_D1,RSIPeriod,RSIPriceType,i+1);
         
      if (rsicD1>RSIOverBought   && rsipD1<RSIOverBought)   ExtMapBuffer1[i] = ExtMapBuffer1[i] + 7;
      if (rsicD1<RSIOverSold && rsipD1>RSIOverSold) ExtMapBuffer2[i] = ExtMapBuffer1[i] - 7;

      double rsicW1 = iRSI(NULL,PERIOD_W1,RSIPeriod,RSIPriceType,i);
      double rsipW1 = iRSI(NULL,PERIOD_W1,RSIPeriod,RSIPriceType,i+1);
         
      if (rsicW1>RSIOverBought   && rsipW1<RSIOverBought)   ExtMapBuffer1[i] = ExtMapBuffer1[i] + 8;
      if (rsicW1<RSIOverSold && rsipW1>RSIOverSold) ExtMapBuffer2[i] = ExtMapBuffer1[i] - 8;

      double rsicMN1 = iRSI(NULL,PERIOD_MN1,RSIPeriod,RSIPriceType,i);
      double rsipMN1 = iRSI(NULL,PERIOD_MN1,RSIPeriod,RSIPriceType,i+1);
         
      if (rsicMN1>RSIOverBought   && rsipMN1<RSIOverBought)   ExtMapBuffer1[i] = ExtMapBuffer1[i] + 9;
      if (rsicMN1<RSIOverSold && rsipMN1>RSIOverSold) ExtMapBuffer2[i] = ExtMapBuffer1[i] - 9;


   }                        
   return(0);
}