
#property copyright "© 2008, London Forex Rush system"
#property link      "www.LondonForexRush.com"

#property indicator_separate_window
#property indicator_minimum 0.0
#property indicator_maximum 1.0
#property indicator_buffers 3
#property indicator_color1 GreenYellow
#property indicator_color2 Tomato
#property indicator_color3 Gray

double g_ibuf_76[];
double g_ibuf_80[];
double g_ibuf_84[];

void DrawBar(int ai_0, int ai_4) {
   if (ai_4 == 1) {
      g_ibuf_76[ai_0] = 1;
      g_ibuf_80[ai_0] = EMPTY_VALUE;
      g_ibuf_84[ai_0] = EMPTY_VALUE;
      return;
   }
   if (ai_4 == 2) {
      g_ibuf_76[ai_0] = EMPTY_VALUE;
      g_ibuf_80[ai_0] = 1;
      g_ibuf_84[ai_0] = EMPTY_VALUE;
      return;
   }
   if (ai_4 == 3) {
      g_ibuf_76[ai_0] = EMPTY_VALUE;
      g_ibuf_80[ai_0] = EMPTY_VALUE;
      g_ibuf_84[ai_0] = 1;
      return;
   }
   g_ibuf_76[ai_0] = EMPTY_VALUE;
   g_ibuf_80[ai_0] = EMPTY_VALUE;
   g_ibuf_84[ai_0] = EMPTY_VALUE;
}

int init() {
   SetIndexBuffer(0, g_ibuf_76);
   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(1, g_ibuf_80);
   SetIndexStyle(1, DRAW_HISTOGRAM);
   SetIndexBuffer(2, g_ibuf_84);
   SetIndexStyle(2, DRAW_HISTOGRAM);
   string ls_0 = "Market Trend indicator";
   IndicatorShortName(ls_0);
   SetIndexLabel(0, "Green");
   SetIndexLabel(1, "Red");
   SetIndexLabel(2, "Gray");
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   int li_12;
   int li_16;
   int l_ind_counted_0 = IndicatorCounted();
   if (l_ind_counted_0 < 0) return (-1);
   int li_4 = Bars - l_ind_counted_0;
   if (l_ind_counted_0 > 0) li_4++;
   int l_count_20 = 0;
   int l_count_24 = 0;
   double ld_28 = 0;
   for (int li_8 = li_4; li_8 >= 0; li_8--) {
      li_12 = li_8;
      l_count_20 = 0;
      l_count_24 = 0;
      while (li_12 < Bars && li_12 < li_8 + 20) {
         ld_28 = iMA(NULL, 0, 10, 0, MODE_SMA, PRICE_CLOSE, li_12) - iMA(NULL, 0, 30, 0, MODE_SMA, PRICE_CLOSE, li_12);
         if (ld_28 > 0.0) l_count_20++;
         else
            if (ld_28 < 0.0) l_count_24++;
         li_12++;
      }
      if (l_count_20 >= 20) li_16 = 1;
      else {
         if (l_count_24 >= 20) li_16 = 2;
         else li_16 = 3;
      }
      DrawBar(li_8, li_16);
   }
   return (0);
}