/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "asystem2000"
#property link      "asystem2000@yandex.ru"

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Lime
#property indicator_color2 Orange
#property indicator_color3 Yellow
#property indicator_color4 Yellow
#property indicator_color5 Aqua
#property indicator_color6 Red

extern double Period1 = 12.0;
extern double Period2 = 34.0;
extern double Period3 = 69.0;
extern string Dev_Step_1 = "5,3";
extern string Dev_Step_2 = "5,3";
extern string Dev_Step_3 = "5,3";
extern int Symbol_1_Kod = 159;
extern int Symbol_2_Kod = 159;
extern int Symbol_3_Kod = 82;
extern string _____ = "";
extern bool Box.Alerts = FALSE;
extern bool Email.Alerts = FALSE;
extern bool Sound.Alerts = TRUE;
extern bool Alert.Lv1 = TRUE;
extern bool Alert.Lv2 = TRUE;
extern bool Alert.Lv3 = TRUE;
string gs_168 = "stage one level high.wav";
string gs_176 = "stage one level low.wav";
string gs_184 = "stage two level high.wav";
string gs_192 = "stage two level low.wav";
string gs_200 = "stage three level high.wav";
string gs_208 = "stage three level low.wav";
double g_ibuf_216[];
double g_ibuf_220[];
double g_ibuf_224[];
double g_ibuf_228[];
double g_ibuf_232[];
double g_ibuf_236[];
int gi_unused_240;
int gi_unused_244;
int gi_unused_248;
int gi_252;
int gi_256;
int gi_260;
int gi_264;
int gi_268;
int gi_272;
string gs_276;
string gs_284;
string gs_292;
int g_digits_300;
int g_timeframe_304;
bool gi_308;
bool gi_312;
bool gi_316;
int g_bars_320 = -1;
int gi_unused_324 = 65535;

int init() {
   int lia_8[];
   g_timeframe_304 = Period();
   gs_284 = TimeFrameToString(g_timeframe_304);
   gs_276 = Symbol();
   g_digits_300 = Digits;
   gs_292 = "tbb" + gs_276 + gs_284;
   if (Period1 > 0.0) gi_unused_240 = MathCeil(Period1 * Period());
   else gi_unused_240 = 0;
   if (Period2 > 0.0) gi_unused_244 = MathCeil(Period2 * Period());
   else gi_unused_244 = 0;
   if (Period3 > 0.0) gi_unused_248 = MathCeil(Period3 * Period());
   else gi_unused_248 = 0;
   if (Period1 > 0.0) {
      SetIndexStyle(0, DRAW_ARROW);
      SetIndexArrow(0, Symbol_1_Kod);
      SetIndexBuffer(0, g_ibuf_216);
      SetIndexEmptyValue(0, 0.0);
      SetIndexStyle(1, DRAW_ARROW);
      SetIndexArrow(1, Symbol_1_Kod);
      SetIndexBuffer(1, g_ibuf_220);
      SetIndexEmptyValue(1, 0.0);
   }
   if (Period2 > 0.0) {
      SetIndexStyle(2, DRAW_ARROW);
      SetIndexArrow(2, Symbol_2_Kod);
      SetIndexBuffer(2, g_ibuf_224);
      SetIndexEmptyValue(2, 0.0);
      SetIndexStyle(3, DRAW_ARROW);
      SetIndexArrow(3, Symbol_2_Kod);
      SetIndexBuffer(3, g_ibuf_228);
      SetIndexEmptyValue(3, 0.0);
   }
   if (Period3 > 0.0) {
      SetIndexStyle(4, DRAW_ARROW);
      SetIndexArrow(4, Symbol_3_Kod);
      SetIndexBuffer(4, g_ibuf_232);
      SetIndexEmptyValue(4, 0.0);
      SetIndexStyle(5, DRAW_ARROW);
      SetIndexArrow(5, Symbol_3_Kod);
      SetIndexBuffer(5, g_ibuf_236);
      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_256 = lia_8[1];
      gi_252 = lia_8[0];
   }
   if (IntFromStr(Dev_Step_2, li_12, lia_8) == 1) {
      gi_264 = lia_8[1];
      gi_260 = lia_8[0];
   }
   if (IntFromStr(Dev_Step_3, li_12, lia_8) == 1) {
      gi_272 = lia_8[1];
      gi_268 = lia_8[0];
   }
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   string ls_0;
   if (Bars != g_bars_320) {
      gi_308 = TRUE;
      gi_312 = TRUE;
      gi_316 = TRUE;
   }
   if (Period1 > 0.0) CountZZ(g_ibuf_216, g_ibuf_220, Period1, gi_252, gi_256);
   if (Period2 > 0.0) CountZZ(g_ibuf_224, g_ibuf_228, Period2, gi_260, gi_264);
   if (Period3 > 0.0) CountZZ(g_ibuf_232, g_ibuf_236, Period3, gi_268, gi_272);
   string ls_8 = gs_276 + "  " + gs_284 + " at " + DoubleToStr(Close[0], g_digits_300);
   if (gi_308 && Alert.Lv1) {
      if (g_ibuf_216[0] != 0.0) {
         gi_308 = FALSE;
         ls_0 = " ZZS: Level 1 Low;  ";
         if (Box.Alerts) Alert(ls_0, ls_8);
         if (Email.Alerts) SendMail(ls_0, ls_8);
         if (Sound.Alerts) PlaySound(gs_176);
      }
      if (g_ibuf_220[0] != 0.0) {
         gi_308 = FALSE;
         ls_0 = " ZZS: Level 1 High; ";
         if (Box.Alerts) Alert(ls_0, ls_8);
         if (Email.Alerts) SendMail(ls_0, ls_8);
         if (Sound.Alerts) PlaySound(gs_168);
      }
   }
   if (gi_312 && Alert.Lv2) {
      if (g_ibuf_224[0] != 0.0) {
         gi_312 = FALSE;
         ls_0 = " ZZS: Level 2 Low;  ";
         if (Box.Alerts) Alert(ls_0, ls_8);
         if (Email.Alerts) SendMail(ls_0, ls_8);
         if (Sound.Alerts) PlaySound(gs_192);
      }
      if (g_ibuf_228[0] != 0.0) {
         gi_312 = FALSE;
         ls_0 = " ZZS: Level 2 High; ";
         if (Box.Alerts) Alert(ls_0, ls_8);
         if (Email.Alerts) SendMail(ls_0, ls_8);
         if (Sound.Alerts) PlaySound(gs_184);
      }
   }
   if (gi_316 && Alert.Lv3) {
      if (g_ibuf_232[0] != 0.0) {
         gi_316 = FALSE;
         ls_0 = " ZZS: Level 3 Low;  ";
         if (Box.Alerts) Alert(ls_0, ls_8);
         if (Email.Alerts) SendMail(ls_0, ls_8);
         if (Sound.Alerts) PlaySound(gs_208);
      }
      if (g_ibuf_236[0] != 0.0) {
         gi_316 = FALSE;
         ls_0 = " ZZS: Level 3 High; ";
         if (Box.Alerts) Alert(ls_0, ls_8);
         if (Email.Alerts) SendMail(ls_0, ls_8);
         if (Sound.Alerts) PlaySound(gs_200);
      }
   }
   g_bars_320 = 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);
}
