
#property copyright "Copyright © 2009, TradeWays"
#property link      "http://www.tradeways.org"

#property indicator_separate_window
#property indicator_minimum 0.0
#property indicator_maximum 6.0
#property indicator_buffers 8
#property indicator_color1 DodgerBlue
#property indicator_color2 RoyalBlue
#property indicator_color3 MediumBlue
#property indicator_color4 Blue
#property indicator_color5 Salmon
#property indicator_color6 Tomato
#property indicator_color7 OrangeRed
#property indicator_color8 Red

int g_period_76 = 10;
extern bool invert = FALSE;
extern string Pair = "";
extern string ____ = "enter pair in uppercase";
extern string _____ = "like EURUSD";
extern string ______ = "leave empty for current symbol";
extern string _______ = "if you have a mini account";
extern string ________ = "add a \"m\"  e.g EURUSDm ";
extern bool lablesOn = TRUE;
extern int BarLevel = 5;
double g_ibuf_140[];
double g_ibuf_144[];
double g_ibuf_148[];
double g_ibuf_152[];
double g_ibuf_156[];
double g_ibuf_160[];
double g_ibuf_164[];
double g_ibuf_168[];
double gda_unused_172[];

int init() {
   SetIndexBuffer(0, g_ibuf_140);
   SetIndexBuffer(1, g_ibuf_144);
   SetIndexBuffer(2, g_ibuf_148);
   SetIndexBuffer(3, g_ibuf_152);
   SetIndexBuffer(4, g_ibuf_156);
   SetIndexBuffer(5, g_ibuf_160);
   SetIndexBuffer(6, g_ibuf_164);
   SetIndexBuffer(7, g_ibuf_168);
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexStyle(2, DRAW_ARROW);
   SetIndexStyle(3, DRAW_ARROW);
   SetIndexStyle(4, DRAW_ARROW);
   SetIndexStyle(5, DRAW_ARROW);
   SetIndexStyle(6, DRAW_ARROW);
   SetIndexStyle(7, DRAW_ARROW);
   SetIndexEmptyValue(0, 0.0);
   SetIndexEmptyValue(1, 0.0);
   SetIndexEmptyValue(2, 0.0);
   SetIndexEmptyValue(3, 0.0);
   SetIndexEmptyValue(4, 0.0);
   SetIndexEmptyValue(5, 0.0);
   SetIndexEmptyValue(6, 0.0);
   SetIndexEmptyValue(7, 0.0);
   SetIndexArrow(0, 110);
   SetIndexArrow(1, 110);
   SetIndexArrow(2, 110);
   SetIndexArrow(3, 110);
   SetIndexArrow(4, 110);
   SetIndexArrow(5, 110);
   SetIndexArrow(6, 110);
   SetIndexArrow(7, 110);
   for (int li_0 = 0; li_0 < 8; li_0++) SetIndexLabel(li_0, NULL);
   if (Pair == "") Pair = Symbol();
   if (iClose(Pair, 0, 0) == 0.0) Pair = Symbol();
   IndicatorShortName(Pair + "(" + g_period_76 + ")");
   if (lablesOn) {
      SetIndexLabel(0, "rsi50-55");
      SetIndexLabel(1, "rsi55-60");
      SetIndexLabel(2, "rsi60-70");
      SetIndexLabel(3, "rsi>70");
      SetIndexLabel(4, "rsi45-50");
      SetIndexLabel(5, "rsi40-45");
      SetIndexLabel(6, "rsi30-40");
      SetIndexLabel(7, "rsi<30");
   }
   return (1);
}

int deinit() {
   return (0);
}

int start() {
   double ld_8;
   //if (TimeCurrent() > StrToTime("2050.04.20")) {
   //   Alert("New version available! Download it using re-activated link from Plimus");
   //   return;
   //}
   int li_0 = IndicatorCounted();
   if (li_0 < 0) return (-1);
   if (li_0 > 0) li_0--;
   for (int li_4 = Bars - li_0; li_4 >= 0; li_4--) {
      ld_8 = iRSI(Pair, 0, g_period_76, PRICE_CLOSE, li_4);
      if (invert == TRUE) ld_8 -= 2.0 * (ld_8 - 50.0);
      if (ld_8 < 50.0) {
         if (ld_8 < 50.0 && ld_8 > 45.0) drawblock(0, 0, 0, 0, 1, 0, 0, 0, li_4);
         else {
            if (ld_8 <= 45.0 && ld_8 > 40.0) drawblock(0, 0, 0, 0, 0, 1, 0, 0, li_4);
            else {
               if (ld_8 <= 40.0 && ld_8 > 30.0) drawblock(0, 0, 0, 0, 0, 0, 1, 0, li_4);
               else drawblock(0, 0, 0, 0, 0, 0, 0, 1, li_4);
            }
         }
      } else {
         if (ld_8 >= 50.0) {
            if (ld_8 >= 50.0 && ld_8 < 55.0) drawblock(1, 0, 0, 0, 0, 0, 0, 0, li_4);
            else {
               if (ld_8 >= 55.0 && ld_8 < 60.0) drawblock(0, 1, 0, 0, 0, 0, 0, 0, li_4);
               else {
                  if (ld_8 >= 60.0 && ld_8 < 70.0) drawblock(0, 0, 1, 0, 0, 0, 0, 0, li_4);
                  else drawblock(0, 0, 0, 1, 0, 0, 0, 0, li_4);
               }
            }
         }
      }
   }
   return (0);
}

void drawblock(int ai_0, int ai_4, int ai_8, int ai_12, int ai_16, int ai_20, int ai_24, int ai_28, int ai_32) {
   g_ibuf_140[ai_32] = ai_0 * BarLevel;
   g_ibuf_144[ai_32] = ai_4 * BarLevel;
   g_ibuf_148[ai_32] = ai_8 * BarLevel;
   g_ibuf_152[ai_32] = ai_12 * BarLevel;
   g_ibuf_156[ai_32] = ai_16 * BarLevel;
   g_ibuf_160[ai_32] = ai_20 * BarLevel;
   g_ibuf_164[ai_32] = ai_24 * BarLevel;
   g_ibuf_168[ai_32] = ai_28 * BarLevel;
}