

#property indicator_chart_window

extern bool ChartAlerts = FALSE;
extern bool EmailAlerts = FALSE;
extern string EmailSubject = "MT4 chart setup: ";
extern int LookbackBars = 500;
extern double VerticalSpacing = 1.5;
extern int ShowMinLevelArrows = 1;
extern int ShowMaxLevelArrows = 5;
extern int StartHour = 0;
extern int EndHour = 23;
extern double MinBarHeight = 5.0;
extern double MaxBarHeight = 999.0;
extern bool ShowBullishSetups = TRUE;
extern bool ShowBearishSetups = TRUE;
extern bool ShowFollowSameColor = TRUE;
extern bool ShowFollowOppColor = TRUE;
extern bool ___OUTSIDE_BARS___ = TRUE;
extern color OutsideBarColor = White;
extern double OB_CloseWithinXpct = 40.0;
extern double OB_MinBodyPct = 0.0;
extern double OB_MaxBodyPct = 100.0;
extern bool ___ENGULF_BODIES___ = TRUE;
extern color EngulfBodyColor = Yellow;
extern double EB_CloseWithinXpct = 40.0;
extern double EB_MinBodyPct = 0.0;
extern double EB_MaxBodyPct = 100.0;
extern int EB_SizeRatioPct = 100;
extern double EB_Tolerance = 2.0;
extern bool EB_MustBreak = FALSE;
extern bool ___PINBARS___ = TRUE;
extern color PinBarColor = CornflowerBlue;
extern double PB_CloseWithinXpct = 50.0;
extern double PB_MinOuterWickPct = 50.0;
extern int PB_ClearBars = 5;
extern int PB_ClearPips = 10;
extern bool PB_CheckColor = FALSE;
extern bool ___HANGING_MEN___ = TRUE;
extern color HangManColor = OrangeRed;
extern double HM_CloseWithinXpct = 50.0;
extern double HM_MinInnerWickPct = 50.0;
extern int HM_MinTrendBars = 5;
extern double HM_Tolerance = 2.0;
extern bool ___RAIL_TRACKS___ = TRUE;
extern color RailTrackColor = BlueViolet;
extern double RT_MinBodyPct = 60.0;
extern double RT_MaxBodyDiffPct = 20.0;
extern double RT_Tolerance = 2.0;
extern bool ___KONG_BARS___ = TRUE;
extern color KongBarColor = ForestGreen;
extern double KB_CloseWithinXpct = 40.0;
extern double KB_MinBodyPct = 0.0;
extern double KB_MaxBodyPct = 100.0;
extern int KB_SizeRatioPct = 125;
extern int KB_LookbackBars = 25;
extern bool KB_UseAveHeights = TRUE;
extern bool KB_CompareBody = TRUE;
extern bool ___DOJIS___ = TRUE;
extern color DojiColor = DarkGoldenrod;
extern double DojiMaxBodyPct = 5.0;
extern double DojiCentralPct = 100.0;
extern bool ___INSIDE_BARS___ = TRUE;
extern color InsideBarColor = HotPink;
extern bool ___DBL_TOPS_BOTS___ = TRUE;
extern color DoubleTBColor = Gray;
extern double DoubleTBTolerance = 2.0;
extern int DoubleTBLookback = 5;
extern int DoubleTBBarsGap = 0;
extern bool DoubleTBWiderClose = FALSE;
string g_symbol_444;
int g_digits_452;
int gi_unused_456;
int g_timeframe_460;
double gd_464;
datetime g_time_472;

int init() {
   CheckPresets();
   g_symbol_444 = Symbol();
   g_timeframe_460 = Period();
   gd_464 = MarketInfo(g_symbol_444, MODE_POINT);
   g_digits_452 = MarketInfo(g_symbol_444, MODE_DIGITS);
   gi_unused_456 = MarketInfo(g_symbol_444, MODE_SPREAD);
   if (g_digits_452 == 3 || g_digits_452 == 5) gd_464 = 10.0 * gd_464;
   del_obj();
   plot_obj(0);
   g_time_472 = -9999;
   return (0);
}

int deinit() {
   del_obj();
   return (0);
}

int start() {
   if (g_time_472 != Time[0]) {
      del_obj();
      plot_obj(1);
   }
   g_time_472 = Time[0];
   return (0);
}

void del_obj() {
   string name_4;
   int li_0 = 0;
   while (li_0 < ObjectsTotal()) {
      name_4 = ObjectName(li_0);
      if (StringSubstr(name_4, 0, 4) == "obid") ObjectDelete(name_4);
      else li_0++;
   }
}

void plot_obj(int ai_0) {
   int count_4;
   int hour_12;
   double ld_16;
   double ld_24;
   double ld_32;
   double ld_40;
   double ld_48;
   double ld_56;
   bool li_64;
   bool li_68;
   bool li_72;
   double ld_76;
   double ld_84;
   double ld_92;
   bool li_104;
   bool li_108;
   double ld_112;
   double ld_120;
   double ld_128;
   bool li_136;
   bool li_140;
   bool li_144;
   bool li_148;
   bool li_152;
   bool li_156;
   bool li_160;
   double ld_164;
   double ld_172;
   double ld_180;
   bool li_188;
   bool li_192;
   int li_196;
   string ls_200;
   string ls_212;
   double price_220;
   double price_228;
   int width_236;
   int width_240;
   for (int li_8 = 1; li_8 <= MathMin(Bars - 1, LookbackBars); li_8++) {
      hour_12 = TimeHour(Time[li_8]);
      if (hour_12 < StartHour || hour_12 > EndHour) continue;
      if (High[li_8] - Low[li_8] < MinBarHeight * gd_464 || High[li_8] - Low[li_8] > MaxBarHeight * gd_464) continue;
      if (!ShowFollowSameColor && (Close[li_8] - Open[li_8]) * (Close[li_8 + 1] - (Open[li_8 + 1])) > 0.0) continue;
      if (!ShowFollowOppColor && (Close[li_8] - Open[li_8]) * (Close[li_8 + 1] - (Open[li_8 + 1])) < 0.0) continue;
      ld_16 = DivZero(MathAbs(Close[li_8] - Open[li_8]), High[li_8] - Low[li_8]);
      ld_24 = 100.0 * DivZero(Close[li_8] - Low[li_8], High[li_8] - Low[li_8]);
      ld_32 = MathMax(Open[li_8], Close[li_8]);
      ld_40 = MathMin(Open[li_8], Close[li_8]);
      ld_48 = MathMax(Open[li_8 + 1], Close[li_8 + 1]);
      ld_56 = MathMin(Open[li_8 + 1], Close[li_8 + 1]);
      li_64 = TRUE;
      if (!___OUTSIDE_BARS___ || High[li_8] < High[li_8 + 1] || Low[li_8] > Low[li_8 + 1]) li_64 = FALSE;
      if (ld_16 < OB_MinBodyPct / 100.0) li_64 = FALSE;
      if (ld_16 > OB_MaxBodyPct / 100.0) li_64 = FALSE;
      if (Close[li_8] > Open[li_8] && 100 - OB_CloseWithinXpct > ld_24) li_64 = FALSE;
      if (Close[li_8] < Open[li_8] && ld_24 > OB_CloseWithinXpct) li_64 = FALSE;
      li_68 = TRUE;
      if (EB_Tolerance < 0.0 || (!___ENGULF_BODIES___)) li_68 = FALSE;
      else {
         if (ld_32 - ld_40 < (ld_48 - ld_56) * EB_SizeRatioPct / 100.0) li_68 = FALSE;
         if (ld_32 < ld_48 - EB_Tolerance * gd_464 || ld_40 > ld_56 + EB_Tolerance * gd_464) li_68 = FALSE;
         if (Close[li_8] > Open[li_8] && High[li_8] < High[li_8 + 1] && EB_MustBreak) li_68 = FALSE;
         if (Close[li_8] < Open[li_8] && Low[li_8] > Low[li_8 + 1] && EB_MustBreak) li_68 = FALSE;
         if (ld_16 < EB_MinBodyPct / 100.0) li_68 = FALSE;
         if (ld_16 > EB_MaxBodyPct / 100.0) li_68 = FALSE;
         if (Close[li_8] > Open[li_8] && 100 - EB_CloseWithinXpct > ld_24) li_68 = FALSE;
         if (Close[li_8] < Open[li_8] && ld_24 > EB_CloseWithinXpct) li_68 = FALSE;
      }
      li_72 = TRUE;
      if (!___KONG_BARS___) li_72 = FALSE;
      else {
         if (ld_16 < KB_MinBodyPct / 100.0) li_72 = FALSE;
         if (ld_16 > KB_MaxBodyPct / 100.0) li_72 = FALSE;
         if (Close[li_8] > Open[li_8] && 100 - KB_CloseWithinXpct > ld_24) li_72 = FALSE;
         if (Close[li_8] < Open[li_8] && ld_24 > KB_CloseWithinXpct) li_72 = FALSE;
         ld_76 = High[li_8] - Low[li_8];
         if (KB_CompareBody) ld_76 = MathAbs(Close[li_8] - Open[li_8]);
         ld_84 = 0;
         ld_92 = 0;
         for (int li_100 = 1; li_100 <= KB_LookbackBars; li_100++) {
            if (KB_CompareBody) {
               ld_84 = MathMax(ld_84, MathAbs(Close[li_8 + li_100] - (Open[li_8 + li_100])));
               ld_92 += MathAbs(Close[li_8 + li_100] - (Open[li_8 + li_100])) / KB_LookbackBars;
            } else {
               ld_84 = MathMax(ld_84, High[li_8 + li_100] - (Low[li_8 + li_100]));
               ld_92 += (High[li_8 + li_100] - (Low[li_8 + li_100])) / KB_LookbackBars;
            }
         }
         if (!KB_UseAveHeights) ld_92 = ld_84;
         if (ld_76 < ld_92 * KB_SizeRatioPct / 100.0) li_72 = FALSE;
      }
      li_104 = TRUE;
      if (!___INSIDE_BARS___ || High[li_8] > High[li_8 + 1] || Low[li_8] < Low[li_8 + 1]) li_104 = FALSE;
      li_108 = TRUE;
      if (!___DOJIS___) li_108 = FALSE;
      if (ld_16 > DojiMaxBodyPct / 100.0) li_108 = FALSE;
      ld_112 = (High[li_8] + Low[li_8]) / 2.0;
      ld_120 = (Open[li_8] + Close[li_8]) / 2.0;
      ld_128 = (High[li_8] - Low[li_8]) * DojiCentralPct / 200.0;
      if (ld_120 > ld_112 + ld_128 || ld_120 < ld_112 - ld_128) li_108 = FALSE;
      li_136 = TRUE;
      if (!___PINBARS___) li_136 = FALSE;
      if (100 - PB_CloseWithinXpct < ld_24) li_140 = TRUE;
      else li_140 = FALSE;
      if (ld_24 < PB_CloseWithinXpct) li_144 = TRUE;
      else li_144 = FALSE;
      if ((!li_140) && !li_144) li_136 = FALSE;
      if (li_140) {
         if (PB_CheckColor && Close[li_8] < Open[li_8]) li_136 = FALSE;
         for (li_100 = 1; li_100 <= PB_ClearBars; li_100++)
            if (Low[li_8] > Low[li_8 + li_100] - PB_ClearPips * gd_464) li_136 = FALSE;
         if (MathMin(Open[li_8], Close[li_8]) - Low[li_8] < (High[li_8] - Low[li_8]) * PB_MinOuterWickPct / 100.0) li_136 = FALSE;
      }
      if (li_144) {
         if (PB_CheckColor && Close[li_8] > Open[li_8]) li_136 = FALSE;
         for (li_100 = 1; li_100 <= PB_ClearBars; li_100++)
            if (High[li_8] < High[li_8 + li_100] + PB_ClearPips * gd_464) li_136 = FALSE;
         if (High[li_8] - MathMax(Open[li_8], Close[li_8]) < (High[li_8] - Low[li_8]) * PB_MinOuterWickPct / 100.0) li_136 = FALSE;
      }
      li_148 = TRUE;
      if (!___HANGING_MEN___) li_148 = FALSE;
      if (100 - HM_CloseWithinXpct < ld_24) li_152 = TRUE;
      else li_152 = FALSE;
      if (ld_24 < HM_CloseWithinXpct) li_156 = TRUE;
      else li_156 = FALSE;
      if ((!li_156) && !li_152) li_148 = FALSE;
      if (li_156) {
         for (li_100 = 1; li_100 <= HM_MinTrendBars; li_100++)
            if (Low[li_8] > Low[li_8 + li_100] + HM_Tolerance * gd_464) li_148 = FALSE;
         if (High[li_8] - MathMax(Open[li_8], Close[li_8]) < (High[li_8] - Low[li_8]) * HM_MinInnerWickPct / 100.0) li_148 = FALSE;
      }
      if (li_152) {
         for (li_100 = 1; li_100 <= HM_MinTrendBars; li_100++)
            if (High[li_8] < High[li_8 + li_100] - HM_Tolerance * gd_464) li_148 = FALSE;
         if (MathMin(Open[li_8], Close[li_8]) - Low[li_8] < (High[li_8] - Low[li_8]) * HM_MinInnerWickPct / 100.0) li_148 = FALSE;
      }
      li_160 = TRUE;
      if (!___RAIL_TRACKS___) li_160 = FALSE;
      if (ld_16 < RT_MinBodyPct / 100.0) li_160 = FALSE;
      if (ld_16 < RT_MinBodyPct / 100.0) li_160 = FALSE;
      if ((Close[li_8] - Open[li_8]) * (Close[li_8 + 1] - (Open[li_8 + 1])) > 0.0) li_160 = FALSE;
      ld_164 = MathAbs(Close[li_8 + 1] - (Open[li_8 + 1]));
      ld_172 = MathAbs(Close[li_8] - Open[li_8]);
      ld_180 = MathAbs(ld_172 - ld_164);
      if (ld_180 > ld_164 * RT_MaxBodyDiffPct / 100.0) li_160 = FALSE;
      if (MathAbs(Close[li_8 + 1] - Open[li_8]) > RT_Tolerance * gd_464) li_160 = FALSE;
      if (li_64) {
         li_68 = FALSE;
         li_136 = FALSE;
         li_148 = FALSE;
         li_160 = FALSE;
         li_72 = FALSE;
         li_108 = FALSE;
         li_104 = FALSE;
      }
      if (li_68) {
         li_136 = FALSE;
         li_148 = FALSE;
         li_160 = FALSE;
         li_72 = FALSE;
         li_108 = FALSE;
         li_104 = FALSE;
      }
      if (li_136) {
         li_148 = FALSE;
         li_160 = FALSE;
         li_72 = FALSE;
         li_108 = FALSE;
         li_104 = FALSE;
      }
      if (li_148) {
         li_160 = FALSE;
         li_72 = FALSE;
         li_108 = FALSE;
         li_104 = FALSE;
      }
      if (li_160) {
         li_72 = FALSE;
         li_108 = FALSE;
         li_104 = FALSE;
      }
      if (li_72) {
         li_108 = FALSE;
         li_104 = FALSE;
      }
      if (li_108) li_104 = FALSE;
      li_188 = FALSE;
      li_192 = FALSE;
      if (___DBL_TOPS_BOTS___) {
         for (li_100 = 1; li_100 <= DoubleTBLookback; li_100++) {
            if (High[li_8 + li_100] > High[li_8] + DoubleTBTolerance * gd_464) break;
            if (MathAbs(High[li_8 + li_100] - High[li_8]) <= DoubleTBTolerance * gd_464 && li_100 > DoubleTBBarsGap)
               if (!DoubleTBWiderClose || Close[li_8] < Low[li_8 + li_100]) li_188 = TRUE;
         }
         for (li_100 = 1; li_100 <= DoubleTBLookback; li_100++) {
            if (Low[li_8 + li_100] < Low[li_8] - DoubleTBTolerance * gd_464) break;
            if (MathAbs(Low[li_8 + li_100] - Low[li_8]) <= DoubleTBTolerance * gd_464 && li_100 > DoubleTBBarsGap)
               if (!DoubleTBWiderClose || Close[li_8] > High[li_8 + li_100]) li_192 = TRUE;
         }
      }
      if ((!li_64) && !li_68 && (!li_104) && (!li_136) && (!li_148) && (!li_160) && (!li_108) && (!li_72) && (!li_188) && !li_192) continue;
      li_196 = 0;
      if (Close[li_8] > Open[li_8]) li_196 = 1;
      if (Close[li_8] <= Open[li_8]) li_196 = -1;
      if (li_136) {
         if (li_140) li_196 = 1;
         if (li_144) li_196 = -1;
      }
      if (li_148) {
         if (li_156) li_196 = 1;
         if (li_152) li_196 = -1;
      }
      ls_200 = g_symbol_444 + ",";
      switch (g_timeframe_460) {
      case PERIOD_M1:
         ls_200 = ls_200 + "M1 : ";
         break;
      case PERIOD_M5:
         ls_200 = ls_200 + "M5 : ";
         break;
      case PERIOD_M15:
         ls_200 = ls_200 + "M15 : ";
         break;
      case PERIOD_M30:
         ls_200 = ls_200 + "M30 : ";
         break;
      case PERIOD_H1:
         ls_200 = ls_200 + "H1 : ";
         break;
      case PERIOD_H4:
         ls_200 = ls_200 + "H4 : ";
         break;
      case PERIOD_D1:
         ls_200 = ls_200 + "D1 : ";
         break;
      case PERIOD_W1:
         ls_200 = ls_200 + "W1 : ";
         break;
      case PERIOD_MN1:
         ls_200 = ls_200 + "MN : ";
         break;
      default:
         ls_200 = ls_200 + "?? : ";
      }
      ls_212 = " ";
      price_220 = iHigh(g_symbol_444, g_timeframe_460, li_8) + 10.0 * gd_464 + 10.0 * VerticalSpacing * gd_464;
      price_228 = iLow(g_symbol_444, g_timeframe_460, li_8) - 5.0 * VerticalSpacing * gd_464;
      width_236 = 0;
      width_240 = 0;
      if (li_64 || li_68 || li_104 || li_136 || li_148 || li_160 || li_108 || li_72) {
         if (li_196 == 1 && ShowBullishSetups) {
            count_4 = 0;
            if (High[li_8 + 2] > High[li_8 + 1]) count_4 += 2;
            if (High[li_8 + 3] > High[li_8 + 2]) count_4++;
            if (High[li_8 + 4] >= High[li_8 + 3]) count_4++;
            if (High[li_8 + 5] >= High[li_8 + 4]) count_4++;
            if (High[li_8 + 10] > High[li_8 + 1]) count_4++;
            if (High[li_8 + 15] > High[li_8 + 1]) count_4++;
            width_236 = MathMin(MathMax(1, count_4 - 1), 5);
            if (width_236 >= ShowMinLevelArrows && width_236 <= ShowMaxLevelArrows) {
               ObjectCreate("obid" + li_8, OBJ_ARROW, 0, iTime(g_symbol_444, g_timeframe_460, li_8), price_228);
               ObjectSet("obid" + li_8, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
               ObjectSet("obid" + li_8, OBJPROP_WIDTH, width_236);
            }
         }
         if (li_196 == -1 && ShowBearishSetups) {
            count_4 = 0;
            if (Low[li_8 + 2] < Low[li_8 + 1]) count_4 += 2;
            if (Low[li_8 + 3] < Low[li_8 + 2]) count_4++;
            if (Low[li_8 + 4] <= Low[li_8 + 3]) count_4++;
            if (Low[li_8 + 5] <= Low[li_8 + 4]) count_4++;
            if (Low[li_8 + 10] < Low[li_8 + 1]) count_4++;
            if (Low[li_8 + 15] < Low[li_8 + 1]) count_4++;
            width_240 = MathMin(MathMax(1, count_4 - 1), 5);
            if (width_240 >= ShowMinLevelArrows && width_240 <= ShowMaxLevelArrows) {
               ObjectCreate("obid" + li_8, OBJ_ARROW, 0, iTime(g_symbol_444, g_timeframe_460, li_8), price_220);
               ObjectSet("obid" + li_8, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
               ObjectSet("obid" + li_8, OBJPROP_WIDTH, width_240);
            }
         }
         if (li_64) {
            ObjectSet("obid" + li_8, OBJPROP_COLOR, OutsideBarColor);
            ls_212 = "Outside Bar";
         }
         if (li_68) {
            ObjectSet("obid" + li_8, OBJPROP_COLOR, EngulfBodyColor);
            ls_212 = "Engulfing Body";
         }
         if (li_136) {
            ObjectSet("obid" + li_8, OBJPROP_COLOR, PinBarColor);
            ls_212 = "Pinbar";
         }
         if (li_148) {
            ObjectSet("obid" + li_8, OBJPROP_COLOR, HangManColor);
            ls_212 = "Hanging Man";
         }
         if (li_160) {
            ObjectSet("obid" + li_8, OBJPROP_COLOR, RailTrackColor);
            ls_212 = "Railroad Track";
         }
         if (li_72) {
            ObjectSet("obid" + li_8, OBJPROP_COLOR, KongBarColor);
            ls_212 = "Kong Bar";
         }
         if (li_108) {
            ObjectSet("obid" + li_8, OBJPROP_COLOR, DojiColor);
            ls_212 = "Doji";
         }
         if (li_104) {
            ObjectSet("obid" + li_8, OBJPROP_COLOR, InsideBarColor);
            ls_212 = "Inside Bar";
         }
      }
      if (li_188 && ShowBearishSetups) {
         ObjectCreate("obidt" + li_8, OBJ_ARROW, 0, iTime(g_symbol_444, g_timeframe_460, li_8), price_220 + 3.0 * VerticalSpacing * width_240 * gd_464);
         ObjectSet("obidt" + li_8, OBJPROP_ARROWCODE, 159);
         ObjectSet("obidt" + li_8, OBJPROP_COLOR, DoubleTBColor);
         ObjectSet("obidt" + li_8, OBJPROP_WIDTH, 3);
         if (ls_212 == " ") ls_212 = "Double Top";
      }
      if (li_192 && ShowBullishSetups) {
         ObjectCreate("obidb" + li_8, OBJ_ARROW, 0, iTime(g_symbol_444, g_timeframe_460, li_8), price_228 - 3.0 * VerticalSpacing * width_236 * gd_464);
         ObjectSet("obidb" + li_8, OBJPROP_ARROWCODE, 159);
         ObjectSet("obidb" + li_8, OBJPROP_COLOR, DoubleTBColor);
         ObjectSet("obidb" + li_8, OBJPROP_WIDTH, 3);
         if (ls_212 == " ") ls_212 = "Double Bottom";
      }
      if (ls_212 != " " && li_8 == 1 && ai_0) {
         ls_200 = ls_200 + ls_212;
         if (ChartAlerts) Alert(ls_200);
         if (EmailAlerts) SendMail(EmailSubject, ls_200);
      }
   }
}

double DivZero(double ad_0, double ad_8) {
   if (ad_8 == 0.0) return (0);
   return (ad_0 / ad_8);
}

int CheckPresets() {
   string ls_16;
   int li_24;
   string ls_28;
   int li_36;
   string ls_44;
   int li_52;
   string ls_56;
   int li_64;
   int li_68;
   int li_72;
   int li_76;
   string ls_80;
   string ls_88;
   bool li_0 = FALSE;
   string name_4 = "Presets---Candle Identifier.TXT";
   int file_12 = FileOpen(name_4, FILE_CSV|FILE_READ, ';');
   if (file_12 > 0) {
      while (!FileIsEnding(file_12)) {
         ls_16 = FileReadString(file_12);
         li_24 = StringFind(ls_16, "//", 0);
         if (li_24 == 0) ls_16 = "";
         else
            if (li_24 > 0) ls_16 = StringSubstr(ls_16, 0, li_24);
         ls_28 = "";
         li_36 = 0;
         for (int li_40 = 0; li_40 < StringLen(ls_16); li_40++) {
            ls_44 = StringSubstr(ls_16, li_40, 1);
            if (ls_44 == "\"") li_36 = 1 - li_36;
            else {
               if (li_36 == 1) ls_28 = ls_28 + ls_44;
               else
                  if (ls_44 != " " && ls_44 != "_") ls_28 = ls_28 + StringLower(ls_44);
            }
         }
         if (StringLen(ls_28) > 0) {
            li_52 = 0;
            if (StringFind(ls_28, "m1:", 0) >= 0) li_52 = 1;
            else {
               if (StringFind(ls_28, "m5:", 0) >= 0) li_52 = 5;
               else {
                  if (StringFind(ls_28, "m15:", 0) >= 0) li_52 = 15;
                  else {
                     if (StringFind(ls_28, "m30:", 0) >= 0) li_52 = 30;
                     else {
                        if (StringFind(ls_28, "h1:", 0) >= 0) li_52 = 60;
                        else {
                           if (StringFind(ls_28, "h4:", 0) >= 0) li_52 = 240;
                           else {
                              if (StringFind(ls_28, "d1:", 0) >= 0) li_52 = 1440;
                              else {
                                 if (StringFind(ls_28, "w1:", 0) >= 0) li_52 = 10080;
                                 else
                                    if (StringFind(ls_28, "mn:", 0) >= 0) li_52 = 43200;
                              }
                           }
                        }
                     }
                  }
               }
            }
            ls_56 = "";
            li_64 = StringFind(ls_28, ",", 0);
            li_68 = StringFind(ls_28, ":", 0);
            li_72 = StringFind(ls_28, "=", 0);
            li_76 = StringFind(ls_28, ";", 0);
            if (li_64 >= 0) ls_56 = StringSubstr(ls_28, 0, li_64);
            else
               if (li_68 >= 0) ls_56 = StringSubstr(ls_28, 0, li_68);
            if (li_64 < 0 && li_52 > 0) ls_56 = "";
            ls_80 = "";
            if (li_68 >= 0) ls_80 = StringSubstr(ls_28, li_68 + 1, li_72 - li_68 - 1);
            else ls_80 = StringSubstr(ls_28, 0, li_72);
            ls_88 = StringSubstr(ls_28, li_72 + 1, li_76 - li_72 + 1);
            if (ls_56 == "" || StringFind(StringLower(Symbol()), ls_56, 0) >= 0 && li_52 == 0 || li_52 == Period() && ls_88 != "*") {
               if (ls_80 == "usepresets") li_0 = StrToBool(ls_88);
               else {
                  if (ls_80 == "chartalerts") ChartAlerts = StrToBool(ls_88);
                  else {
                     if (ls_80 == "emailalerts") EmailAlerts = StrToBool(ls_88);
                     else {
                        if (ls_80 == "emailsubject") EmailSubject = ls_88;
                        else {
                           if (ls_80 == "lookbackbars") LookbackBars = StrToInteger(ls_88);
                           else {
                              if (ls_80 == "verticalspacing") VerticalSpacing = StrToDouble(ls_88);
                              else {
                                 if (ls_80 == "showminlevelarrows") ShowMinLevelArrows = StrToInteger(ls_88);
                                 else {
                                    if (ls_80 == "showmaxlevelarrows") ShowMaxLevelArrows = StrToInteger(ls_88);
                                    else {
                                       if (ls_80 == "starthour") StartHour = StrToInteger(ls_88);
                                       else {
                                          if (ls_80 == "endhour") EndHour = StrToInteger(ls_88);
                                          else {
                                             if (ls_80 == "minbarheight") MinBarHeight = StrToDouble(ls_88);
                                             else {
                                                if (ls_80 == "maxbarheight") MaxBarHeight = StrToDouble(ls_88);
                                                else {
                                                   if (ls_80 == "showbullishsetups") ShowBullishSetups = StrToBool(ls_88);
                                                   else {
                                                      if (ls_80 == "showbearishsetups") ShowBearishSetups = StrToBool(ls_88);
                                                      else {
                                                         if (ls_80 == "showfollowsamecolor") ShowFollowSameColor = StrToBool(ls_88);
                                                         else {
                                                            if (ls_80 == "showfollowoppcolor") ShowFollowOppColor = StrToBool(ls_88);
                                                            else {
                                                               if (ls_80 == "outsidebars") ___OUTSIDE_BARS___ = StrToBool(ls_88);
                                                               else {
                                                                  if (ls_80 == "outsidebarcolor") OutsideBarColor = StrToColor(ls_88);
                                                                  else {
                                                                     if (ls_80 == "obclosewithinxpct") OB_CloseWithinXpct = StrToDouble(ls_88);
                                                                     else {
                                                                        if (ls_80 == "obminbodypct") OB_MinBodyPct = StrToDouble(ls_88);
                                                                        else {
                                                                           if (ls_80 == "obmaxbodypct") OB_MaxBodyPct = StrToDouble(ls_88);
                                                                           else {
                                                                              if (ls_80 == "engulfbodies") ___ENGULF_BODIES___ = StrToBool(ls_88);
                                                                              else {
                                                                                 if (ls_80 == "engulfbodycolor") EngulfBodyColor = StrToColor(ls_88);
                                                                                 else {
                                                                                    if (ls_80 == "ebclosewithinxpct") EB_CloseWithinXpct = StrToDouble(ls_88);
                                                                                    else {
                                                                                       if (ls_80 == "ebminbodypct") EB_MinBodyPct = StrToDouble(ls_88);
                                                                                       else {
                                                                                          if (ls_80 == "ebmaxbodypct") EB_MaxBodyPct = StrToDouble(ls_88);
                                                                                          else {
                                                                                             if (ls_80 == "ebsizeratiopct") EB_SizeRatioPct = StrToInteger(ls_88);
                                                                                             else {
                                                                                                if (ls_80 == "ebtolerance") EB_Tolerance = StrToDouble(ls_88);
                                                                                                else {
                                                                                                   if (ls_80 == "ebmustbreak") EB_MustBreak = StrToBool(ls_88);
                                                                                                   else {
                                                                                                      if (ls_80 == "pinbars") ___PINBARS___ = StrToBool(ls_88);
                                                                                                      else {
                                                                                                         if (ls_80 == "pinbarcolor") PinBarColor = StrToColor(ls_88);
                                                                                                         else {
                                                                                                            if (ls_80 == "pbclosewithinxpct") PB_CloseWithinXpct = StrToDouble(ls_88);
                                                                                                            else {
                                                                                                               if (ls_80 == "pbminouterwickpct") PB_MinOuterWickPct = StrToDouble(ls_88);
                                                                                                               else {
                                                                                                                  if (ls_80 == "pbclearbars") PB_ClearBars = StrToInteger(ls_88);
                                                                                                                  else {
                                                                                                                     if (ls_80 == "pbclearpips") PB_ClearPips = StrToInteger(ls_88);
                                                                                                                     else {
                                                                                                                        if (ls_80 == "pbcheckcolor") PB_CheckColor = StrToBool(ls_88);
                                                                                                                        else {
                                                                                                                           if (ls_80 == "hangingmen") ___HANGING_MEN___ = StrToBool(ls_88);
                                                                                                                           else {
                                                                                                                              if (ls_80 == "hangmancolor") HangManColor = StrToColor(ls_88);
                                                                                                                              else {
                                                                                                                                 if (ls_80 == "hmclosewithinxpct") HM_CloseWithinXpct = StrToDouble(ls_88);
                                                                                                                                 else {
                                                                                                                                    if (ls_80 == "hmmininnerwickpct") HM_MinInnerWickPct = StrToDouble(ls_88);
                                                                                                                                    else {
                                                                                                                                       if (ls_80 == "hmmintrendbars") HM_MinTrendBars = StrToInteger(ls_88);
                                                                                                                                       else {
                                                                                                                                          if (ls_80 == "hmtolerance") HM_Tolerance = StrToDouble(ls_88);
                                                                                                                                          else {
                                                                                                                                             if (ls_80 == "railtracks") ___RAIL_TRACKS___ = StrToBool(ls_88);
                                                                                                                                             else {
                                                                                                                                                if (ls_80 == "railtrackcolor") RailTrackColor = StrToColor(ls_88);
                                                                                                                                                else {
                                                                                                                                                   if (ls_80 == "rtminbodypct") RT_MinBodyPct = StrToDouble(ls_88);
                                                                                                                                                   else {
                                                                                                                                                      if (ls_80 == "rtmaxbodydiffpct") RT_MaxBodyDiffPct = StrToDouble(ls_88);
                                                                                                                                                      else {
                                                                                                                                                         if (ls_80 == "rttolerance") RT_Tolerance = StrToDouble(ls_88);
                                                                                                                                                         else {
                                                                                                                                                            if (ls_80 == "kongbars") ___KONG_BARS___ = StrToBool(ls_88);
                                                                                                                                                            else {
                                                                                                                                                               if (ls_80 == "kongbarcolor") KongBarColor = StrToColor(ls_88);
                                                                                                                                                               else {
                                                                                                                                                                  if (ls_80 == "kbclosewithinxpct") KB_CloseWithinXpct = StrToDouble(ls_88);
                                                                                                                                                                  else {
                                                                                                                                                                     if (ls_80 == "kbminbodypct") KB_MinBodyPct = StrToDouble(ls_88);
                                                                                                                                                                     else {
                                                                                                                                                                        if (ls_80 == "kbmaxbodypct") KB_MaxBodyPct = StrToDouble(ls_88);
                                                                                                                                                                        else {
                                                                                                                                                                           if (ls_80 == "kbsizeratiopct") KB_SizeRatioPct = StrToInteger(ls_88);
                                                                                                                                                                           else {
                                                                                                                                                                              if (ls_80 == "kblookbackbars") KB_LookbackBars = StrToInteger(ls_88);
                                                                                                                                                                              else {
                                                                                                                                                                                 if (ls_80 == "kbuseaveheights") KB_UseAveHeights = StrToBool(ls_88);
                                                                                                                                                                                 else {
                                                                                                                                                                                    if (ls_80 == "kbomparebody") KB_CompareBody = StrToBool(ls_88);
                                                                                                                                                                                    else {
                                                                                                                                                                                       if (ls_80 == "dojis") ___DOJIS___ = StrToBool(ls_88);
                                                                                                                                                                                       else {
                                                                                                                                                                                          if (ls_80 == "dojicolor") DojiColor = StrToColor(ls_88);
                                                                                                                                                                                          else {
                                                                                                                                                                                             if (ls_80 == "dojimaxbodypct") DojiMaxBodyPct = StrToDouble(ls_88);
                                                                                                                                                                                             else {
                                                                                                                                                                                                if (ls_80 == "dojicentralpct") DojiCentralPct = StrToDouble(ls_88);
                                                                                                                                                                                                else {
                                                                                                                                                                                                   if (ls_80 == "insidebars") ___INSIDE_BARS___ = StrToBool(ls_88);
                                                                                                                                                                                                   else {
                                                                                                                                                                                                      if (ls_80 == "insidebarcolor") InsideBarColor = StrToColor(ls_88);
                                                                                                                                                                                                      else {
                                                                                                                                                                                                         if (ls_80 == "dbltopsbots") ___DBL_TOPS_BOTS___ = StrToBool(ls_88);
                                                                                                                                                                                                         else {
                                                                                                                                                                                                            if (ls_80 == "doubletbcolor") DoubleTBColor = StrToColor(ls_88);
                                                                                                                                                                                                            else {
                                                                                                                                                                                                               if (ls_80 == "doubletbtolerance") DoubleTBTolerance = StrToDouble(ls_88);
                                                                                                                                                                                                               else {
                                                                                                                                                                                                                  if (ls_80 == "doubletblookback") DoubleTBLookback = StrToInteger(ls_88);
                                                                                                                                                                                                                  else {
                                                                                                                                                                                                                     if (ls_80 == "doubletbbarsgap") DoubleTBBarsGap = StrToInteger(ls_88);
                                                                                                                                                                                                                     else
                                                                                                                                                                                                                        if (ls_80 == "doubletbwiderclose") DoubleTBWiderClose = StrToBool(ls_88);
                                                                                                                                                                                                                  }
                                                                                                                                                                                                               }
                                                                                                                                                                                                            }
                                                                                                                                                                                                         }
                                                                                                                                                                                                      }
                                                                                                                                                                                                   }
                                                                                                                                                                                                }
                                                                                                                                                                                             }
                                                                                                                                                                                          }
                                                                                                                                                                                       }
                                                                                                                                                                                    }
                                                                                                                                                                                 }
                                                                                                                                                                              }
                                                                                                                                                                           }
                                                                                                                                                                        }
                                                                                                                                                                     }
                                                                                                                                                                  }
                                                                                                                                                               }
                                                                                                                                                            }
                                                                                                                                                         }
                                                                                                                                                      }
                                                                                                                                                   }
                                                                                                                                                }
                                                                                                                                             }
                                                                                                                                          }
                                                                                                                                       }
                                                                                                                                    }
                                                                                                                                 }
                                                                                                                              }
                                                                                                                           }
                                                                                                                        }
                                                                                                                     }
                                                                                                                  }
                                                                                                               }
                                                                                                            }
                                                                                                         }
                                                                                                      }
                                                                                                   }
                                                                                                }
                                                                                             }
                                                                                          }
                                                                                       }
                                                                                    }
                                                                                 }
                                                                              }
                                                                           }
                                                                        }
                                                                     }
                                                                  }
                                                               }
                                                            }
                                                         }
                                                      }
                                                   }
                                                }
                                             }
                                          }
                                       }
                                    }
                                 }
                              }
                           }
                        }
                     }
                  }
               }
            }
            if (!(li_0)) break;
         }
         ls_28 = FileReadString(file_12);
      }
      FileClose(file_12);
   }
   return (0);
}

int StrToColor(string as_0) {
   int str2int_16;
   int str2int_20;
   int str2int_24;
   as_0 = StringLower(as_0);
   if (as_0 == "aliceblue") return (16775408);
   if (as_0 == "antiquewhite") return (14150650);
   if (as_0 == "aqua") return (16776960);
   if (as_0 == "aquamarine") return (13959039);
   if (as_0 == "beige") return (14480885);
   if (as_0 == "bisque") return (12903679);
   if (as_0 == "black") return (0);
   if (as_0 == "blanchedalmond") return (13495295);
   if (as_0 == "blue") return (16711680);
   if (as_0 == "blueviolet") return (14822282);
   if (as_0 == "brown") return (2763429);
   if (as_0 == "burlywood") return (8894686);
   if (as_0 == "cadetblue") return (10526303);
   if (as_0 == "chartreuse") return (65407);
   if (as_0 == "chocolate") return (1993170);
   if (as_0 == "coral") return (5275647);
   if (as_0 == "cornflowerblue") return (15570276);
   if (as_0 == "cornsilk") return (14481663);
   if (as_0 == "crimson") return (3937500);
   if (as_0 == "darkblue") return (9109504);
   if (as_0 == "darkgoldenrod") return (755384);
   if (as_0 == "darkgray") return (11119017);
   if (as_0 == "darkgreen") return (25600);
   if (as_0 == "darkkhaki") return (7059389);
   if (as_0 == "darkolivegreen") return (3107669);
   if (as_0 == "darkorange") return (36095);
   if (as_0 == "darkorchid") return (13382297);
   if (as_0 == "darksalmon") return (8034025);
   if (as_0 == "darkseagreen") return (9157775);
   if (as_0 == "darkslateblue") return (9125192);
   if (as_0 == "darkslategray") return (5197615);
   if (as_0 == "darkturquoise") return (13749760);
   if (as_0 == "darkviolet") return (13828244);
   if (as_0 == "deeppink") return (9639167);
   if (as_0 == "deepskyblue") return (16760576);
   if (as_0 == "dimgray") return (6908265);
   if (as_0 == "dodgerblue") return (16748574);
   if (as_0 == "firebrick") return (2237106);
   if (as_0 == "forestgreen") return (2263842);
   if (as_0 == "gainsboro") return (14474460);
   if (as_0 == "gold") return (55295);
   if (as_0 == "goldenrod") return (2139610);
   if (as_0 == "gray") return (8421504);
   if (as_0 == "green") return (32768);
   if (as_0 == "greenyellow") return (3145645);
   if (as_0 == "honeydew") return (15794160);
   if (as_0 == "hotpink") return (11823615);
   if (as_0 == "indianred") return (6053069);
   if (as_0 == "indigo") return (8519755);
   if (as_0 == "ivory") return (15794175);
   if (as_0 == "khaki") return (9234160);
   if (as_0 == "lavender") return (16443110);
   if (as_0 == "lavenderblush") return (16118015);
   if (as_0 == "lawngreen") return (64636);
   if (as_0 == "lemonchiffon") return (13499135);
   if (as_0 == "lightblue") return (15128749);
   if (as_0 == "lightcoral") return (8421616);
   if (as_0 == "lightcyan") return (16777184);
   if (as_0 == "lightgoldenrod") return (13826810);
   if (as_0 == "lightgray") return (13882323);
   if (as_0 == "lightgreen") return (9498256);
   if (as_0 == "lightpink") return (12695295);
   if (as_0 == "lightsalmon") return (8036607);
   if (as_0 == "lightseagreen") return (11186720);
   if (as_0 == "lightskyblue") return (16436871);
   if (as_0 == "lightslategray") return (10061943);
   if (as_0 == "lightsteelblue") return (14599344);
   if (as_0 == "lightyellow") return (14745599);
   if (as_0 == "lime") return (65280);
   if (as_0 == "limegreen") return (3329330);
   if (as_0 == "linen") return (15134970);
   if (as_0 == "magenta") return (16711935);
   if (as_0 == "maroon") return (128);
   if (as_0 == "mediumaquamarine") return (11193702);
   if (as_0 == "mediumblue") return (13434880);
   if (as_0 == "mediumorchid") return (13850042);
   if (as_0 == "mediumpurple") return (14381203);
   if (as_0 == "mediumseagreen") return (7451452);
   if (as_0 == "mediumslateblue") return (15624315);
   if (as_0 == "mediumspringgreen") return (10156544);
   if (as_0 == "mediumturquoise") return (13422920);
   if (as_0 == "mediumvioletred") return (8721863);
   if (as_0 == "midnightblue") return (7346457);
   if (as_0 == "mintcream") return (16449525);
   if (as_0 == "mistyrose") return (14804223);
   if (as_0 == "moccasin") return (11920639);
   if (as_0 == "navajowhite") return (11394815);
   if (as_0 == "navy") return (8388608);
   if (as_0 == "none") return (0);
   if (as_0 == "oldlace") return (15136253);
   if (as_0 == "olive") return (32896);
   if (as_0 == "olivedrab") return (2330219);
   if (as_0 == "orange") return (42495);
   if (as_0 == "orangered") return (17919);
   if (as_0 == "orchid") return (14053594);
   if (as_0 == "palegoldenrod") return (11200750);
   if (as_0 == "palegreen") return (10025880);
   if (as_0 == "paleturquoise") return (15658671);
   if (as_0 == "palevioletred") return (9662683);
   if (as_0 == "papayawhip") return (14020607);
   if (as_0 == "peachpuff") return (12180223);
   if (as_0 == "peru") return (4163021);
   if (as_0 == "pink") return (13353215);
   if (as_0 == "plum") return (14524637);
   if (as_0 == "powderblue") return (15130800);
   if (as_0 == "purple") return (8388736);
   if (as_0 == "red") return (255);
   if (as_0 == "rosybrown") return (9408444);
   if (as_0 == "royalblue") return (14772545);
   if (as_0 == "saddlebrown") return (1262987);
   if (as_0 == "salmon") return (7504122);
   if (as_0 == "sandybrown") return (6333684);
   if (as_0 == "seagreen") return (5737262);
   if (as_0 == "seashell") return (15660543);
   if (as_0 == "sienna") return (2970272);
   if (as_0 == "silver") return (12632256);
   if (as_0 == "skyblue") return (15453831);
   if (as_0 == "slateblue") return (13458026);
   if (as_0 == "slategray") return (9470064);
   if (as_0 == "snow") return (16448255);
   if (as_0 == "springgreen") return (8388352);
   if (as_0 == "steelblue") return (11829830);
   if (as_0 == "tan") return (9221330);
   if (as_0 == "teal") return (8421376);
   if (as_0 == "thistle") return (14204888);
   if (as_0 == "tomato") return (4678655);
   if (as_0 == "turquoise") return (13688896);
   if (as_0 == "violet") return (15631086);
   if (as_0 == "wheat") return (11788021);
   if (as_0 == "white") return (16777215);
   if (as_0 == "whitesmoke") return (16119285);
   if (as_0 == "yellow") return (65535);
   if (as_0 == "yellowgreen") return (3329434);
   int li_8 = StringFind(as_0, ",", 0);
   int li_12 = StringFind(as_0, ",", li_8 + 1);
   if (li_8 > 0 && li_12 > 0) {
      str2int_16 = StrToInteger(StringSubstr(as_0, 0, li_8));
      str2int_20 = StrToInteger(StringSubstr(as_0, li_8 + 1, li_12 - 1));
      str2int_24 = StrToInteger(StringSubstr(as_0, li_12 + 1, StringLen(as_0)));
      return (str2int_24 * 256 * 256 + str2int_20 * 256 + str2int_16);
   }
   return (0);
}

int StrToBool(string as_0) {
   as_0 = StringLower(StringSubstr(as_0, 0, 1));
   if (as_0 == "t" || as_0 == "y" || as_0 == "1") return (1);
   return (0);
}

string StringLower(string as_0) {
   int li_36;
   string ls_ret_8 = "";
   string ls_16 = "abcdefghijklmnopqrstuvwxyz";
   string ls_24 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   for (int li_32 = 0; li_32 < StringLen(as_0); li_32++) {
      li_36 = StringFind(ls_24, StringSubstr(as_0, li_32, 1), 0);
      if (li_36 >= 0) ls_ret_8 = ls_ret_8 + StringSubstr(ls_16, li_36, 1);
      else ls_ret_8 = ls_ret_8 + StringSubstr(as_0, li_32, 1);
   }
   return (ls_ret_8);
}