
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 Red

extern string TimeFrame = "+1";
extern int MaPeriod = 5;
extern int MaType = 1;
extern bool MultiColor = TRUE;
extern string note = "turn on Alert = true; turn off = false";
extern bool alertsOn = FALSE;
extern bool alertsOnCurrent = TRUE;
extern bool alertsMessage = TRUE;
extern bool alertsSound = TRUE;
extern bool alertsEmail = FALSE;
extern string soundfile = "alert.wav";
double G_ibuf_132[];
double G_ibuf_136[];
double G_ibuf_140[];
double G_ibuf_144[];
string Gs_148;
int G_timeframe_156;
bool G_bool_160;
bool G_bool_164;
string Gsa_168[] = {"0", "M1", "M5", "M15", "M30", "H1", "H4", "D1", "W1", "MN1", ",help", "Help", "chart", "Chart", "+0", "+1", "+2", "+3", "+4", "+5", "+6", "+7", "+8", "-0", "-1",
      "-2", "-3", "-4", "-5", "-6", "-7", "-8"};
int Gia_172[] = {0, 1, 5, 15, 30, 60, 240, 1440, 10080, 43200};
int Gi_180 = 10;
string Gs_nothing_184 = "nothing";
datetime G_time_192;
string Gsa_196[] = {"M1", "M5", "M15", "M30", "H1", "H4", "D1", "W1", "MN"};
int Gia_200[] = {1, 5, 15, 30, 60, 240, 1440, 10080, 43200};

// 6A26F548831E6A8C26BFBBD9F6EC61E0
void f0_3() {
   Alert("If the default timeframe for the chart is H1, then +1 will indicate H4, -1 indicates M30");
   Alert("Enter +1 to specify the next higher TimeFrame; -1 to specify the next lower TimeFrame");
   Alert("To specify variable TimeFrames, use either + or - followed by a number 1 to 8");
   Alert("Variable TimeFrames use the default time period for the chart and add or subtract an offset");
   Alert("By using Variable TimeFrames, you may change the default timeframe on the chart and the indicators will change accordingly");
   Alert("Variable TimeFrames are provided so you can specify multiple Currency Power indicators on the same chart");
   Alert("To specify the default time period for the chart, use chart");
   Alert("Constant TimeFrames are specified using the Metatrader mneumonics, M1,M15,M30.. through MN1");
   Alert("***Help for TimeFrame Input***");
}

// 853E2958380EACE863714177E216596A
int f0_4(string As_0) {
   int Li_16;
   int arr_size_8 = ArraySize(Gsa_168);
   for (int index_12 = 0; index_12 < arr_size_8; index_12++)
      if (As_0 == Gsa_168[index_12]) break;
   if (index_12 < Gi_180) return (index_12);
   if (index_12 == 10 || index_12 == 11) return (-1);
   if (index_12 == 12 || index_12 == 14) return (f0_5(Period()));
   if (index_12 > 13 && index_12 < arr_size_8) {
      Li_16 = f0_5(Period());
      if (index_12 < 22) index_12 = Li_16 + index_12 - 14;
      else index_12 = Li_16 + 23 - index_12;
      return (index_12);
   }
   f0_3();
   Alert("***Invalid TimeFrame = " + As_0);
   return (-1);
}

// AE19BEECAD027856E5A977A822F55A02
int f0_5(int Ai_0) {
   for (int index_4 = 0; index_4 < Gi_180; index_4++)
      if (Gia_172[index_4] == Ai_0) return (index_4);
   f0_3();
   Alert("***Invalid Time Period = " + Ai_0);
   return (-1);
}

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   IndicatorBuffers(4);
   SetIndexBuffer(0, G_ibuf_132);
   SetIndexDrawBegin(0, MaPeriod + 1);
   SetIndexBuffer(1, G_ibuf_136);
   SetIndexBuffer(2, G_ibuf_140);
   SetIndexBuffer(3, G_ibuf_144);
   Gs_148 = WindowExpertName();
   G_bool_164 = TimeFrame == "calculateValue";
   if (G_bool_164) return (0);
   G_bool_160 = TimeFrame == "returnBars";
   if (G_bool_160) return (0);
   int Li_0 = f0_4(TimeFrame);
   if (Li_0 == -1) f0_3();
   if (Li_0 < Gi_180) G_timeframe_156 = Gia_172[Li_0];
   IndicatorShortName(Gsa_168[Li_0] + " Gann SSL");
   return (0);
}

// 52D46093050F38C27267BCE42543EF60
int deinit() {
   return (0);
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   int Li_8;
   double ima_16;
   double ima_24;
   int shift_32;
   int Li_0 = IndicatorCounted();
   if (Li_0 < 0) return (-1);
   if (Li_0 > 0) Li_0--;
   int Li_12 = MathMin(Bars - Li_0, Bars - 1);
   if (G_bool_160) {
      G_ibuf_132[0] = Li_12 + 1;
      return (0);
   }
   if (G_bool_164 || G_timeframe_156 == Period()) {
      if (MultiColor && (!G_bool_164) && G_ibuf_144[Li_12] == -1.0) f0_1(Li_12, G_ibuf_136, G_ibuf_140);
      for (int Li_4 = Li_12; Li_4 >= 0; Li_4--) {
         Li_8 = Li_4 + 1;
         G_ibuf_144[Li_4] = G_ibuf_144[Li_8];
         ima_16 = iMA(Symbol(), 0, MaPeriod, 0, MaType, PRICE_HIGH, Li_8);
         ima_24 = iMA(Symbol(), 0, MaPeriod, 0, MaType, PRICE_LOW, Li_8);
         if (Close[Li_4] > ima_16) G_ibuf_144[Li_4] = 1;
         if (Close[Li_4] < ima_24) G_ibuf_144[Li_4] = -1;
         if (G_ibuf_144[Li_4] == -1.0) G_ibuf_132[Li_4] = ima_16;
         else G_ibuf_132[Li_4] = ima_24;
         if (MultiColor && (!G_bool_164) && G_ibuf_144[Li_4] == -1.0) f0_6(Li_4, G_ibuf_136, G_ibuf_140, G_ibuf_132);
      }
      f0_2();
      return (0);
   }
   Li_12 = MathMax(Li_12, MathMin(Bars, iCustom(NULL, G_timeframe_156, Gs_148, "returnBars", 0, 0) * G_timeframe_156 / Period()));
   if (MultiColor && G_ibuf_144[Li_12] == -1.0) f0_1(Li_12, G_ibuf_136, G_ibuf_140);
   for (Li_4 = Li_12; Li_4 >= 0; Li_4--) {
      shift_32 = iBarShift(NULL, G_timeframe_156, Time[Li_4]);
      G_ibuf_132[Li_4] = iCustom(NULL, G_timeframe_156, Gs_148, "calculateValue", MaPeriod, MaType, 0, shift_32);
      G_ibuf_136[Li_4] = EMPTY_VALUE;
      G_ibuf_140[Li_4] = EMPTY_VALUE;
      G_ibuf_144[Li_4] = iCustom(NULL, G_timeframe_156, Gs_148, "calculateValue", MaPeriod, MaType, 3, shift_32);
   }
   if (MultiColor) {
      for (Li_4 = Li_12; Li_4 >= 0; Li_4--)
         if (G_ibuf_144[Li_4] == -1.0) f0_6(Li_4, G_ibuf_136, G_ibuf_140, G_ibuf_132);
   }
   f0_2();
   return (0);
}

// 304CD8F881C2EC9D8467D17452E084AC
void f0_2() {
   int Li_0;
   if ((!G_bool_164) && alertsOn) {
      if (alertsOnCurrent) Li_0 = 0;
      else Li_0 = 1;
      Li_0 = iBarShift(NULL, 0, iTime(NULL, G_timeframe_156, Li_0));
      if (G_ibuf_144[Li_0] != G_ibuf_144[Li_0 + 1]) {
         if (G_ibuf_144[Li_0] == 1.0) f0_7(Li_0, "up");
         if (G_ibuf_144[Li_0] == -1.0) f0_7(Li_0, "down");
      }
   }
}

// DA717D55A7C333716E8D000540764674
void f0_7(int Ai_0, string As_4) {
   string str_concat_12;
   if (Gs_nothing_184 != As_4 || G_time_192 != Time[Ai_0]) {
      Gs_nothing_184 = As_4;
      G_time_192 = Time[Ai_0];
      str_concat_12 = StringConcatenate(Symbol(), " ", f0_0(G_timeframe_156), " at ", TimeToStr(TimeLocal(), TIME_SECONDS), " GANN SSL TF+1 has changed direction to ",
         As_4);
      if (alertsMessage) Alert(str_concat_12);
      if (alertsEmail) SendMail(StringConcatenate(Symbol(), " Gannline  "), str_concat_12);
      if (alertsSound) PlaySound("alert.wav");
   }
}

// 21F8D7C6ACBD885873A4BA3D594D41CD
void f0_1(int Ai_0, double &Gda_4[], double &Gda_8[]) {
   if (Gda_8[Ai_0] != EMPTY_VALUE && Gda_8[Ai_0 + 1] != EMPTY_VALUE) {
      Gda_8[Ai_0 + 1] = EMPTY_VALUE;
      return;
   }
   if (Gda_4[Ai_0] != EMPTY_VALUE && Gda_4[Ai_0 + 1] != EMPTY_VALUE && Gda_4[Ai_0 + 2] == EMPTY_VALUE) Gda_4[Ai_0 + 1] = EMPTY_VALUE;
}

// D1B45A6FF1A5430B6E40FB3AD384517E
void f0_6(int Ai_0, double &Gda_4[], double &Gda_8[], double Gda_12[]) {
   if (Gda_4[Ai_0 + 1] == EMPTY_VALUE) {
      if (Gda_4[Ai_0 + 2] == EMPTY_VALUE) {
         Gda_4[Ai_0] = Gda_12[Ai_0];
         Gda_4[Ai_0 + 1] = Gda_12[Ai_0 + 1];
         Gda_8[Ai_0] = EMPTY_VALUE;
         return;
      }
      Gda_8[Ai_0] = Gda_12[Ai_0];
      Gda_8[Ai_0 + 1] = Gda_12[Ai_0 + 1];
      Gda_4[Ai_0] = EMPTY_VALUE;
      return;
   }
   Gda_4[Ai_0] = Gda_12[Ai_0];
   Gda_8[Ai_0] = EMPTY_VALUE;
}

// 1368D28A27D3419A04740CF6C5C45FD7
string f0_0(int Ai_0) {
   for (int Li_4 = ArraySize(Gia_200) - 1; Li_4 >= 0; Li_4--)
      if (Ai_0 == Gia_200[Li_4]) return (Gsa_196[Li_4]);
   return ("");
}