

#property indicator_chart_window
#property indicator_buffers 6
//#property indicator_color1 Lime
//#property indicator_color2 Red
//#property indicator_color3 Yellow
//#property indicator_color4 Yellow
#property indicator_color5 Lime
#property indicator_color6 Red
#property indicator_width5 4
#property indicator_width6 4

extern double Period1 = 0;
extern double Period2 = 15.0;
extern double Period3 = 65.0;
extern string Dev_Step_1 = "3,2";
extern string Dev_Step_2 = "8,5";
extern string Dev_Step_3 = "30,20";
extern int Symbol_1_Kod = 140;
extern int Symbol_2_Kod = 141;
extern int Symbol_3_Kod = 142;
extern string _____ = "";
extern bool Audible.Alerts = TRUE;
extern bool Box.Alerts = TRUE;
extern bool Email.Alerts = FALSE;
extern bool Alert.Lv1 = FALSE;
extern bool Alert.Lv2 = FALSE;
extern bool Alert.Lv3 = TRUE;
double g_ibuf_168[];
double g_ibuf_172[];
double g_ibuf_176[];
double g_ibuf_180[];
double g_ibuf_184[];
double g_ibuf_188[];
int gi_unused_192;
int gi_unused_196;
int gi_unused_200;
int gi_204;
int gi_208;
int gi_212;
int gi_216;
int gi_220;
int gi_224;
string gs_228;
string gs_236;
string gs_244;
int g_digits_252;
int g_timeframe_256;
bool gi_260;
bool gi_264;
bool gi_268;
int g_bars_272 = -1;
int gi_unused_276 = 65535;

int init() {
   int lia_8[];
   g_timeframe_256 = Period();
   gs_236 = TimeFrameToString(g_timeframe_256);
   gs_228 = Symbol();
   g_digits_252 = Digits;
   gs_244 = "tbb" + gs_228 + gs_236;
   if (Period1 > 0.0) gi_unused_192 = MathCeil(Period1 * Period());
   else gi_unused_192 = 0;
   if (Period2 > 0.0) gi_unused_196 = MathCeil(Period2 * Period());
   else gi_unused_196 = 0;
   if (Period3 > 0.0) gi_unused_200 = MathCeil(Period3 * Period());
   else gi_unused_200 = 0;
   if (Period1 > 0.0) {
      SetIndexStyle(0, DRAW_ARROW);
      SetIndexArrow(0, Symbol_1_Kod);
      SetIndexBuffer(0, g_ibuf_168);
      SetIndexEmptyValue(0, 0.0);
      SetIndexStyle(1, DRAW_ARROW);
      SetIndexArrow(1, Symbol_1_Kod);
      SetIndexBuffer(1, g_ibuf_172);
      SetIndexEmptyValue(1, 0.0);
   }
   if (Period2 > 0.0) {
      SetIndexStyle(2, DRAW_NONE);
      SetIndexArrow(2, Symbol_2_Kod);
      SetIndexBuffer(2, g_ibuf_176);
      SetIndexEmptyValue(2, 0.0);
      SetIndexStyle(3, DRAW_NONE);
      SetIndexArrow(3, Symbol_2_Kod);
      SetIndexBuffer(3, g_ibuf_180);
      SetIndexEmptyValue(3, 0.0);
   }
   if (Period3 > 0.0) {
      SetIndexStyle(4, DRAW_ARROW);
      SetIndexArrow(4, Symbol_3_Kod);
      SetIndexBuffer(4, g_ibuf_184);
      SetIndexEmptyValue(4, 0.0);
      SetIndexStyle(5, DRAW_ARROW);
      SetIndexArrow(5, Symbol_3_Kod);
      SetIndexBuffer(5, g_ibuf_188);
      SetIndexEmptyValue(5, 0.0);
   }
   int li_unused_0 = 0;
   int li_unused_4 = 0;
   int li_12 = 0;
   if (IntFromStr(Dev_Step_1, li_12, lia_8) == 1) {
      gi_208 = lia_8[1];
      gi_204 = lia_8[0];
   }
   if (IntFromStr(Dev_Step_2, li_12, lia_8) == 1) {
      gi_216 = lia_8[1];
      gi_212 = lia_8[0];
   }
   if (IntFromStr(Dev_Step_3, li_12, lia_8) == 1) {
      gi_224 = lia_8[1];
      gi_220 = lia_8[0];
   }
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   string ls_0;
   if (Bars != g_bars_272) {
      gi_260 = TRUE;
      gi_264 = TRUE;
      gi_268 = TRUE;
   }
   if (Period1 > 0.0) CountZZ(g_ibuf_168, g_ibuf_172, Period1, gi_204, gi_208);
   if (Period2 > 0.0) CountZZ(g_ibuf_176, g_ibuf_180, Period2, gi_212, gi_216);
   if (Period3 > 0.0) CountZZ(g_ibuf_184, g_ibuf_188, Period3, gi_220, gi_224);
   string ls_8 = gs_228 + "  " + gs_236 + " at " + DoubleToStr(Close[0], g_digits_252);
   if (gi_260 && Alert.Lv1) {
      if (g_ibuf_168[0] != 0.0) {
         gi_260 = FALSE;
         ls_0 = " ZZS: Level 1 Support;  ";
         if (Audible.Alerts) PlaySound("yeehaaa.wav");
         if (Box.Alerts) Alert(ls_0, ls_8);
         if (Email.Alerts) SendMail(ls_0, ls_8);
      }
      if (g_ibuf_172[0] != 0.0) {
         gi_260 = FALSE;
         ls_0 = " ZZS: Level 1 Resistant; ";
         if (Audible.Alerts) PlaySound("yeehaaa.wav");
         if (Box.Alerts) Alert(ls_0, ls_8);
         if (Email.Alerts) SendMail(ls_0, ls_8);
      }
   }
   if (gi_264 && Alert.Lv2) {
      if (g_ibuf_176[0] != 0.0) {
         gi_264 = FALSE;
         ls_0 = " ZZS: Level 2 Support;  ";
         if (Audible.Alerts) PlaySound("yeehaaa.wav");
         if (Box.Alerts) Alert(ls_0, ls_8);
         if (Email.Alerts) SendMail(ls_0, ls_8);
      }
      if (g_ibuf_180[0] != 0.0) {
         gi_264 = FALSE;
         ls_0 = " ZZS: Level 2 Resistant; ";
         if (Audible.Alerts) PlaySound("yeehaaa.wav");
         if (Box.Alerts) Alert(ls_0, ls_8);
         if (Email.Alerts) SendMail(ls_0, ls_8);
      }
   }
   if (gi_268 && Alert.Lv3) {
      if (g_ibuf_184[0] != 0.0) {
         gi_268 = FALSE;
         ls_0 = " ZZS: Level 3 Support--Standby Buy;  ";
         if (Audible.Alerts) PlaySound("yeehaaa.wav");
         if (Box.Alerts) Alert(ls_0, ls_8);
         if (Email.Alerts) SendMail(ls_0, ls_8);
      }
      if (g_ibuf_188[0] != 0.0) {
         gi_268 = FALSE;
         ls_0 = " ZZS: Level 3 Resistant--Standby Sell; ";
         if (Audible.Alerts) PlaySound("yeehaaa.wav");
         if (Box.Alerts) Alert(ls_0, ls_8);
         if (Email.Alerts) SendMail(ls_0, ls_8);
      }
   }
   g_bars_272 = Bars;
   return (0);
}

string TimeFrameToString(int ai_0) {
   string ls_ret_4;
   switch (ai_0) {
   case 1:
      ls_ret_4 = "M1";
      break;
   case 5:
      ls_ret_4 = "M5";
      break;
   case 15:
      ls_ret_4 = "M15";
      break;
   case 30:
      ls_ret_4 = "M30";
      break;
   case 60:
      ls_ret_4 = "H1";
      break;
   case 240:
      ls_ret_4 = "H4";
      break;
   case 1440:
      ls_ret_4 = "D1";
      break;
   case 10080:
      ls_ret_4 = "W1";
      break;
   case 43200:
      ls_ret_4 = "MN";
   }
   return (ls_ret_4);
}

int CountZZ(double &ada_0[], double &ada_4[], int ai_8, int ai_12, int ai_16) {
   double ld_36;
   double ld_44;
   double ld_52;
   double ld_60;
   double ld_68;
   double ld_76;
   for (int li_20 = Bars - ai_8; li_20 >= 0; li_20--) {
      ld_36 = Low[iLowest(NULL, 0, MODE_LOW, ai_8, li_20)];
      if (ld_36 == ld_76) ld_36 = 0.0;
      else {
         ld_76 = ld_36;
         if (Low[li_20] - ld_36 > ai_12 * Point) ld_36 = 0.0;
         else {
            for (int li_24 = 1; li_24 <= ai_16; li_24++) {
               ld_44 = ada_0[li_20 + li_24];
               if (ld_44 != 0.0 && ld_44 > ld_36) ada_0[li_20 + li_24] = 0.0;
            }
         }
      }
      ada_0[li_20] = ld_36;
      ld_36 = High[iHighest(NULL, 0, MODE_HIGH, ai_8, li_20)];
      if (ld_36 == ld_68) ld_36 = 0.0;
      else {
         ld_68 = ld_36;
         if (ld_36 - High[li_20] > ai_12 * Point) ld_36 = 0.0;
         else {
            for (li_24 = 1; li_24 <= ai_16; li_24++) {
               ld_44 = ada_4[li_20 + li_24];
               if (ld_44 != 0.0 && ld_44 < ld_36) ada_4[li_20 + li_24] = 0.0;
            }
         }
      }
      ada_4[li_20] = ld_36;
   }
   ld_68 = -1;
   int li_28 = -1;
   ld_76 = -1;
   int li_32 = -1;
   for (li_20 = Bars - ai_8; li_20 >= 0; li_20--) {
      ld_52 = ada_0[li_20];
      ld_60 = ada_4[li_20];
      if (ld_52 == 0.0 && ld_60 == 0.0) continue;
      if (ld_60 != 0.0) {
         if (ld_68 > 0.0) {
            if (ld_68 < ld_60) ada_4[li_28] = 0;
            else ada_4[li_20] = 0;
         }
         if (ld_68 < ld_60 || ld_68 < 0.0) {
            ld_68 = ld_60;
            li_28 = li_20;
         }
         ld_76 = -1;
      }
      if (ld_52 != 0.0) {
         if (ld_76 > 0.0) {
            if (ld_76 > ld_52) ada_0[li_32] = 0;
            else ada_0[li_20] = 0;
         }
         if (ld_52 < ld_76 || ld_76 < 0.0) {
            ld_76 = ld_52;
            li_32 = li_20;
         }
         ld_68 = -1;
      }
   }
   for (li_20 = Bars - 1; li_20 >= 0; li_20--) {
      if (li_20 >= Bars - ai_8) ada_0[li_20] = 0.0;
      else {
         ld_44 = ada_4[li_20];
         if (ld_44 != 0.0) ada_4[li_20] = ld_44;
      }
   }
   return (0);
}

int Str2Massive(string as_0, int &ai_8, int &aia_12[]) {
   int li_20;
   int l_str2int_16 = StrToInteger(as_0);
   if (l_str2int_16 > 0) {
      ai_8++;
      li_20 = ArrayResize(aia_12, ai_8);
      if (li_20 == 0) return (-1);
      aia_12[ai_8 - 1] = l_str2int_16;
      return (1);
   }
   return (0);
}

int IntFromStr(string as_0, int &ai_8, int aia_12[]) {
   string ls_28;
   if (StringLen(as_0) == 0) return (-1);
   string ls_16 = as_0;
   int li_24 = 0;
   ai_8 = 0;
   ArrayResize(aia_12, ai_8);
   while (StringLen(ls_16) > 0) {
      li_24 = StringFind(ls_16, ",");
      if (li_24 > 0) {
         ls_28 = StringSubstr(ls_16, 0, li_24);
         ls_16 = StringSubstr(ls_16, li_24 + 1, StringLen(ls_16));
      } else {
         if (StringLen(ls_16) > 0) {
            ls_28 = ls_16;
            ls_16 = "";
         }
      }
      if (Str2Massive(ls_28, ai_8, aia_12) == 0) return (-2);
   }
   return (1);
}