

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Aqua
#property indicator_color2 Orange
//#property indicator_color3 Black
//#property indicator_color4 Black

extern int PeriodIndikator = 9;
extern double Factor = 1.0;
extern double HistoriBar = 1000.0;
extern bool alert = FALSE;
extern bool sound = TRUE;
extern bool email = FALSE;
double G_ibuf_108[];
double G_ibuf_112[];
//double G_ibuf_116[];
//double G_ibuf_120[];
double Gd_unused_124;
double Gd_unused_132;
double Gd_148 = 1000.0;
double Gd_156 = 0.0;
double Gd_unused_164 = 1000.0;
double Gd_unused_172 = 0.0;
int Gi_180 = 1;
int Gi_unused_184 = 1;
int Gi_unused_188;
datetime G_time_192;

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   Gi_unused_188 = 1;
   if (Digits == 5 || Digits == 3) Gi_unused_188 = 10;
   IndicatorBuffers(2);
   SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 2);
   SetIndexDrawBegin(0, 0);
   SetIndexBuffer(0, G_ibuf_108);
   SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 2);
   SetIndexDrawBegin(1, 0);
   SetIndexBuffer(1, G_ibuf_112);
   SetIndexArrow(0, 233);
   SetIndexArrow(1, 234);
   /*SetIndexBuffer(2, G_ibuf_116);
   SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID, 0);
   SetIndexArrow(2, 110);
   SetIndexBuffer(3, G_ibuf_120);
   SetIndexStyle(3, DRAW_ARROW, STYLE_SOLID, 0);
   SetIndexArrow(3, 110);*/
   return (0);
}

// B83A886A5C437CCD9AC15473FD6F1788
void f0_2(string As_0) {
   if (IsTesting() == FALSE && IsOptimization() == FALSE && IsVisualMode() == FALSE) SendMail(WindowExpertName(), As_0);
}

// A8CFDE6331BD59EB2AC96F8911C4B666
void f0_1(string A_name_0, string A_text_8, string A_fontname_16, int A_fontsize_24, color A_color_28, int A_y_32, int A_x_36, int A_corner_40, int A_bool_44) {
   ObjectCreate(A_name_0, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(A_name_0, A_text_8, A_fontsize_24, A_fontname_16, A_color_28);
   ObjectSet(A_name_0, OBJPROP_CORNER, A_corner_40);
   ObjectSet(A_name_0, OBJPROP_XDISTANCE, A_x_36);
   ObjectSet(A_name_0, OBJPROP_YDISTANCE, A_y_32);
   ObjectSet(A_name_0, OBJPROP_BACK, A_bool_44);
}

// 085FEA7ABDC5D904FE69A3081EFD7398
void f0_0(string As_0) {
   if (IsTesting() == FALSE && IsOptimization() == FALSE && IsVisualMode() == FALSE) {
      if (sound) PlaySound("News.wav");
      if (alert) Alert("New signal " + As_0);
      if (email) f0_2("New signal " + As_0);
   }
}

// BE8F80182E0C983916DA7338C2C1C040
int f0_3(string A_name_0, string A_name_8) {
   if (ObjectFind(A_name_0) == -1) return (0);
   if (ObjectFind(A_name_8) == -1) return (0);
   if (ObjectGet(A_name_0, OBJPROP_XDISTANCE) > ObjectGet(A_name_8, OBJPROP_XDISTANCE) - 10.0 && ObjectGet(A_name_0, OBJPROP_XDISTANCE) < ObjectGet(A_name_8, OBJPROP_XDISTANCE) +
      10.0) {
      if (ObjectGet(A_name_0, OBJPROP_YDISTANCE) > ObjectGet(A_name_8, OBJPROP_YDISTANCE) - 10.0 && ObjectGet(A_name_0, OBJPROP_YDISTANCE) < ObjectGet(A_name_8, OBJPROP_YDISTANCE) +
         10.0) return (1);
   }
   return (0);
}

// E4DB2306E8CC4DEB5830201DE61935CA
double f0_4() {
   double Ld_ret_0 = 0;
   for (int pos_8 = 0; pos_8 < OrdersTotal(); pos_8++) {
      if (OrderSelect(pos_8, SELECT_BY_POS, MODE_TRADES) == TRUE)
         if (OrderSymbol() == Symbol()) Ld_ret_0 += OrderProfit();
   }
   return (Ld_ret_0);
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   string Ls_0;
   double iatr_20;
   double Ld_28;
   double Ld_36;
   if (f0_3("x", "r4") == 1) {
      alert = FALSE;
      ObjectDelete("r2");
      f0_1("x", "G", "Wingdings", 25, Pink, 160, 55, 1, FALSE);
      PlaySound("Tick.wav");
      G_time_192 = 0;
      RefreshRates();
   }
   if (f0_3("x", "t4") == 1) {
      sound = FALSE;
      ObjectDelete("t2");
      f0_1("x", "G", "Wingdings", 25, Pink, 160, 55, 1, FALSE);
      PlaySound("Tick.wav");
      G_time_192 = 0;
      RefreshRates();
   }
   if (f0_3("x", "u4") == 1) {
      email = FALSE;
      ObjectDelete("u2");
      f0_1("x", "G", "Wingdings", 25, Pink, 160, 55, 1, FALSE);
      PlaySound("Tick.wav");
      G_time_192 = 0;
      RefreshRates();
   }
   if (f0_3("x", "r3") == 1) {
      alert = TRUE;
      f0_1("r2", "þ", "Wingdings", 14, Red, 55, 65, 1, FALSE);
      f0_1("x", "G", "Wingdings", 25, Pink, 160, 55, 1, FALSE);
      PlaySound("Tick.wav");
      G_time_192 = 0;
      RefreshRates();
   }
   if (f0_3("x", "t3") == 1) {
      sound = TRUE;
      f0_1("t2", "þ", "Wingdings", 14, Red, 80, 65, 1, FALSE);
      f0_1("x", "G", "Wingdings", 25, Pink, 160, 55, 1, FALSE);
      PlaySound("Tick.wav");
      G_time_192 = 0;
      RefreshRates();
   }
   if (f0_3("x", "u3") == 1) {
      email = TRUE;
      f0_1("u2", "þ", "Wingdings", 14, Red, 105, 65, 1, FALSE);
      f0_1("x", "G", "Wingdings", 25, Pink, 160, 55, 1, FALSE);
      PlaySound("Tick.wav");
      G_time_192 = 0;
      RefreshRates();
   }
   for (int index_8 = 0; index_8 < 100; index_8++) {
      if (G_ibuf_108[index_8] < 1000.0) {
         Ls_0 = "BUY";
         break;
      }
      if (G_ibuf_112[index_8] < 1000.0) {
         Ls_0 = "SELL";
         break;
      }
   }
   if (Ls_0 == "BUY" && ObjectDescription("Signal1") != "BUY") {
      f0_0("BUY");
      f0_1("Signal1", "BUY", "Comic Sans MS", 30, Aqua, 80, 32, 1, FALSE);
   }
   if (Ls_0 == "SELL" && ObjectDescription("Signal1") != "SELL") {
      f0_0("SELL");
      f0_1("Signal1", "SELL", "Comic Sans MS", 30, Orange, 80, 25, 1, FALSE);
   }
   f0_1("r1", "Profit", "Arial", 10, Lime, 50, 80, 1, FALSE);
   f0_1("Pr", DoubleToStr(f0_4(), 0), "Arial", 13, Yellow, 50, 35, 1, FALSE);
   if (Time[0] == G_time_192) return (0);
   G_time_192 = Time[0];
   int Li_12 = Bars - IndicatorCounted();
   if (IndicatorCounted() > 0) Li_12++;
   for (int bars_16 = Bars; bars_16 > 0; bars_16--) {
      if (bars_16 <= HistoriBar) {
         iatr_20 = iATR(NULL, 0, 100, 0);
         Ld_28 = Close[bars_16] - iATR(NULL, 0, PeriodIndikator, bars_16) * Factor;
         Ld_36 = Close[bars_16] + iATR(NULL, 0, PeriodIndikator, bars_16) * Factor;
         if (Ld_28 > Gd_156 && Gi_180 == 1) Gd_156 = Ld_28;
         if (Ld_36 < Gd_148 && Gi_180 == 2) Gd_148 = Ld_36;
         //if (Gd_156 != 0.0 && Gi_180 == 1) Gd_unused_124 = Gd_156;
         //if (Gd_148 != 1000.0 && Gi_180 == 2) Gd_unused_132 = Gd_148;
         if (Close[bars_16] < Gd_156 && Gi_180 == 1) {
            Gi_180 = 2;
            if (bars_16 < HistoriBar / 2.0) G_ibuf_112[bars_16] = High[bars_16] + iatr_20;
            Gd_156 = 0;
         }
         if (Close[bars_16] > Gd_148 && Gi_180 == 2) {
            Gi_180 = 1;
            if (bars_16 < HistoriBar / 2.0) G_ibuf_108[bars_16] = Low[bars_16] - iatr_20;
            Gd_148 = 1000;
         }
         //Print(G_ibuf_112[bars_16]);
      }
   }
   return (0);
}

// 52D46093050F38C27267BCE42543EF60
int deinit() {
   if (IsTesting() == FALSE && IsOptimization() == FALSE && IsVisualMode() == FALSE) {
      ObjectDelete("Fon");
      ObjectDelete("x");
      ObjectDelete("V");
      ObjectDelete("W");
      ObjectDelete("r1");
      ObjectDelete("r2");
      ObjectDelete("r3");
      ObjectDelete("r4");
      ObjectDelete("t1");
      ObjectDelete("t2");
      ObjectDelete("t3");
      ObjectDelete("t4");
      ObjectDelete("u1");
      ObjectDelete("u2");
      ObjectDelete("u3");
      ObjectDelete("u4");
      ObjectDelete("Signal1");
      ObjectDelete("Signal2");
      ObjectDelete("Time");
      ObjectDelete("Pr");
   }
   return (0);
}
