
#property copyright "Point Zero Trading Solutions,Fix Connection Issue,Squall 0109"
#property link      "http://www.pointzero-trading.com"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Silver
#property indicator_color2 Silver
#property indicator_color3 DeepSkyBlue
#property indicator_color4 Salmon

int Gia_76[] = {33, 42, 39, 40, 41, 59, 58, 64, 38, 61, 43, 36, 47, 63, 35, 91, 93};
string Gs_80;
extern string Settings_ex = "---- Indicator Settings";
extern int TrendPeriod = 200;
extern int SwingPeriod = 120;
extern int MaxHistoryBars = 3000;
extern bool Swings = TRUE;
extern bool Corrections = TRUE;
extern string CL_Settings = "---- Drawing Settings";
extern color BullColor = DeepSkyBlue;
extern color BearColor = Tomato;
extern int ArrowSize = 3;
extern int LineWidth = 4;
extern string Alerts_ex = "---- Alerts";
extern string AlertCaption = "My Alert Name";
extern bool DisplayAlerts = FALSE;
extern bool EmailAlerts = FALSE;
extern bool PushAlerts = FALSE;
extern bool SoundAlerts = FALSE;
extern string SoundFile = "alert.wav";
double G_ibuf_180[];
double G_ibuf_184[];
double G_ibuf_188[];
double G_ibuf_192[];
double G_ibuf_196[];
double G_ibuf_200[];
double G_ibuf_204[];
double G_ibuf_208[];
string Gs_212;
bool Gi_220;
string Gs_224;
double Gd_unused_232;
double Gd_unused_240;
int Gi_unused_248;
int Gi_252;
int Gi_256;
double Gd_260;
double Gd_268;
int Gi_276;
int Gi_280;
int Gi_284;
int Gi_288;
bool Gi_unused_292 = FALSE;
int Gi_296;
bool Gi_300 = TRUE;
int Gi_unused_304 = EMPTY_VALUE;

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   IndicatorBuffers(8);
   IndicatorShortName("PZ Swing Trading");
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexStyle(2, DRAW_HISTOGRAM);
   SetIndexStyle(3, DRAW_HISTOGRAM);
   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
   SetIndexBuffer(0, G_ibuf_180);
   SetIndexBuffer(1, G_ibuf_184);
   SetIndexBuffer(2, G_ibuf_188);
   SetIndexBuffer(3, G_ibuf_192);
   SetIndexBuffer(4, G_ibuf_196);
   SetIndexBuffer(5, G_ibuf_200);
   SetIndexBuffer(6, G_ibuf_204);
   SetIndexBuffer(7, G_ibuf_208);
   Gs_80 = f0_1();
   double Ld_0 = TrendPeriod;
   Gd_260 = Ld_0 / 100.0;
   Ld_0 = SwingPeriod;
   Gd_268 = Ld_0 / 100.0;
   if (Gd_260 <= 0.75 || ((!Swings) && (!Corrections))) Gi_220 = FALSE;
   else Gi_220 = TRUE;
   Gi_276 = TrendPeriod / 2;
   Gi_280 = TrendPeriod / 4;
   Gi_284 = TrendPeriod / 8;
   Gi_288 = TrendPeriod / 16;
   Gs_212 = "PZST" + "-" + DoubleToStr(Gd_260, 2);
   Gs_224 = WindowExpertName();
   f0_4();
   f0_3();
   return (0);
}

// F7B1F0AA13347699EFAE0D924298CB02
void f0_4() {
   string name_0;
   int objs_total_8 = ObjectsTotal();
   for (int Li_12 = objs_total_8 - 1; Li_12 >= 0; Li_12--) {
      name_0 = ObjectName(Li_12);
      if (StringFind(name_0, Gs_212) != -1) ObjectDelete(name_0);
   }
}

// 52D46093050F38C27267BCE42543EF60
int deinit() {
   f0_3();
   f0_4();
   return (0);
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   int Li_unused_4;
   double iatr_8;
   double Ld_16;
   double Ld_24;
   double icustom_32;
   double icustom_40;
   double icustom_48;
   double icustom_56;
   double icustom_64;
   double icustom_72;
   double icustom_80;
   double icustom_88;
   int count_96;
   int count_100;
   int count_104;
   double Ld_108;
   string Ls_unused_116;
   bool bool_124;
   bool bool_128;
   bool bool_132;
   bool bool_136;
   bool bool_140;
   double Ld_144;
   double Ld_152;
   double Ld_160;
   double Ld_168;
   int Li_176 = 1;
   int ind_counted_180 = IndicatorCounted();
   if (ind_counted_180 < 0) return (-1);
   int Li_184 = Bars - 1 - ind_counted_180;
   for (int Li_188 = Li_184; Li_188 >= Li_176; Li_188--) {
      Li_unused_4 = Li_188 > MaxHistoryBars;
      iatr_8 = iATR(Symbol(), 0, 100, Li_188);
      Ld_16 = High[Li_188] + iatr_8 * Gd_260;
      Ld_24 = Low[Li_188] - iatr_8 * Gd_260;
      if (G_ibuf_196[Li_188 + 1] != EMPTY_VALUE && Ld_24 < G_ibuf_196[Li_188 + 1]) Ld_24 = G_ibuf_196[Li_188 + 1];
      if (G_ibuf_200[Li_188 + 1] != EMPTY_VALUE && Ld_16 > G_ibuf_200[Li_188 + 1]) Ld_16 = G_ibuf_200[Li_188 + 1];
      G_ibuf_208[Li_188] = G_ibuf_208[Li_188 + 1];
      G_ibuf_196[Li_188] = EMPTY_VALUE;
      G_ibuf_200[Li_188] = EMPTY_VALUE;
      G_ibuf_204[Li_188] = EMPTY_VALUE;
      if (Close[Li_188] > Ld_16 && G_ibuf_208[Li_188 + 1] != 0.0) G_ibuf_208[Li_188] = 0;
      else
         if (Close[Li_188] < Ld_24 && G_ibuf_208[Li_188 + 1] != 1.0) G_ibuf_208[Li_188] = 1;
      if (G_ibuf_208[Li_188] == 0.0) {
         G_ibuf_196[Li_188] = Ld_24;
         G_ibuf_180[Li_188] = Ld_24;
         G_ibuf_184[Li_188] = Ld_24 + iatr_8 * Gd_268;
         G_ibuf_188[Li_188] = G_ibuf_184[Li_188];
         G_ibuf_192[Li_188] = G_ibuf_180[Li_188];
      } else {
         G_ibuf_200[Li_188] = Ld_16;
         G_ibuf_180[Li_188] = Ld_16;
         G_ibuf_184[Li_188] = Ld_16 - iatr_8 * Gd_268;
         G_ibuf_188[Li_188] = G_ibuf_184[Li_188];
         G_ibuf_192[Li_188] = G_ibuf_180[Li_188];
      }
      if ((!Gi_220) || iatr_8 == 0.0 || iatr_8 == EMPTY_VALUE) continue;
      icustom_32 = iCustom(Symbol(), 0, Gs_224, Settings_ex, Gi_276, SwingPeriod, MaxHistoryBars, 0, 0, 7, Li_188);
      icustom_40 = iCustom(Symbol(), 0, Gs_224, Settings_ex, Gi_276, SwingPeriod, MaxHistoryBars, 0, 0, 7, Li_188 + 1);
      icustom_48 = iCustom(Symbol(), 0, Gs_224, Settings_ex, Gi_280, SwingPeriod, MaxHistoryBars, 0, 0, 7, Li_188);
      icustom_56 = iCustom(Symbol(), 0, Gs_224, Settings_ex, Gi_280, SwingPeriod, MaxHistoryBars, 0, 0, 7, Li_188 + 1);
      icustom_64 = iCustom(Symbol(), 0, Gs_224, Settings_ex, Gi_284, SwingPeriod, MaxHistoryBars, 0, 0, 7, Li_188);
      icustom_72 = iCustom(Symbol(), 0, Gs_224, Settings_ex, Gi_284, SwingPeriod, MaxHistoryBars, 0, 0, 7, Li_188 + 1);
      icustom_80 = iCustom(Symbol(), 0, Gs_224, Settings_ex, Gi_288, SwingPeriod, MaxHistoryBars, 0, 0, 7, Li_188);
      icustom_88 = iCustom(Symbol(), 0, Gs_224, Settings_ex, Gi_288, SwingPeriod, MaxHistoryBars, 0, 0, 7, Li_188 + 1);
      count_96 = 0;
      count_100 = 0;
      count_104 = 0;
      Ld_108 = 0;
      bool_124 = G_ibuf_208[Li_188] != G_ibuf_208[Li_188 + 1];
      bool_128 = icustom_32 != icustom_40;
      bool_132 = icustom_48 != icustom_56;
      bool_136 = icustom_64 != icustom_72;
      bool_140 = icustom_80 != icustom_88;
      if (G_ibuf_208[Li_188] == 0.0) count_100++;
      if (icustom_32 == 0.0) count_100++;
      if (icustom_48 == 0.0) count_100++;
      if (icustom_64 == 0.0) count_100++;
      if (icustom_80 == 0.0) count_100++;
      if (G_ibuf_208[Li_188] == 1.0) count_104++;
      if (icustom_32 == 1.0) count_104++;
      if (icustom_48 == 1.0) count_104++;
      if (icustom_64 == 1.0) count_104++;
      if (icustom_80 == 1.0) count_104++;
      if (bool_124) count_96++;
      if (bool_128) count_96++;
      if (bool_132) count_96++;
      if (bool_136) count_96++;
      if (bool_140) count_96++;
      Ld_144 = iHigh(Symbol(), Period(), iHighest(Symbol(), Period(), MODE_HIGH, 3, Li_188));
      Ld_152 = iLow(Symbol(), Period(), iLowest(Symbol(), Period(), MODE_LOW, 3, Li_188));
      Ld_160 = Ld_24 + iatr_8 * (Gd_260 + 0.5);
      Ld_168 = Ld_16 - iatr_8 * (Gd_260 + 0.5);
      if (Corrections && G_ibuf_208[Li_188] == 1.0 && icustom_80 == 0.0 && bool_140 && Gi_252 <= 1 && Ld_152 <= Ld_168 && Close[Li_188] > Open[Li_188] && Close[Li_188] > High[Li_188 +
         1] || Close[Li_188] > High[Li_188 + 2]) {
         Ld_108 = Ld_152;
         Ls_unused_116 = "CR";
         f0_0(Li_188, Li_188 + 2, Ld_108, Ld_108, BullColor, STYLE_SOLID, LineWidth, FALSE);
         Gd_unused_232 = Ld_108;
         G_ibuf_204[Li_188] = 2;
      }
      if (Corrections && G_ibuf_208[Li_188] == 0.0 && icustom_80 == 1.0 && bool_140 && Gi_256 <= 1 && Ld_144 >= Ld_160 && Close[Li_188] < Open[Li_188] && Close[Li_188] < Low[Li_188 +
         1] || Close[Li_188] < Low[Li_188 + 2]) {
         Ld_108 = Ld_144;
         Ls_unused_116 = "CR";
         f0_0(Li_188, Li_188 + 2, Ld_108, Ld_108, BearColor, STYLE_SOLID, LineWidth, FALSE);
         Gd_unused_240 = Ld_108;
         G_ibuf_204[Li_188] = 3;
      }
      if (Swings && G_ibuf_208[Li_188] == 0.0 && icustom_80 == 0.0 && bool_140 && Ld_152 <= G_ibuf_184[Li_188] && Close[Li_188] > Open[Li_188] && Close[Li_188] > High[Li_188 +
         1] || Close[Li_188] > High[Li_188 + 2]) {
         Ld_108 = Ld_152;
         Ls_unused_116 = "SW";
         f0_2(Li_188, Ld_108, 233, BullColor, STYLE_SOLID, ArrowSize);
         Gd_unused_232 = Ld_108;
         G_ibuf_204[Li_188] = 0;
      }
      if (Swings && G_ibuf_208[Li_188] == 1.0 && icustom_80 == 1.0 && bool_140 && Ld_144 >= G_ibuf_184[Li_188] && Close[Li_188] < Open[Li_188] && Close[Li_188] < Low[Li_188 +
         1] || Close[Li_188] < Low[Li_188 + 2]) {
         Ld_108 = Ld_144;
         Ls_unused_116 = "SW";
         f0_2(Li_188, Ld_108, 234, BearColor, STYLE_SOLID, ArrowSize);
         Gd_unused_240 = Ld_108;
         G_ibuf_204[Li_188] = 1;
      }
      Gi_unused_248 = count_96;
      Gi_252 = count_100;
      Gi_256 = count_104;
   }
   if (Gi_296 != Time[0]) {
      if (G_ibuf_204[1] == 0.0 && Gi_300 == FALSE) {
         if (DisplayAlerts == TRUE) Alert("PZ Swing Trading" + " (" + AlertCaption + ") [" + Symbol() + "] Bullish Swing");
         if (PushAlerts == TRUE) SendNotification("PZ Swing Trading" + " (" + AlertCaption + ") [" + Symbol() + "] Bullish Swing");
         if (EmailAlerts == TRUE) SendMail("PZ Swing Trading" + " (" + AlertCaption + ") [" + Symbol() + "]", Symbol() + ": Bullish Swing");
         if (SoundAlerts == TRUE) PlaySound(SoundFile);
      } else {
         if (G_ibuf_204[1] == 1.0 && Gi_300 == FALSE) {
            if (DisplayAlerts == TRUE) Alert("PZ Swing Trading" + " (" + AlertCaption + ") [" + Symbol() + "] Bearish Swing");
            if (PushAlerts == TRUE) SendNotification("PZ Swing Trading" + " (" + AlertCaption + ") [" + Symbol() + "] Bearish Swing");
            if (EmailAlerts == TRUE) SendMail("PZ Swing Trading" + " (" + AlertCaption + ") [" + Symbol() + "]", Symbol() + ": Bearish Swing");
            if (SoundAlerts == TRUE) PlaySound(SoundFile);
         } else {
            if (G_ibuf_204[1] == 2.0 && Gi_300 == FALSE) {
               if (DisplayAlerts == TRUE) Alert("PZ Swing Trading" + " (" + AlertCaption + ") [" + Symbol() + "] Bullish Correction @ Downtrend");
               if (PushAlerts == TRUE) SendNotification("PZ Swing Trading" + " (" + AlertCaption + ") [" + Symbol() + "] Bullish Correction @ Downtrend");
               if (EmailAlerts == TRUE) SendMail("PZ Swing Trading" + " (" + AlertCaption + ") [" + Symbol() + "]", Symbol() + ": Bullish Correction @ Downtrend");
               if (SoundAlerts == TRUE) PlaySound(SoundFile);
            } else {
               if (G_ibuf_204[1] == 3.0 && Gi_300 == FALSE) {
                  if (DisplayAlerts == TRUE) Alert("PZ Swing Trading" + " (" + AlertCaption + ") [" + Symbol() + "] Bearish Correction @ Uptrend");
                  if (PushAlerts == TRUE) SendNotification("PZ Swing Trading" + " (" + AlertCaption + ") [" + Symbol() + "] Bearish Correction @ Uptrend");
                  if (EmailAlerts == TRUE) SendMail("PZ Swing Trading" + " (" + AlertCaption + ") [" + Symbol() + "]", Symbol() + ": Bearish Correction @ Uptrend");
                  if (SoundAlerts == TRUE) PlaySound(SoundFile);
               }
            }
         }
      }
      Gi_296 = Time[0];
      Gi_300 = FALSE;
   }
   return (0);
}

// AA5EA51BFAC7B64E723BF276E0075513
int f0_2(int Ai_0, double A_price_4, int Ai_12, color A_color_16, int A_style_20, int A_width_24) {
   int time_28 = Time[Ai_0];
   string name_32 = Gs_212 + "-" + DoubleToStr(time_28, 2);
   ObjectCreate(name_32, OBJ_ARROW, 0, time_28, A_price_4);
   ObjectSet(name_32, OBJPROP_ARROWCODE, Ai_12);
   ObjectSet(name_32, OBJPROP_STYLE, A_style_20);
   ObjectSet(name_32, OBJPROP_WIDTH, A_width_24);
   ObjectSet(name_32, OBJPROP_COLOR, A_color_16);
   return (0);
}

// 2230DA82D7FAFF3EA8CD4CFC92DE64E8
void f0_0(int Ai_0, int Ai_4, double A_price_8, double A_price_16, color A_color_24, int A_style_28, int A_width_32, int A_bool_36) {
   int time_40 = Time[Ai_0];
   int time_44 = Time[Ai_4];
   string name_48 = Gs_212 + "-" + DoubleToStr(time_40, 0);
   if (ObjectFind(name_48) != -1) ObjectDelete(name_48);
   ObjectCreate(name_48, OBJ_TREND, 0, time_40, A_price_8, time_44, A_price_16);
   ObjectSet(name_48, OBJPROP_RAY, A_bool_36);
   ObjectSet(name_48, OBJPROP_STYLE, A_style_28);
   ObjectSet(name_48, OBJPROP_WIDTH, A_width_32);
   ObjectSet(name_48, OBJPROP_COLOR, A_color_24);
   ObjectSet(name_48, OBJPROP_BACK, TRUE);
}

// C23BD2D05F1A927B2825264A247F4626
void f0_3(string As_0 = "") {
//   Comment("Copyright ?http://www.pointzero-trading.com\n" + As_0);
}

// 3180D254E1C24E987439E4F62708F6A2
string f0_1() {
   return (StringSubstr(WindowExpertName(), 16, 10));
}
