/*
   G e n e r a t e d  by ex4-to-mq4 decompiler FREEWARE 4.0.509.5
   Website:  hTtp://wwW.Me t a Q u o t ES .NeT
   E-mail :  S UpP O rT @ME T a QuoTES .NEt
*/

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Black
#property indicator_color2 Lime
#property indicator_color3 Red
#property indicator_color4 Yellow

extern int offSet = 18;
int G_bars_80 = 1500;
extern bool Add_vertical_line = TRUE;
extern color Vertical_line_color_long = Lime;
extern color Vertical_line_color_short = Red;
extern bool Alert_Sound = TRUE;
extern bool Alert_Email = FALSE;
extern int Number_of_bars_to_calculate = 5000;
double G_ibuf_108[];
double G_ibuf_112[];
double G_ibuf_116[];
double G_ibuf_120[];
int Gi_unused_124 = 0;
double G_time_128;
string Gs_136 = "";
string Gs_144 = "Essam.A";
int Gi_152 = 0;
string Gsa_156[];

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 0);
   SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 2);
   SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, 2);
   SetIndexStyle(3, DRAW_HISTOGRAM, STYLE_SOLID, 2);
   IndicatorDigits(Digits + 1);
   SetIndexBuffer(0, G_ibuf_108);
   SetIndexBuffer(1, G_ibuf_112);
   SetIndexBuffer(2, G_ibuf_116);
   SetIndexBuffer(3, G_ibuf_120);
   IndicatorShortName(Gs_144);
   SetIndexLabel(1, NULL);
   SetIndexLabel(2, NULL);
   SetIndexLabel(3, NULL);
   ArrayResize(Gsa_156, Number_of_bars_to_calculate);
   G_time_128 = Time[0];
   return (0);
}

// 52D46093050F38C27267BCE42543EF60
int deinit() {
   int Li_0 = ArrayRange(Gsa_156, 0) - 1;
   int Li_4 = 0;
   for (Li_4 = Li_0; Li_4 >= 0; Li_4--)
      if (Gsa_156[Li_4] != "") ObjectDelete(Gsa_156[Li_4]);
   return (0);
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   double Ld_0;
   double Ld_8;
   double Ld_16;
   int Li_24 = IndicatorCounted();
   double Ld_28 = 0;
   double Ld_36 = 0;
   double Ld_unused_44 = 0;
   double Ld_unused_52 = 0;
   double Ld_60 = 0;
   double Ld_unused_68 = 0;
   double low_76 = 0;
   double high_84 = 0;
   int count_92 = 0;
   f0_0();
   int Li_96 = 16777215;
   if (Li_24 > 0) Li_24--;
   int Li_100 = Bars - Li_24;
   if (G_bars_80 >= Bars) G_bars_80 = Bars;
   SetIndexDrawBegin(1, Bars - G_bars_80 + offSet);
   SetIndexDrawBegin(2, Bars - G_bars_80 + offSet);
   int ind_counted_104 = IndicatorCounted();
   if (Bars <= offSet + 1) return (0);
   if (ind_counted_104 < offSet + 1) for (int Li_108 = 1; Li_108 <= offSet; Li_108++) G_ibuf_108[G_bars_80 - Li_108] = 0.0;
   for (Li_108 = 0; Li_108 < Li_100; Li_108++) {
      high_84 = High[iHighest(NULL, 0, MODE_HIGH, offSet, Li_108)];
      low_76 = Low[iLowest(NULL, 0, MODE_LOW, offSet, Li_108)];
      Ld_16 = (High[Li_108] + Low[Li_108]) / 2.0;
      if (high_84 - low_76 == 0.0) Ld_28 = Ld_36 / 4.0 + (-0.125);
      else Ld_28 = ((Ld_16 - low_76) / (high_84 - low_76) - 0.5) / 4.0 + Ld_36 / 4.0;
      Ld_28 = MathMin(MathMax(Ld_28, -0.999), 0.999);
      if (1 - Ld_28 == 0.0) G_ibuf_108[Li_108] = Ld_60 / 4.0 + 0.25;
      else G_ibuf_108[Li_108] = MathLog((Ld_28 + 1.0) / (1 - Ld_28)) / 4.0 + Ld_60 / 4.0;
      Ld_36 = Ld_28;
      Ld_60 = G_ibuf_108[Li_108];
   }
   bool Li_112 = TRUE;
   for (Li_108 = Li_100 - 2; Li_108 >= 0; Li_108--) {
      Ld_8 = G_ibuf_108[Li_108 + 1];
      Ld_0 = G_ibuf_108[Li_108 + 2];
      if ((Ld_8 < 0.0 && Ld_0 > 0.0) || Ld_8 < 0.0) Li_112 = FALSE;
      if ((Ld_8 > 0.0 && Ld_0 < 0.0) || Ld_8 > 0.0) Li_112 = TRUE;
      if (!Li_112) {
         Gs_136 = "SHORT";
         Li_96 = 65535;
      } else {
         Gs_136 = "LONG";
         Li_96 = 65280;
      }
      if (Ld_8 >= 0.0) {
         G_ibuf_112[Li_108 + 1] = Ld_8;
         G_ibuf_116[Li_108 + 1] = EMPTY_VALUE;
      }
      if (Ld_8 < 0.0) {
         G_ibuf_112[Li_108 + 1] = EMPTY_VALUE;
         G_ibuf_116[Li_108 + 1] = Ld_8;
      }
      if (Ld_8 <= 0.0 && Ld_0 > 0.0) {
         G_ibuf_120[Li_108 + 1] = -2.5;
         ArrayMaximum(G_ibuf_112, 100);
         if (Add_vertical_line && count_92 < Number_of_bars_to_calculate) {
            f0_1(Li_108 + 1, Vertical_line_color_short);
            count_92++;
         }
         G_ibuf_112[Li_108 + 1] = EMPTY_VALUE;
         G_ibuf_116[Li_108 + 1] = EMPTY_VALUE;
         if (G_time_128 != Time[0]) {
            if (Alert_Sound) {
               Alert("Error: Short signal on " + Symbol() + "!");
               PlaySound("Alert.wav");
            }
            if (Alert_Email) SendMail("Error", "Error: Short signal on " + Symbol() + "!");
            G_time_128 = Time[0];
         }
      }
      if (Ld_8 >= 0.0 && Ld_0 < 0.0) {
         G_ibuf_120[Li_108 + 1] = 2.5;
         if (Add_vertical_line && count_92 < Number_of_bars_to_calculate) {
            f0_1(Li_108 + 1, Vertical_line_color_long);
            count_92++;
         }
         G_ibuf_112[Li_108 + 1] = EMPTY_VALUE;
         G_ibuf_116[Li_108 + 1] = EMPTY_VALUE;
         if (G_time_128 != Time[0]) {
            if (Alert_Sound) {
               Alert("Error: Long signal on " + Symbol() + "!");
               PlaySound("Alert.wav");
            }
            if (Alert_Email) SendMail("Error", "Error: Long signal on " + Symbol() + "!");
            G_time_128 = Time[0];
         }
      }
   }
   f0_2("Error_ind2", Gs_136, 12, Li_96, 10, 15);
   return (0);
}

// 158D7E1197BD06A8E626874DE72FAA46
void f0_0() {
   f0_3("Error_ind2");
   f0_2("Error_ind2", "", 12, White, 10, 15);
}

// EA3A0E828966333DF661A5256929317B
void f0_3(string A_name_0) {
   ObjectCreate(A_name_0, OBJ_LABEL, WindowFind(Gs_144), 0, 0);
}

// E586BD4368DDB26061EE3FD85A4A2925
void f0_2(string A_name_0, string A_text_8, int A_fontsize_16, color A_color_20, int A_x_24, int A_y_28) {
   ObjectSet(A_name_0, OBJPROP_XDISTANCE, A_x_24);
   ObjectSet(A_name_0, OBJPROP_YDISTANCE, A_y_28);
   ObjectSetText(A_name_0, A_text_8, A_fontsize_16, "Arial", A_color_20);
}

// 443538C7472AA4F2C93D9B3A63CC7612
void f0_1(int Ai_0, color A_color_4) {
   if (ObjectFind(TimeToStr(Time[Ai_0])) == -1) {
      if (ObjectCreate(TimeToStr(Time[Ai_0]), OBJ_VLINE, 0, Time[Ai_0], 0)) {
         Gsa_156[Gi_152] = TimeToStr(Time[Ai_0]);
         ObjectSet(TimeToStr(Time[Ai_0]), OBJPROP_STYLE, STYLE_DOT);
         ObjectSet(TimeToStr(Time[Ai_0]), OBJPROP_COLOR, A_color_4);
         Gi_152++;
      }
   }
}
