/*
   Generated by EX4 TO MQ4 decompile Service 
   Website: http://www.ex4Tomq4.net 
   E-mail : info@ex4Tomq4.net 
*/

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 DarkBlue
#property indicator_color2 White

extern int Dee_period = 48;
extern double Dee_change = 3.0;
int g_ma_method_88 = MODE_LWMA;
int g_applied_price_92 = PRICE_CLOSE;
extern int SL_distance_pips = 16;
extern bool Email = TRUE;
double g_ibuf_104[];
double g_ibuf_108[];
double g_ibuf_112[];
datetime g_time_116;

void f0_1(string as_0, double ad_8, double ad_16, double ad_24) {
   string ls_32;
   string ls_40;
   string ls_48;
   string ls_56;
   string ls_64;
   if (Time[0] != g_time_116) {
      g_time_116 = Time[0];
      if (ad_24 != 0.0) ls_48 = " at price " + DoubleToStr(ad_24, 4);
      else ls_48 = "";
      if (ad_8 != 0.0) ls_40 = ", TakeProfit on " + DoubleToStr(ad_8, 4);
      else ls_40 = "";
      if (ad_16 != 0.0) ls_32 = ", StopLoss on " + DoubleToStr(ad_16, 4);
      else ls_32 = "";
      Alert("ULTRAFASTPROFIT " + as_0 + ls_48 + ls_40 + ls_32 + " ", Symbol(), ", ", Period(), " minutes chart");
      ls_56 = "Alert " + as_0 + ls_48;
      ls_64 = "Alert " + as_0 + ls_48 + ls_40 + ls_32 + " " + Symbol() + ", " + Period() + " minutes chart";
      if (Email) SendMail(ls_56, ls_64);
   }
}

int init() {
   int li_0;
   if (Dee_period == 8) li_0 = 2;
   else li_0 = 4;
   IndicatorBuffers(3);
   string ls_4 = "(" + Dee_period + ")";
   SetIndexBuffer(0, g_ibuf_104);
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, li_0);
   SetIndexLabel(0, "ULTRAFASTPROFIT ");
   SetIndexBuffer(1, g_ibuf_108);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, li_0);
   SetIndexLabel(1, "ULTRAFASTPROFIT ");
   SetIndexBuffer(2, g_ibuf_112);
   ArraySetAsSeries(g_ibuf_112, TRUE);
   IndicatorShortName("Ultrafastprofit(" + Dee_period + ")");
   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS) + 1.0);
   return (0);
}

int deinit() {
   return (0);
}

double f0_0(int ai_0, int a_period_4) {
   return (iMA(NULL, 0, a_period_4, 0, g_ma_method_88, g_applied_price_92, ai_0));
}

int start() {
   double lda_20[];
   double lda_24[];
   double ld_36;
   int ind_counted_0 = IndicatorCounted();
   if (ind_counted_0 < 0) return (-1);
   int li_4 = 1;
   int period_8 = MathFloor(MathSqrt(Dee_period));
   int li_12 = MathFloor(Dee_period / Dee_change);
   int li_16 = Bars - ind_counted_0 + Dee_period;
   if (li_16 > Bars) li_16 = Bars;
   ArraySetAsSeries(lda_20, TRUE);
   ArrayResize(lda_20, li_16);
   ArraySetAsSeries(lda_24, TRUE);
   ArrayResize(lda_24, li_16);
   double ld_28 = Close[1];
   for (li_4 = 0; li_4 < li_16; li_4++) lda_20[li_4] = 2.0 * f0_0(li_4, li_12) - f0_0(li_4, Dee_period);
   for (li_4 = 0; li_4 < li_16 - Dee_period; li_4++) g_ibuf_112[li_4] = iMAOnArray(lda_20, 0, period_8, 0, g_ma_method_88, li_4);
   for (li_4 = li_16 - Dee_period; li_4 > 0; li_4--) {
      lda_24[li_4] = lda_24[li_4 + 1];
      if (g_ibuf_112[li_4] > g_ibuf_112[li_4 + 1]) lda_24[li_4] = 1;
      if (g_ibuf_112[li_4] < g_ibuf_112[li_4 + 1]) lda_24[li_4] = -1;
      if (lda_24[li_4] > 0.0) {
         g_ibuf_104[li_4] = g_ibuf_112[li_4];
         if (lda_24[li_4 + 1] < 0.0) g_ibuf_104[li_4 + 1] = g_ibuf_112[li_4 + 1];
         if (lda_24[li_4 + 1] < 0.0) {
            if (li_4 == 1) {
               ld_36 = ld_28 - SL_distance_pips * Point;
               f0_1("Buy signal", 0, ld_36, ld_28);
            }
         }
         g_ibuf_108[li_4] = EMPTY_VALUE;
      } else {
         if (lda_24[li_4] < 0.0) {
            g_ibuf_108[li_4] = g_ibuf_112[li_4];
            if (lda_24[li_4 + 1] > 0.0) g_ibuf_108[li_4 + 1] = g_ibuf_112[li_4 + 1];
            if (lda_24[li_4 + 1] > 0.0) {
               if (li_4 == 1) {
                  ld_36 = ld_28 + SL_distance_pips * Point;
                  f0_1("Sell signal", 0, ld_36, ld_28);
               }
            }
            g_ibuf_104[li_4] = EMPTY_VALUE;
         }
      }
   }
   return (0);
}
