#property copyright " "
#property link      ""

#property indicator_separate_window
#property indicator_minimum -2.0
#property indicator_maximum 2.0
#property indicator_buffers 2
#property indicator_color1 White
#property indicator_color2 Red

extern int TimeFrame = 60;
extern string Info = "H4";
extern int PeriodRSI = 14;
double g_ibuf_80[];
double g_ibuf_84[];

int init() {
   SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 3);
   SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 3);
   SetIndexBuffer(0, g_ibuf_80);
   SetIndexBuffer(1, g_ibuf_84);
   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
   string ls_0 = "RSI Filter(" + PeriodRSI + ")       " + Info;
   IndicatorShortName(ls_0);
   SetIndexLabel(0, "UpTrend");
   SetIndexLabel(1, "DownTrend");
   SetIndexDrawBegin(0, PeriodRSI);
   SetIndexDrawBegin(1, PeriodRSI);
   return (0);
}

int start() {
   int li_4;
   double l_irsi_8;
   for (int li_0 = Bars - PeriodRSI - 1; li_0 >= 0; li_0--) {
      l_irsi_8 = iRSI(NULL, TimeFrame, PeriodRSI, PRICE_CLOSE, li_0);
      if (l_irsi_8 > 70.0) li_4 = 1;
      if (l_irsi_8 < 30.0) li_4 = -1;
      if (li_4 > 0) {
         if (l_irsi_8 > 40.0) g_ibuf_80[li_0] = 1.0;
         else g_ibuf_80[li_0] = EMPTY_VALUE;
         g_ibuf_84[li_0] = 0;
      }
      if (li_4 < 0) {
         if (l_irsi_8 < 60.0) g_ibuf_84[li_0] = -1.0;
         else g_ibuf_84[li_0] = EMPTY_VALUE;
         g_ibuf_80[li_0] = 0;
      }
   }
   return (0);
}
