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

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Fuchsia

extern double AccountSize = 10000.0;
extern int TokyoStart = 0;
extern int TokyoEnd = 8;
extern color TokyoHighColor = Aqua;
extern color TokyoLowColor = Fuchsia;
extern int LondonStart = 9;
extern int Countdown = 2;
extern color CountdownColor = Aqua;
extern color TextColor = Yellow;
extern double RiskRatio = 0.03;
int g_color_124 = LimeGreen;
int g_color_128 = OrangeRed;
int g_color_132 = Gray;
int g_fontsize_136 = 30;
string gs_arial_140 = "Arial";
string gs_mainind1_148 = "MainInd1";
int g_fontsize_156 = 12;
string gs_arial_160 = "Arial";
string g_name_168 = "Countdown1";
int g_fontsize_176 = 10;
string gs_arial_180 = "Arial";
double g_ibuf_188[];
double g_ibuf_192[];
int gi_196 = 1;
int gi_200 = 0;
bool gi_204 = TRUE;
int gi_208 = 0;
double gd_212 = 0.0;
double gd_220 = 0.0;

void objectCreate(string a_name_0, int a_x_8, int a_y_12, string a_text_16 = "-", int a_fontsize_24 = 40, string a_fontname_28 = "Arial", color a_color_36 = -1) {
   int l_window_40 = WindowOnDropped();
   ObjectCreate(a_name_0, OBJ_LABEL, l_window_40, 0, 0);
   ObjectSet(a_name_0, OBJPROP_CORNER, 0);
   ObjectSet(a_name_0, OBJPROP_COLOR, a_color_36);
   ObjectSet(a_name_0, OBJPROP_XDISTANCE, a_x_8);
   ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_12);
   ObjectSetText(a_name_0, a_text_16, a_fontsize_24, a_fontname_28, a_color_36);
}

int HourToTime(int ai_0, int ai_4 = 0, int ai_8 = -1) {
   int li_ret_12;
   int l_index_16 = 0;
   if (ai_0 < 0 || ai_0 > 23) return (0);
   if (ai_8 == -1) li_ret_12 = StrToTime(DoubleToStr(Year(), 0) + "." + DoubleToStr(Month(), 0) + "." + DoubleToStr(Day(), 0) + " " + DoubleToStr(ai_0, 0) + ":00");
   else {
      li_ret_12 = StrToTime(DoubleToStr(TimeYear(Time[ai_8]), 0) + "." + DoubleToStr(TimeMonth(Time[ai_8]), 0) + "." + DoubleToStr(TimeDay(Time[ai_8]), 0) + " " + DoubleToStr(ai_0, 0) +
         ":00");
   }
   if (ai_4 == -1) {
      for (l_index_16 = ai_8; l_index_16 < Bars && TimeDay(Time[ai_8]) == TimeDay(Time[l_index_16]); l_index_16++) {
      }
      li_ret_12 = StrToTime(DoubleToStr(TimeYear(Time[l_index_16]), 0) + "." + DoubleToStr(TimeMonth(Time[l_index_16]), 0) + "." + DoubleToStr(TimeDay(Time[l_index_16]), 0) +
         " " + DoubleToStr(ai_0, 0) + ":00");
   } else
      if (ai_4 == 1) li_ret_12 += 86400;
   return (li_ret_12);
}

int init() {
   SetIndexBuffer(0, g_ibuf_188);
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 4, TokyoHighColor);
   SetIndexBuffer(1, g_ibuf_192);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 4, TokyoLowColor);
   string ls_0 = "Main Indicator";
   IndicatorShortName(ls_0);
   SetIndexLabel(0, "Tokyo High");
   SetIndexLabel(1, "Tokyo Low");
   gi_208 = LondonStart + Countdown;
   if (gi_208 > 23) gi_208 -= 24;
   return (0);
}

int deinit() {
   ObjectDelete(gs_mainind1_148);
   ObjectDelete(g_name_168);
   ObjectDelete("lmn1");
   ObjectDelete("lmn2");
   ObjectDelete("lmn3");
   ObjectDelete("lmn4");
   ObjectDelete("lmn5");
   ObjectDelete("lmn6");
   ObjectDelete("lmn7");
   return (0);
}

int start() {
   double ld_16;
   double ld_24;
   string l_dbl2str_40;
   string ls_48;
   double ld_104;
   double ld_112;
   double ld_120;
   double ld_128;
   if (TokyoStart < 0 || TokyoStart > 23) return (1);
   if (TokyoEnd < 0 || TokyoEnd > 23) return (1);
   if (LondonStart < 0 || LondonStart > 23) return (2);
   if (gi_208 < 0 || gi_208 > 23) return (2);
   if (Countdown < 0 || Countdown > 24) return (2);
   if (Bars < 50) return (3);
   double ld_0 = 0.9 * iATR(NULL, PERIOD_D1, 14, 0);
   int l_index_8 = 0;
   int l_index_12 = 0;
   int li_32 = 0;
   int li_36 = 0;
   string l_dbl2str_56 = "";
   int li_64 = 0;
   int li_68 = 0;
   int li_72 = 0;
   int li_76 = 0;
   int li_80 = 0;
   int li_84 = 0;
   int li_88 = 0;
   int li_92 = 0;
   int li_96 = 0;
   int li_100 = 0;
   double l_spread_136 = 0;
   double l_tickvalue_144 = 0;
   bool li_152 = FALSE;
   bool li_156 = FALSE;
   int l_ind_counted_160 = IndicatorCounted();
   int li_164 = Bars - l_ind_counted_160;
   double ld_168 = 0;
   if (l_ind_counted_160 > 0) li_164++;
   if (gi_204) {
      objectCreate(gs_mainind1_148, 10, 25, "", g_fontsize_136, gs_arial_140, g_color_132);
      objectCreate(g_name_168, 10, 70, "", g_fontsize_156, gs_arial_160, CountdownColor);
      objectCreate("lmn1", 10, 110, "-", g_fontsize_176, gs_arial_180, TextColor);
      objectCreate("lmn2", 10, 140, "-", g_fontsize_176, gs_arial_180, TextColor);
      objectCreate("lmn3", 10, 160, "-", g_fontsize_176, gs_arial_180, TextColor);
      objectCreate("lmn4", 10, 190, "-", g_fontsize_176, gs_arial_180, TextColor);
      objectCreate("lmn5", 10, 210, "-", g_fontsize_176, gs_arial_180, TextColor);
      objectCreate("lmn6", 10, 240, "-", g_fontsize_176, gs_arial_180, TextColor);
      objectCreate("lmn7", 10, 260, "-", g_fontsize_176, gs_arial_180, TextColor);
   }
   for (l_index_8 = li_164; l_index_8 >= 0; l_index_8--) {
      li_84 = HourToTime(TokyoStart, 0, l_index_8);
      if (TokyoStart > TokyoEnd) li_88 = HourToTime(TokyoEnd, 1, l_index_8);
      else li_88 = HourToTime(TokyoEnd, 0, l_index_8);
      li_96 = HourToTime(TokyoEnd, 0, l_index_8);
      if (TokyoStart > TokyoEnd) li_92 = HourToTime(TokyoStart, -1, l_index_8);
      else li_92 = HourToTime(TokyoStart, 0, l_index_8);
      li_152 = FALSE;
      if (Time[l_index_8] >= li_84 && Time[l_index_8] <= li_88) {
         li_152 = TRUE;
         li_100 = li_84;
      }
      if (Time[l_index_8] >= li_92 && Time[l_index_8] <= li_96) {
         li_152 = TRUE;
         li_100 = li_92;
      }
      if (li_152) {
         if (g_ibuf_188[l_index_8 + 1] != EMPTY_VALUE) {
            if (High[l_index_8] <= g_ibuf_188[l_index_8 + 1]) g_ibuf_188[l_index_8] = g_ibuf_188[l_index_8 + 1];
            else {
               g_ibuf_188[l_index_8] = High[l_index_8];
               for (l_index_12 = l_index_8 + 1; Time[l_index_12] >= li_100 && l_index_12 < Bars; l_index_12++) g_ibuf_188[l_index_12] = High[l_index_8];
            }
         } else g_ibuf_188[l_index_8] = High[l_index_8];
         if (g_ibuf_192[l_index_8 + 1] != EMPTY_VALUE) {
            if (Low[l_index_8] >= g_ibuf_192[l_index_8 + 1]) g_ibuf_192[l_index_8] = g_ibuf_192[l_index_8 + 1];
            else {
               g_ibuf_192[l_index_8] = Low[l_index_8];
               for (l_index_12 = l_index_8 + 1; Time[l_index_12] >= li_100 && l_index_12 < Bars; l_index_12++) g_ibuf_192[l_index_12] = Low[l_index_8];
            }
         } else g_ibuf_192[l_index_8] = Low[l_index_8];
      }
   }
   int l_count_176 = 0;
   int l_count_180 = 0;
   for (l_index_8 = 1; l_index_8 <= 20; l_index_8++) {
      if (iMA(NULL, PERIOD_H1, 10, 0, MODE_SMA, PRICE_CLOSE, l_index_8 - 1) - iMA(NULL, PERIOD_H1, 30, 0, MODE_SMA, PRICE_CLOSE, l_index_8 - 1) > 0.0) l_count_176++;
      else
         if (iMA(NULL, PERIOD_H1, 10, 0, MODE_SMA, PRICE_CLOSE, l_index_8 - 1) - iMA(NULL, PERIOD_H1, 30, 0, MODE_SMA, PRICE_CLOSE, l_index_8 - 1) < 0.0) l_count_180++;
   }
   if (l_count_176 >= 20) gi_196 = 1;
   else {
      if (l_count_180 >= 20) gi_196 = 2;
      else gi_196 = 3;
   }
   ld_168 = gd_212 - gd_220;
   if (gi_196 == 1 && ld_168 < ld_0 / 2.0) gi_200 = 1;
   else {
      if (gi_196 == 2 && ld_168 < ld_0 / 2.0) gi_200 = 2;
      else gi_200 = 3;
   }
   li_64 = HourToTime(LondonStart);
   if (LondonStart > gi_208) li_68 = HourToTime(gi_208, 1, 0);
   else li_68 = HourToTime(gi_208);
   li_76 = HourToTime(gi_208);
   if (LondonStart > gi_208) li_72 = HourToTime(LondonStart, -1, 0);
   else li_72 = HourToTime(LondonStart);
   li_156 = FALSE;
   if (TimeCurrent() >= li_64 && TimeCurrent() <= li_68) {
      li_156 = TRUE;
      li_80 = li_68;
   }
   if (TimeCurrent() >= li_72 && TimeCurrent() <= li_76) {
      li_156 = TRUE;
      li_80 = li_76;
   }
   if (li_156) {
      li_32 = MathFloor((li_80 - TimeCurrent()) / 3600);
      li_36 = MathFloor((li_80 - TimeCurrent() - 3600 * li_32) / 60) + 1.0;
      l_dbl2str_40 = DoubleToStr(li_32, 0);
      if (li_36 < 10) ls_48 = "0" + DoubleToStr(li_36, 0);
      else ls_48 = DoubleToStr(li_36, 0);
      ObjectSetText(g_name_168, "COUNTDOWN: " + l_dbl2str_40 + ":" + ls_48, g_fontsize_156, gs_arial_160, CountdownColor);
   } else {
      ObjectSetText(g_name_168, "COUNTDOWN: -", g_fontsize_156, gs_arial_160, CountdownColor);
      gi_200 = 3;
   }
   l_spread_136 = MarketInfo(Symbol(), MODE_SPREAD);
   l_tickvalue_144 = MarketInfo(Symbol(), MODE_TICKVALUE);
   if (gi_200 == 1) {
      for (l_index_12 = 0; l_index_12 < Bars && g_ibuf_188[l_index_12] == EMPTY_VALUE; l_index_12++) {
      }
      if (g_ibuf_188[l_index_12] != EMPTY_VALUE) {
         gd_212 = g_ibuf_188[l_index_12];
         gd_220 = g_ibuf_192[l_index_12];
         ld_104 = gd_212 + 5.0 * Point;
         ld_112 = gd_220 + (gd_212 - gd_220) / 2.0 - 5.0 * Point;
         ld_120 = gd_220 - 5.0 * Point;
         ObjectSetText("lmn1", "Entry: " + DoubleToStr(ld_104, Digits), g_fontsize_176, gs_arial_180, TextColor);
         ObjectSetText("lmn2", "Aggressive Stop Loss: " + DoubleToStr(ld_112, Digits), g_fontsize_176, gs_arial_180, TextColor);
         ObjectSetText("lmn3", "Conservative Stop Loss: " + DoubleToStr(ld_120, Digits), g_fontsize_176, gs_arial_180, TextColor);
         ld_128 = gd_220 + ld_0;
         ObjectSetText("lmn4", "Aggressive Target: " + DoubleToStr(ld_128, Digits), g_fontsize_176, gs_arial_180, TextColor);
         l_dbl2str_56 = DoubleToStr(ld_128, Digits);
         ld_16 = StrToDouble(StringSubstr(l_dbl2str_56, StringLen(l_dbl2str_56) - 2, 2));
         if (ld_16 >= 0.0 && ld_16 <= 15.0) ld_16 = StrToDouble(StringSubstr(l_dbl2str_56, 0, StringLen(l_dbl2str_56) - 2) + "00") - 5.0 * Point;
         else {
            if (ld_16 >= 50.0 && ld_16 <= 65.0) ld_16 = StrToDouble(StringSubstr(l_dbl2str_56, 0, StringLen(l_dbl2str_56) - 2) + "50") - 5.0 * Point;
            else ld_16 = ld_128;
         }
         ObjectSetText("lmn5", "Conservative Target: " + DoubleToStr(ld_16, Digits), g_fontsize_176, gs_arial_180, TextColor);
         ld_16 = (ld_104 - ld_112) / Point + l_spread_136;
         ld_16 *= l_tickvalue_144;
         ld_16 = RiskRatio * AccountSize / ld_16;
         ld_24 = (ld_104 - ld_120) / Point + l_spread_136;
         ld_24 *= l_tickvalue_144;
         ld_24 = RiskRatio * AccountSize / ld_24;
         ObjectSetText("lmn6", "Aggressive Lot Size Multiplier: " + DoubleToStr(ld_16, 2), g_fontsize_176, gs_arial_180, TextColor);
         ObjectSetText("lmn7", "Conservative Lot Size Multiplier: " + DoubleToStr(ld_24, 2), g_fontsize_176, gs_arial_180, TextColor);
      }
   } else {
      if (gi_200 == 2) {
         for (l_index_12 = 0; l_index_12 < Bars && g_ibuf_188[l_index_12] == EMPTY_VALUE; l_index_12++) {
         }
         if (g_ibuf_188[l_index_12] != EMPTY_VALUE) {
            gd_212 = g_ibuf_188[l_index_12];
            gd_220 = g_ibuf_192[l_index_12];
            ld_104 = gd_220 - 5.0 * Point;
            ld_112 = gd_220 + (gd_212 - gd_220) / 2.0 + 5.0 * Point;
            ld_120 = gd_212 + 5.0 * Point;
            ObjectSetText("lmn1", "Entry: " + DoubleToStr(ld_104, Digits), g_fontsize_176, gs_arial_180, TextColor);
            ObjectSetText("lmn2", "Aggressive Stop Loss: " + DoubleToStr(ld_112, Digits), g_fontsize_176, gs_arial_180, TextColor);
            ObjectSetText("lmn3", "Conservative Stop Loss: " + DoubleToStr(ld_120, Digits), g_fontsize_176, gs_arial_180, TextColor);
            ld_128 = gd_212 - ld_0;
            ObjectSetText("lmn4", "Aggressive Target: " + DoubleToStr(ld_128, Digits), g_fontsize_176, gs_arial_180, TextColor);
            l_dbl2str_56 = DoubleToStr(ld_128, Digits);
            ld_16 = StrToDouble(StringSubstr(l_dbl2str_56, StringLen(l_dbl2str_56) - 2, 2));
            if (ld_16 >= 85.0 && ld_16 <= 0.0) ld_16 = StrToDouble(StringSubstr(l_dbl2str_56, 0, StringLen(l_dbl2str_56) - 2) + "00") + 5.0 * Point;
            else {
               if (ld_16 >= 35.0 && ld_16 <= 50.0) ld_16 = StrToDouble(StringSubstr(l_dbl2str_56, 0, StringLen(l_dbl2str_56) - 2) + "50") + 5.0 * Point;
               else ld_16 = ld_128;
            }
            ObjectSetText("lmn5", "Conservative Target: " + DoubleToStr(ld_16, Digits), g_fontsize_176, gs_arial_180, TextColor);
            ld_16 = (ld_112 - ld_104) / Point + l_spread_136;
            ld_16 *= l_tickvalue_144;
            ld_16 = RiskRatio * AccountSize / ld_16;
            ld_24 = (ld_120 - ld_104) / Point + l_spread_136;
            ld_24 *= l_tickvalue_144;
            ld_24 = RiskRatio * AccountSize / ld_24;
            ObjectSetText("lmn6", "Aggressive Lot Size Multiplier: " + DoubleToStr(ld_16, 2), g_fontsize_176, gs_arial_180, TextColor);
            ObjectSetText("lmn7", "Conservative Lot Size Multiplier: " + DoubleToStr(ld_24, 2), g_fontsize_176, gs_arial_180, TextColor);
         }
      } else {
         ObjectSetText("lmn1", "", g_fontsize_176, gs_arial_180, TextColor);
         ObjectSetText("lmn2", "", g_fontsize_176, gs_arial_180, TextColor);
         ObjectSetText("lmn3", "", g_fontsize_176, gs_arial_180, TextColor);
         ObjectSetText("lmn4", "", g_fontsize_176, gs_arial_180, TextColor);
         ObjectSetText("lmn5", "", g_fontsize_176, gs_arial_180, TextColor);
         ObjectSetText("lmn6", "", g_fontsize_176, gs_arial_180, TextColor);
         ObjectSetText("lmn7", "", g_fontsize_176, gs_arial_180, TextColor);
      }
   }
   if (gi_200 == 1) ObjectSetText(gs_mainind1_148, "LONG TRADE", g_fontsize_136, gs_arial_140, g_color_124);
   else {
      if (gi_200 == 2) ObjectSetText(gs_mainind1_148, "SHORT TRADE", g_fontsize_136, gs_arial_140, g_color_128);
      else {
         if (gi_200 == 3) ObjectSetText(gs_mainind1_148, "NO TRADE", g_fontsize_136, gs_arial_140, g_color_132);
         else ObjectSetText(gs_mainind1_148, "", g_fontsize_136, gs_arial_140, g_color_124);
      }
   }
   return (0);
}