/*
   Generated by EX4-TO-MQ4 decompiler V4.0.438.3 [-]
   Website: https://purebeam.biz
   E-mail : purebeam@gmail.com
*/

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 DarkTurquoise
#property indicator_color2 Orange
#property indicator_color3 Red

int g_width_76 = 3;
extern int SignalPeriod = 29;
int gi_84 = 0;
int g_ma_method_88 = MODE_LWMA;
int g_applied_price_92 = PRICE_CLOSE;
double gd_96 = 1.8;
bool gi_104 = TRUE;
int gi_108 = 0;
int gi_112 = 10000;
bool gi_116 = FALSE;
extern int aTake_Profit = 15;
extern int aStop_Loss = 15;
extern bool aAlerts = TRUE;
extern bool EmailOn = TRUE;
datetime g_time_136;
string gs_148;
string gs_156 = "Super Trend Profit";
double g_ibuf_164[];
double g_ibuf_168[];
double g_ibuf_172[];
double g_ibuf_176[];
int gi_180;
string gs_184;
int gi_unused_192 = 0;
string g_name_196 = "informerR";
string gs_signall_204 = "signalL";
extern int SignalTextSize = 14;
extern int InformerTextSize = 14;
extern color BuySignalColor = DarkTurquoise;
extern color SellSignalColor = Red;

string f0_4() {
   string timeframe_4;
   switch (Period()) {
   case PERIOD_M1:
      timeframe_4 = "M1";
      break;
   case PERIOD_M5:
      timeframe_4 = "M5";
      break;
   case PERIOD_M15:
      timeframe_4 = "M15";
      break;
   case PERIOD_M30:
      timeframe_4 = "M30";
      break;
   case PERIOD_H1:
      timeframe_4 = "H1";
      break;
   case PERIOD_H4:
      timeframe_4 = "H4";
      break;
   case PERIOD_D1:
      timeframe_4 = "D1";
      break;
   case PERIOD_W1:
      timeframe_4 = "W1";
      break;
   case PERIOD_MN1:
      timeframe_4 = "MN1";
      break;
   default:
      timeframe_4 = Period();
   }
   return (timeframe_4);
}

void f0_10(string as_0, double ad_8, double ad_16, double ad_24) {
   string ls_32;
   string ls_40;
   string ls_48;
   string ls_56;
   if (Time[0] != g_time_136) {
      g_time_136 = Time[0];
      if (gs_148 != as_0) {
         gs_148 = as_0;
         if (ad_8 != 0.0) ls_48 = " @ Price " + DoubleToStr(ad_8, 4);
         else ls_48 = "";
         if (ad_16 != 0.0) ls_40 = ", TakeProfit   " + DoubleToStr(ad_16, 4);
         else ls_40 = "";
         if (ad_24 != 0.0) ls_32 = ", StopLoss   " + DoubleToStr(ad_24, 4);
         else ls_32 = "";
         ls_56 = gs_184 + "Super Trend Profit " + f0_3() + " Alert " + as_0 + "" + ls_48 + ls_40 + ls_32 + " ";
         Alert(ls_56, Symbol(), ", ", Period(), " minutes chart");
         PlaySound("alert.wav");
         if (EmailOn) SendMail(gs_184, ls_56);
      }
   }
}

int init() {
   IndicatorBuffers(4);
   if ((!SetIndexBuffer(0, g_ibuf_164)) && !SetIndexBuffer(1, g_ibuf_168) && (!SetIndexBuffer(2, g_ibuf_172)) && (!SetIndexBuffer(3, g_ibuf_176))) Print("cannot set indicator buffers!");
   if (gi_104) {
      SetIndexStyle(0, DRAW_NONE, EMPTY, g_width_76 - 1);
      SetIndexStyle(1, DRAW_NONE, EMPTY, g_width_76 - 1);
      SetIndexStyle(2, DRAW_NONE, EMPTY, g_width_76 - 1);
      SetIndexArrow(0, 159);
      SetIndexArrow(1, 159);
      SetIndexArrow(2, 159);
   } else {
      SetIndexStyle(0, DRAW_NONE);
      SetIndexStyle(1, DRAW_NONE);
      SetIndexStyle(2, DRAW_NONE);
   }
   gi_180 = SignalPeriod + MathFloor(MathSqrt(SignalPeriod));
   SetIndexDrawBegin(0, gi_180);
   SetIndexDrawBegin(1, gi_180);
   SetIndexDrawBegin(2, gi_180);
   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS) + 1.0);
   IndicatorShortName("Super Trend Profit(" + SignalPeriod + ")");
   SetIndexLabel(0, "Super Trend Profit");
   gs_184 = Symbol() + " (" + f0_4() + "):  ";
   gs_148 = "";
   ArrayInitialize(g_ibuf_164, EMPTY_VALUE);
   ArrayInitialize(g_ibuf_172, EMPTY_VALUE);
   ArrayInitialize(g_ibuf_168, EMPTY_VALUE);
   return (0);
}

int deinit() {
   f0_7();
   ObjectsDeleteAll(0, OBJ_TEXT);
   ObjectsDeleteAll(0, OBJ_LABEL);
   return (0);
}

int start() {
   double ima_on_arr_20;
   int li_unused_28;
   int ind_counted_8 = IndicatorCounted();
   if (ind_counted_8 < 1) {
      for (int li_4 = 0; li_4 <= gi_180; li_4++) g_ibuf_176[Bars - li_4] = 0;
      for (li_4 = 0; li_4 <= SignalPeriod; li_4++) {
         g_ibuf_164[Bars - li_4] = EMPTY_VALUE;
         g_ibuf_168[Bars - li_4] = EMPTY_VALUE;
         g_ibuf_172[Bars - li_4] = EMPTY_VALUE;
      }
   }
   int li_0 = Bars - ind_counted_8;
   for (li_4 = 1; li_4 < li_0; li_4++) {
      g_ibuf_176[li_4] = 2.0 * iMA(NULL, 0, MathFloor(SignalPeriod / gd_96), gi_84, g_ma_method_88, g_applied_price_92, li_4) - iMA(NULL, 0, SignalPeriod, gi_84, g_ma_method_88,
         g_applied_price_92, li_4);
   }
   double ima_on_arr_12 = iMAOnArray(g_ibuf_176, 0, MathFloor(MathSqrt(SignalPeriod)), 0, g_ma_method_88, 1);
   for (li_4 = 2; li_4 < li_0 + 1; li_4++) {
      ima_on_arr_20 = iMAOnArray(g_ibuf_176, 0, MathFloor(MathSqrt(SignalPeriod)), 0, g_ma_method_88, li_4);
      li_unused_28 = 0;
      if (ima_on_arr_20 > ima_on_arr_12) {
         g_ibuf_172[li_4 - 1] = ima_on_arr_12 - gi_108 * Point;
         li_unused_28 = 1;
      } else {
         if (ima_on_arr_20 < ima_on_arr_12) {
            g_ibuf_164[li_4 - 1] = ima_on_arr_12 + gi_108 * Point;
            li_unused_28 = 2;
         } else {
            g_ibuf_164[li_4 - 1] = EMPTY_VALUE;
            g_ibuf_168[li_4 - 1] = ima_on_arr_12;
            g_ibuf_172[li_4 - 1] = EMPTY_VALUE;
            li_unused_28 = 3;
         }
      }
      if (ind_counted_8 > 0) {
      }
      ima_on_arr_12 = ima_on_arr_20;
   }
   if (li_0 > gi_112) li_0 = gi_112;
   for (li_4 = 2; li_4 <= li_0; li_4++) {
      if (g_ibuf_164[li_4 - 1] != EMPTY_VALUE) {
         if (g_ibuf_164[li_4] != EMPTY_VALUE) f0_9(li_4 - 1, li_4, 1);
         else {
            f0_9(li_4 - 1, li_4, 10);
            f0_2(li_4, g_ibuf_172[li_4], 0);
         }
      }
      if (g_ibuf_172[li_4 - 1] != EMPTY_VALUE) {
         if (g_ibuf_172[li_4] != EMPTY_VALUE) {
            f0_9(li_4 - 1, li_4, -1);
            continue;
         }
         f0_9(li_4 - 1, li_4, -10);
         f0_2(li_4, g_ibuf_164[li_4] + MathAbs(Close[li_4] - iSAR(NULL, 0, 0.02, 0.2, li_4)), 1);
      }
   }
   if (g_ibuf_172[1] != EMPTY_VALUE) f0_1(1);
   if (g_ibuf_164[1] != EMPTY_VALUE) f0_1(0);
   if (aAlerts) {
      if ((gi_116 == FALSE && g_ibuf_172[1] != EMPTY_VALUE && g_ibuf_172[2] == EMPTY_VALUE) || (gi_116 == TRUE && g_ibuf_172[1] != EMPTY_VALUE && g_ibuf_172[2] != EMPTY_VALUE &&
         g_ibuf_172[3] == EMPTY_VALUE)) f0_10("Sell signal", Close[1], f0_8(), f0_0());
      if ((gi_116 == FALSE && g_ibuf_164[1] != EMPTY_VALUE && g_ibuf_164[2] == EMPTY_VALUE) || (gi_116 == TRUE && g_ibuf_164[1] != EMPTY_VALUE && g_ibuf_164[2] != EMPTY_VALUE &&
         g_ibuf_164[3] == EMPTY_VALUE)) f0_10("Buy signal", Close[1], f0_6(), f0_5());
   }
   return (0);
}

double f0_8() {
   return (Bid - aTake_Profit * Point);
}

double f0_6() {
   return (Ask + aTake_Profit * Point);
}

double f0_0() {
   return (Bid + aStop_Loss * Point);
}

double f0_5() {
   return (Ask - aStop_Loss * Point);
}

int f0_3() {
   return (10000.0 * (SignalPeriod * Point));
}

void f0_7() {
   string name_0;
   int str_len_12;
   for (int li_8 = ObjectsTotal() - 1; li_8 >= 0; li_8--) {
      name_0 = ObjectName(li_8);
      str_len_12 = StringLen(gs_156);
      if (StringSubstr(name_0, 0, str_len_12) == gs_156) ObjectDelete(name_0);
   }
}

void f0_9(int ai_0, int ai_4, int ai_8) {
   double price_20;
   double price_28;
   color color_36;
   if (ai_8 > 0) {
      price_20 = g_ibuf_164[ai_0];
      if (ai_8 == 1) price_28 = g_ibuf_164[ai_4];
      else price_28 = g_ibuf_172[ai_4];
      color_36 = DarkTurquoise;
   } else {
      price_20 = g_ibuf_172[ai_0];
      if (ai_8 == -1) price_28 = g_ibuf_172[ai_4];
      else price_28 = g_ibuf_164[ai_4];
      color_36 = Red;
   }
   int time_12 = Time[ai_0];
   int time_16 = Time[ai_4];
   if (price_20 == EMPTY_VALUE || price_28 == EMPTY_VALUE) {
      Print("Empty value for price line encountered!");
      return;
   }
   string name_40 = gs_156 + "_segment_" + color_36 + time_12 + "_" + time_16;
   ObjectDelete(name_40);
   ObjectCreate(name_40, OBJ_TREND, 0, time_12, price_20, time_16, price_28, 0, 0);
   ObjectSet(name_40, OBJPROP_WIDTH, g_width_76);
   ObjectSet(name_40, OBJPROP_COLOR, color_36);
   ObjectSet(name_40, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(name_40, OBJPROP_RAY, FALSE);
}

void f0_2(int ai_0, double a_price_4, int ai_12) {
   string text_16 = "BUY";
   color color_24 = BuySignalColor;
   if (ai_12 == 1) {
      text_16 = "SELL";
      color_24 = SellSignalColor;
   }
   int time_28 = Time[ai_0];
   string name_32 = gs_signall_204 + DoubleToStr(time_28, 0);
   if (ObjectFind(name_32) != -1) ObjectDelete(name_32);
   ObjectCreate(name_32, OBJ_TEXT, 0, time_28, a_price_4);
   ObjectSetText(name_32, text_16, SignalTextSize);
   ObjectSet(name_32, OBJPROP_COLOR, color_24);
}

void f0_1(int ai_0) {
   string text_4 = "Current trend is: UP";
   string text_12 = "Current trading signal: BUY";
   color color_20 = BuySignalColor;
   if (ai_0 == 1) {
      text_4 = "Current trend is: DOWN";
      text_12 = "Current trading signal: SELL";
      color_20 = SellSignalColor;
   }
   if (ObjectFind(g_name_196) != -1) ObjectDelete(g_name_196);
   ObjectCreate(g_name_196, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(g_name_196, text_4, SignalTextSize);
   ObjectSet(g_name_196, OBJPROP_COLOR, color_20);
   ObjectSet(g_name_196, OBJPROP_XDISTANCE, 30);
   ObjectSet(g_name_196, OBJPROP_YDISTANCE, 30);
   string name_24 = g_name_196 + "LL";
   if (ObjectFind(name_24) != -1) ObjectDelete(name_24);
   ObjectCreate(name_24, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(name_24, text_12, SignalTextSize);
   ObjectSet(name_24, OBJPROP_COLOR, color_20);
   ObjectSet(name_24, OBJPROP_XDISTANCE, 30);
   ObjectSet(name_24, OBJPROP_YDISTANCE, InformerTextSize + 35);
}
