
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Black
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Yellow

extern int offSet = 18;
int g_bars_80 = 1500;
extern bool Add_vertical_line = FALSE;
extern color Vertical_line_color_long = Blue;
extern color Vertical_line_color_short = FireBrick;
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 = "reverse point";
int gi_152 = 0;
string gsa_156[];

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);
}

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);
}

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);
}

void f0_0() {
   f0_3("Error_ind2");
   f0_2("Error_ind2", "", 12, White, 10, 15);
}

void f0_3(string a_name_0) {
   ObjectCreate(a_name_0, OBJ_LABEL, WindowFind(gs_144), 0, 0);
}

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);
}

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++;
      }
   }
}