/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2005, David W. Thomas (2009, modified by Rokai)"
#property link      "e-mail: rokai@yahoo.com"

#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 DimGray
#property indicator_color4 Blue
#property indicator_color5 Red

extern int FastMAPeriod = 9;
extern int SlowMAPeriod = 26;
extern int SignalMAPeriod = 3;
extern bool GSignal = FALSE;
extern string SoundFileName = "";
double gd_100 = 0.0;
double g_ibuf_108[];
double g_ibuf_112[];
double g_ibuf_116[];
double g_ibuf_120[];
double g_ibuf_124[];
double gd_128 = 0.0;
double gd_136 = 0.0;
bool gi_144 = FALSE;
bool gi_148 = FALSE;

int init() {
   SetIndexStyle(0, DRAW_LINE, EMPTY, 1);
   SetIndexDrawBegin(0, SlowMAPeriod);
   SetIndexBuffer(0, g_ibuf_108);
   SetIndexStyle(1, DRAW_LINE, EMPTY, 1);
   SetIndexDrawBegin(1, SlowMAPeriod + SignalMAPeriod);
   SetIndexBuffer(1, g_ibuf_112);
   SetIndexStyle(2, DRAW_HISTOGRAM, EMPTY, 2);
   SetIndexDrawBegin(2, SlowMAPeriod + SignalMAPeriod);
   SetIndexBuffer(2, g_ibuf_116);
   SetIndexStyle(3, DRAW_ARROW, EMPTY, 1);
   SetIndexArrow(3, 167);
   SetIndexBuffer(3, g_ibuf_120);
   SetIndexStyle(4, DRAW_ARROW, EMPTY, 1);
   SetIndexArrow(4, 167);
   SetIndexBuffer(4, g_ibuf_124);
   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS) + 1.0);
   IndicatorShortName("Pulse MACD (" + FastMAPeriod + "," + SlowMAPeriod + "," + SignalMAPeriod + ")");
   SetIndexLabel(0, "MACD");
   SetIndexLabel(1, "MACD Signal");
   SetIndexLabel(2, "Histogram");
   SetIndexLabel(3, "Buy");
   SetIndexLabel(4, "Sell");
   gd_128 = 2.0 / (SignalMAPeriod + 1.0);
   gd_136 = 1.0 - gd_128;
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   bool l_bool_0;
   bool l_bool_4;
   double ld_8;
   double ld_16;
   int li_36 = IndicatorCounted();
   if (li_36 < 0) return (-1);
   if (li_36 > 0) li_36--;
   int li_24 = Bars - li_36;
   for (int li_28 = li_24; li_28 >= 0; li_28--) {
      g_ibuf_108[li_28] = iMA(NULL, 0, FastMAPeriod, 0, MODE_EMA, PRICE_CLOSE, li_28) - iMA(NULL, 0, SlowMAPeriod, 0, MODE_EMA, PRICE_CLOSE, li_28);
      g_ibuf_112[li_28] = gd_128 * g_ibuf_108[li_28] + gd_136 * (g_ibuf_112[li_28 + 1]);
      g_ibuf_116[li_28] = g_ibuf_108[li_28] - g_ibuf_112[li_28];
   }
   for (li_28 = 1; li_28 <= li_24; li_28++) 
      {
      ld_16 = 0;
      for (int li_32 = li_28; li_32 <= li_28 + 9; li_32++) ld_16 += MathAbs(High[li_32] - Low[li_32]);
      ld_8 = ld_16 / 10.0;
      l_bool_0 = g_ibuf_108[li_28] >= g_ibuf_112[li_28] && g_ibuf_108[li_28 + 1] <= g_ibuf_112[li_28 + 1] && g_ibuf_108[li_28 - 1] >= g_ibuf_112[li_28 - 1] && NormalizeDouble(g_ibuf_108[li_28 - 1] - (g_ibuf_108[li_28 +
         1]), 4) >= gd_100;
      l_bool_4 = g_ibuf_108[li_28] <= g_ibuf_112[li_28] && g_ibuf_108[li_28 + 1] >= g_ibuf_112[li_28 + 1] && g_ibuf_108[li_28 - 1] <= g_ibuf_112[li_28 - 1] && NormalizeDouble(g_ibuf_108[li_28 +
         1] - (g_ibuf_108[li_28 - 1]), 4) >= gd_100;
      if (l_bool_0) g_ibuf_120[li_28] = g_ibuf_112[li_28];
      else
         if (l_bool_4) g_ibuf_124[li_28] = g_ibuf_112[li_28];
      if (!gi_144 && l_bool_0) {
         gi_144 = TRUE;
         gi_148 = FALSE;
         if (li_28 < 2 && GSignal == TRUE) {
            Alert(Symbol(), " ", Period(), "M  CROSS BUY ");
            if (SoundFileName != "") PlaySound(SoundFileName);
         }
      } else {
         if (!gi_148 && l_bool_4) {
            gi_148 = TRUE;
            gi_144 = FALSE;
            if (li_28 < 2 && GSignal == TRUE) {
               g_ibuf_124[li_28] = g_ibuf_112[li_28];
               Alert(Symbol(), " ", Period(), "M   CROSS SELL ");
               if (SoundFileName != "") PlaySound(SoundFileName);
            }
         }
      }
   }
   
   return (0);
}