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

#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Yellow
#property indicator_color2 Fuchsia
#property indicator_color3 Red
#property indicator_color4 White
#property indicator_color5 DarkViolet

extern int WhiteBarTrigger = 35;
extern int RedBarTrigger = 10;
extern int WavePeriod = 10;
extern int AvgPeriod = 21;
extern bool SoundAlert = FALSE;
extern bool EmailAlert = FALSE;
extern int NumberOfBarsToUse = 500;
double g_ibuf_104[];
double g_ibuf_108[];
double g_ibuf_112[];
double g_ibuf_116[];
double g_ibuf_120[];
double gda_124[];
double gda_128[];
double gda_132[];
double gda_136[];
double gda_140[];
double gda_144[];
double gda_148[];
double gda_152[];
int gi_156 = -50;
int gi_160 = 53;
int gi_164;
bool gi_unused_168 = FALSE;
bool gi_unused_172 = FALSE;
string gs_dummy_176;

int init() {
   string ls_4 = "!SuperADX";
   IndicatorShortName(ls_4);
   ArrayResize(gda_132, Bars);
   ArrayResize(gda_144, Bars);
   ArrayResize(gda_136, Bars);
   ArrayResize(gda_140, Bars);
   ArrayResize(gda_124, Bars);
   ArrayResize(gda_128, Bars);
   ArrayResize(gda_148, Bars);
   ArrayResize(gda_152, Bars);
   SetIndexBuffer(0, g_ibuf_116);
   SetIndexBuffer(1, g_ibuf_112);
   SetIndexBuffer(2, g_ibuf_108);
   SetIndexBuffer(3, g_ibuf_104);
   SetIndexBuffer(4, g_ibuf_120);
   SetIndexLabel(0, "Yellow Bar 53");
   SetIndexLabel(1, "Magenta Bar 53");
   SetIndexLabel(2, "Red Bar 53");
   SetIndexLabel(3, "White Bar 53");
   SetIndexLabel(4, "DarkViolet Bar 53");
   SetIndexEmptyValue(0, 0);
   SetIndexEmptyValue(0, 1);
   SetIndexEmptyValue(0, 2);
   SetIndexEmptyValue(0, 3);
   SetIndexEmptyValue(0, 4);
   SetIndexDrawBegin(0, 1);
   SetIndexDrawBegin(1, 1);
   SetIndexDrawBegin(2, 1);
   SetIndexDrawBegin(3, 1);
   SetIndexDrawBegin(4, 1);
   SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 4, Yellow);
   SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 4, Fuchsia);
   SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, 4, Red);
   SetIndexStyle(3, DRAW_HISTOGRAM, STYLE_SOLID, 4, White);
   SetIndexStyle(4, DRAW_HISTOGRAM, STYLE_SOLID, 4, DarkViolet);
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   double l_ima_on_arr_4;
   int li_12;
   bool li_16;
   bool l_bool_20;
   bool l_bool_24;
   double l_icustom_28 = 0;
   double l_icustom_36 = 0;
   double l_icustom_44 = 0;
   int li_0 = IndicatorCounted();
   if (li_0 < 0) return (-1);
   if (li_0 > 0) li_0--;
   if (NumberOfBarsToUse == 0) li_12 = Bars - 1;
   else li_12 = NumberOfBarsToUse;
   for (int li_52 = li_12; li_52 > 0; li_52--) {
      gda_132[li_52] = iMA(NULL, 0, WavePeriod, 0, MODE_EMA, PRICE_TYPICAL, li_52);
      ArraySetAsSeries(gda_132, TRUE);
   }
   for (li_52 = li_12; li_52 > 0; li_52--) {
      gda_144[li_52] = MathAbs((iHigh(NULL, 0, li_52) + iClose(NULL, 0, li_52) + iLow(NULL, 0, li_52)) / 3.0 - gda_132[li_52]);
      ArraySetAsSeries(gda_144, TRUE);
   }
   for (li_52 = li_12; li_52 > 0; li_52--) {
      l_ima_on_arr_4 = iMAOnArray(gda_144, 0, WavePeriod, 0, MODE_EMA, li_52);
      gda_136[li_52] = l_ima_on_arr_4;
      ArraySetAsSeries(gda_136, TRUE);
   }
   for (li_52 = li_12; li_52 > 0; li_52--) {
      if (gda_136[li_52] > 0.0) gda_140[li_52] = ((iHigh(NULL, 0, li_52) + iClose(NULL, 0, li_52) + iLow(NULL, 0, li_52)) / 3.0 - gda_132[li_52]) / (0.015 * gda_136[li_52]);
      else gda_140[li_52] = 0;
      ArraySetAsSeries(gda_140, TRUE);
   }
   for (li_52 = li_12; li_52 > 0; li_52--) {
      l_ima_on_arr_4 = iMAOnArray(gda_140, 0, AvgPeriod, 0, MODE_EMA, li_52);
      gda_124[li_52] = l_ima_on_arr_4;
      ArraySetAsSeries(gda_124, TRUE);
   }
   for (li_52 = li_12; li_52 > 0; li_52--) {
      l_ima_on_arr_4 = iMAOnArray(gda_124, 0, 4, 0, MODE_SMA, li_52);
      gda_128[li_52] = l_ima_on_arr_4;
      ArraySetAsSeries(gda_128, TRUE);
   }
   for (li_52 = li_12 - 1; li_52 > 0; li_52--) {
      if (gda_124[li_52] >= gda_128[li_52] && gda_124[li_52 + 1] <= gda_128[li_52 + 1] && gda_124[li_52] <= gi_156) gda_148[li_52] = 1;
      else gda_148[li_52] = 0;
      if (gda_124[li_52] <= gda_128[li_52] && gda_124[li_52 + 1] >= gda_128[li_52 + 1] && gda_124[li_52] >= gi_160) gda_152[li_52] = 1;
      else gda_152[li_52] = 0;
   }
   for (li_52 = li_12 - 2; li_52 > 0; li_52--) {
      l_icustom_28 = iCustom(NULL, 0, "!SupportingADX", 14, NumberOfBarsToUse, 0, li_52);
      l_icustom_36 = iCustom(NULL, 0, "!SupportingADX", 14, NumberOfBarsToUse, 0, li_52 + 1);
      l_icustom_44 = iCustom(NULL, 0, "!SupportingADX", 14, NumberOfBarsToUse, 0, li_52 + 2);
      li_16 = MACDSignal(li_52);
      l_bool_20 = l_icustom_36 > WhiteBarTrigger && l_icustom_28 < l_icustom_36 && l_icustom_36 > l_icustom_44;
      l_bool_24 = l_icustom_28 < RedBarTrigger && l_icustom_28 > l_icustom_36 && l_icustom_36 < l_icustom_44;
      g_ibuf_104[li_52] = 0;
      g_ibuf_112[li_52] = 0;
      g_ibuf_120[li_52] = 0;
      g_ibuf_116[li_52] = 0;
      if (l_bool_20 && gda_148[li_52] != 0.0 || gda_152[li_52] != 0.0) {
         g_ibuf_116[li_52] = 2.5 * l_icustom_28;
         if (li_52 == 1) SendAlert("yb");
      }
      if (l_bool_20) {
         if (li_16) {
            g_ibuf_120[li_52] = 1.5 * l_icustom_28;
            if (li_52 == 1) SendAlert("wbmacd");
         } else {
            g_ibuf_104[li_52] = 1.5 * l_icustom_28;
            if (li_52 == 1) SendAlert("wb");
         }
      }
      if (ThreeBars(li_52) && l_bool_20) {
         g_ibuf_112[li_52] = 2.0 * l_icustom_28;
         if (li_52 == 1) SendAlert("tb");
      }
      if (l_bool_24) {
         g_ibuf_108[li_52] = 2.0 * l_icustom_28;
         if (li_52 == 1) SendAlert("rb");
      } else g_ibuf_108[li_52] = 0;
   }
   return (0);
}

int MACDSignal(int ai_0) {
   double l_icustom_4 = iCustom(Symbol(), 0, "!SupportingMACD", 12, 26, 9, 0, ai_0);
   double l_icustom_12 = iCustom(Symbol(), 0, "!SupportingMACD", 12, 26, 9, 0, ai_0 + 1);
   double l_icustom_20 = iCustom(Symbol(), 0, "!SupportingMACD", 12, 26, 9, 1, ai_0);
   double l_icustom_28 = iCustom(Symbol(), 0, "!SupportingMACD", 12, 26, 9, 1, ai_0 + 1);
   if (l_icustom_4 > l_icustom_20 && l_icustom_12 <= l_icustom_28) return (1);
   if (l_icustom_4 < l_icustom_20 && l_icustom_12 >= l_icustom_28) return (1);
   return (0);
}

int ThreeBars(int ai_0) {
   int l_count_4 = 0;
   for (int l_count_8 = 0; l_count_8 < 16; l_count_8++)
      if (g_ibuf_104[ai_0 + l_count_8] != 0.0 || g_ibuf_120[ai_0 + l_count_8] != 0.0) l_count_4++;
   if (l_count_4 > 2) return (1);
   return (0);
}

void SendAlert(string as_0) {
   if (Time[1] != gi_164) {
      if (SoundAlert) {
         if (as_0 == "wb") Alert(Symbol() + " => TF: " + Period() + "M => " + TimeToStr(TimeCurrent()) + " white bar");
         if (as_0 == "wbmacd") Alert(Symbol() + " => TF: " + Period() + "M => " + TimeToStr(TimeCurrent()) + " white bar + macd");
         if (as_0 == "rb") Alert(Symbol() + " => TF: " + Period() + "M => " + TimeToStr(TimeCurrent()) + " red bar");
         if (as_0 == "tb") Alert(Symbol() + " => TF: " + Period() + "M => " + TimeToStr(TimeCurrent()) + " three bars");
         if (as_0 == "yb") Alert(Symbol() + " => TF: " + Period() + "M => " + TimeToStr(TimeCurrent()) + " whitebar + trendwave");
      }
      if (EmailAlert) {
         if (as_0 == "wb") SendMail("!SuperADX Alert", Symbol() + " => TF: " + Period() + "M => " + TimeToStr(TimeCurrent()) + " white bar");
         if (as_0 == "wbmacd") SendMail("!SuperADX Alert", Symbol() + " => TF: " + Period() + "M => " + TimeToStr(TimeCurrent()) + " white bar + macd");
         if (as_0 == "rb") SendMail("!SuperADX Alert", Symbol() + " => TF: " + Period() + "M => " + TimeToStr(TimeCurrent()) + " red bar");
         if (as_0 == "tb") SendMail("!SuperADX Alert", Symbol() + " => TF: " + Period() + "M => " + TimeToStr(TimeCurrent()) + " three bars");
         if (as_0 == "yb") SendMail("!SuperADX Alert", Symbol() + " => TF: " + Period() + "M => " + TimeToStr(TimeCurrent()) + " whitebar + trendwave");
      }
      gi_164 = Time[1];
   }
}
