/*
   Generated by EX4-TO-MQ4 decompiler V4.0.220.2c []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright � 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_levelcolor Red
#property indicator_levelstyle 0
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 CLR_NONE
#property indicator_color3 Black
#property indicator_width1 2
#property indicator_level1 50.0

double g_ibuf_76[];
double g_ibuf_80[];
double g_ibuf_84[];
double g_ibuf_88[];
double g_ibuf_92[];
double g_ibuf_96[];
double g_ibuf_100[];
double g_ibuf_104[];
extern int Smoothing = 5;
extern int TimeFrame = 0;
extern string ALERTS = "------------------------------------------------------";
extern bool CrossFiftyAlert = FALSE;
extern bool CrossFiftyEmail = FALSE;
extern bool CrossLineAlert = FALSE;
extern bool CrossLineEmail = FALSE;
extern bool BothAlert = FALSE;
extern bool BothEmail = FALSE;
extern string MESSAGES = "------------------------------------------------------";
extern string FiftyUpMessage = "QQE Crossed 50 Line UP !!!";
extern string FiftyDownMessage = "QQE Crossed 50 Line DOWN !!!";
extern string QQECrossUpMessage = "QQE Lines Crossed UP !!!";
extern string QQECrossDownMessage = "QQE Lines Crossed DOWN !!!";
extern string BothUpMessage = "QQE Lines Are Crossed and 50 Line Broken UP !!!";
extern string BothDownMessage = "QQE Lines Are Crossed and 50 Line Broken DOWN !!!";
extern string SOUNDS = "------------------------------------------------------";
extern string FiftyUpSound = "alert.wav";
extern string FiftyDownSound = "alert.wav";
extern string QQECrossUpSound = "alert.wav";
extern string QQECrossDownSound = "alert.wav";
extern string BothUpSound = "alert.wav";
extern string BothDownSound = "alert.wav";
extern string DOT_VISIBILITY = "------------------------------------------------------";
extern bool FiftyUpDot = FALSE;
extern bool FiftyDownDot = FALSE;
extern bool QQECrossUpDot = FALSE;
extern bool QQECrossDownDot = FALSE;
extern bool BothUpDot = FALSE;
extern bool BothDownDot = FALSE;
extern string DOT_COLORS = "------------------------------------------------------";
extern color FiftyUpColor = DodgerBlue;
extern color FiftyDownColor = Crimson;
extern color QQECrossUpColor = Teal;
extern color QQECrossDownColor = Pink;
extern color BothUpColor = Blue;
extern color BothDownColor = Red;
extern string DOT_DISTANCE = "------------------------------------------------------";
extern int Distance = 30;
int gi_unused_336 = 0;
int gi_unused_340 = 0;
int gi_344 = 0;

int init() {
   string ls_unused_8;
   string ls_20;
   IndicatorBuffers(8);
   SetIndexBuffer(0, g_ibuf_80);
   SetIndexBuffer(1, g_ibuf_84);
   SetIndexBuffer(2, g_ibuf_88);
   SetIndexBuffer(3, g_ibuf_76);
   SetIndexBuffer(4, g_ibuf_92);
   SetIndexBuffer(5, g_ibuf_96);
   SetIndexBuffer(6, g_ibuf_100);
   SetIndexBuffer(7, g_ibuf_104);
   switch (TimeFrame) {
   case 1:
      ls_20 = "Period_M1";
      break;
   case 5:
      ls_20 = "Period_M5";
      break;
   case 15:
      ls_20 = "Period_M15";
      break;
   case 30:
      ls_20 = "Period_M30";
      break;
   case 60:
      ls_20 = "Period_H1";
      break;
   case 240:
      ls_20 = "Period_H4";
      break;
   case 1440:
      ls_20 = "Period_D1";
      break;
   case 10080:
      ls_20 = "Period_W1";
      break;
   case 43200:
      ls_20 = "Period_MN1";
      break;
   default:
      ls_20 = "Current Timeframe";
   }
   MathSrand(TimeLocal());
   string ls_0 = "QQE " + ls_20;
   IndicatorShortName(ls_0);
   return (0);
}

int deinit() {
   string l_name_4;
   for (int li_0 = 32768; li_0 > 0; li_0--) {
      l_name_4 = "QQE-" + li_0;
      ObjectDelete(l_name_4);
   }
   return (0);
}

int start() {
   int lia_20[];
   double ld_28;
   double ld_36;
   int li_44;
   string l_name_48;
   int li_0 = IndicatorCounted();
   if (li_0 < 0) return (-1);
   if (li_0 > 0) li_0--;
   int li_24 = Bars - li_0;
   int li_unused_12 = Smoothing;
   ArrayCopySeries(lia_20, 5, Symbol(), TimeFrame);
   int li_4 = 0;
   int li_8 = 0;
   while (li_4 < li_24) {
      if (Time[li_4] < lia_20[li_8]) li_8++;
      g_ibuf_76[li_4] = iRSI(NULL, TimeFrame, 14, PRICE_CLOSE, li_8);
      li_4++;
   }
   li_4 = 0;
   li_8 = 0;
   while (li_4 < li_24) {
      if (Time[li_4] < lia_20[li_8]) li_8++;
      g_ibuf_80[li_8] = iMAOnArray(g_ibuf_76, 0, Smoothing, 0, MODE_EMA, li_8);
      li_4++;
   }
   for (li_4 = 0; li_4 < li_24; li_4++) {
      ld_28 = MathMax(g_ibuf_80[li_4 + 1], g_ibuf_80[li_4]);
      ld_36 = MathMin(g_ibuf_80[li_4 + 1], g_ibuf_80[li_4]);
      g_ibuf_96[li_4] = ld_28 - ld_36;
   }
   for (li_4 = 0; li_4 < li_24; li_4++) g_ibuf_92[li_4] = iMAOnArray(g_ibuf_96, 0, 27, 0, MODE_EMA, li_4);
   for (li_4 = 0; li_4 < li_24; li_4++) g_ibuf_100[li_4] = 2.618 * iMAOnArray(g_ibuf_92, 0, 27, 0, MODE_EMA, li_4);
   for (li_4 = li_24; li_4 >= 0; li_4--) {
      if (g_ibuf_80[li_4] == g_ibuf_84[li_4 + 1]) g_ibuf_84[li_4] = g_ibuf_80[li_4];
      else {
         if (g_ibuf_80[li_4 + 1] < g_ibuf_84[li_4 + 1] && g_ibuf_80[li_4] < g_ibuf_84[li_4 + 1]) g_ibuf_84[li_4] = MathMin(g_ibuf_84[li_4 + 1], g_ibuf_80[li_4] + g_ibuf_100[li_4]);
         else {
            if (g_ibuf_80[li_4 + 1] > g_ibuf_84[li_4 + 1] && g_ibuf_80[li_4] > g_ibuf_84[li_4 + 1]) g_ibuf_84[li_4] = MathMax(g_ibuf_84[li_4 + 1], g_ibuf_80[li_4] - g_ibuf_100[li_4]);
            else {
               if (g_ibuf_80[li_4] > g_ibuf_84[li_4 + 1]) g_ibuf_84[li_4] = g_ibuf_80[li_4] - g_ibuf_100[li_4];
               else g_ibuf_84[li_4] = g_ibuf_80[li_4] + g_ibuf_100[li_4];
            }
         }
      }
   }
   for (li_4 = 0; li_4 < li_24; li_4++) g_ibuf_104[li_4] = 4.236 * iMAOnArray(g_ibuf_92, 0, 27, 0, MODE_EMA, li_4);
   for (li_4 = li_24; li_4 >= 0; li_4--) {
      if (g_ibuf_80[li_4] == g_ibuf_88[li_4 + 1]) g_ibuf_88[li_4] = g_ibuf_80[li_4];
      else {
         if (g_ibuf_80[li_4 + 1] < g_ibuf_88[li_4 + 1] && g_ibuf_80[li_4] < g_ibuf_88[li_4 + 1]) g_ibuf_88[li_4] = MathMin(g_ibuf_88[li_4 + 1], g_ibuf_80[li_4] + g_ibuf_104[li_4]);
         else {
            if (g_ibuf_80[li_4 + 1] > g_ibuf_88[li_4 + 1] && g_ibuf_80[li_4] > g_ibuf_88[li_4 + 1]) g_ibuf_88[li_4] = MathMax(g_ibuf_88[li_4 + 1], g_ibuf_80[li_4] - g_ibuf_104[li_4]);
            else {
               if (g_ibuf_80[li_4] > g_ibuf_88[li_4 + 1]) g_ibuf_88[li_4] = g_ibuf_80[li_4] - g_ibuf_104[li_4];
               else g_ibuf_88[li_4] = g_ibuf_80[li_4] + g_ibuf_104[li_4];
            }
         }
      }
   }
   if (gi_344 == Time[0]) return (0);
   for (li_4 = li_24 - 1; li_4 >= 0; li_4--) {
      if (g_ibuf_80[li_4 + 1] > 50.0 && g_ibuf_80[li_4 + 2] <= 50.0 && FiftyUpDot) {
         li_44 = MathRand() + 1;
         l_name_48 = "QQE-" + li_44;
         ObjectCreate(l_name_48, OBJ_ARROW, 0, Time[li_4], Low[li_4] - Distance * Point);
         ObjectSet(l_name_48, OBJPROP_COLOR, FiftyUpColor);
         ObjectSet(l_name_48, OBJPROP_ARROWCODE, 108);
      }
      if (g_ibuf_80[li_4 + 1] < 50.0 && g_ibuf_80[li_4 + 2] >= 50.0 && FiftyDownDot) {
         li_44 = MathRand() + 1;
         l_name_48 = "QQE-" + li_44;
         ObjectCreate(l_name_48, OBJ_ARROW, 0, Time[li_4], High[li_4] + Distance * Point);
         ObjectSet(l_name_48, OBJPROP_COLOR, FiftyDownColor);
         ObjectSet(l_name_48, OBJPROP_ARROWCODE, 108);
      }
      if (g_ibuf_80[li_4 + 1] > g_ibuf_88[li_4 + 1] && g_ibuf_80[li_4 + 2] < g_ibuf_88[li_4 + 2] && QQECrossUpDot) {
         li_44 = MathRand() + 1;
         l_name_48 = "QQE-" + li_44;
         ObjectCreate(l_name_48, OBJ_ARROW, 0, Time[li_4], Low[li_4] - Distance * Point);
         ObjectSet(l_name_48, OBJPROP_COLOR, QQECrossUpColor);
         ObjectSet(l_name_48, OBJPROP_ARROWCODE, 108);
      }
      if (g_ibuf_80[li_4 + 1] < g_ibuf_88[li_4 + 1] && g_ibuf_80[li_4 + 2] > g_ibuf_88[li_4 + 2] && QQECrossDownDot) {
         li_44 = MathRand() + 1;
         l_name_48 = "QQE-" + li_44;
         ObjectCreate(l_name_48, OBJ_ARROW, 0, Time[li_4], High[li_4] + Distance * Point);
         ObjectSet(l_name_48, OBJPROP_COLOR, QQECrossDownColor);
         ObjectSet(l_name_48, OBJPROP_ARROWCODE, 108);
      }
      if ((g_ibuf_80[li_4 + 1] > g_ibuf_88[li_4 + 1] && (g_ibuf_80[li_4 + 1] > 50.0 && g_ibuf_80[li_4 + 2] <= 50.0)) || (g_ibuf_80[li_4 + 1] > g_ibuf_88[li_4 + 1] && g_ibuf_80[li_4 +
         2] < g_ibuf_88[li_4 + 2] && g_ibuf_80[li_4 + 1] > 50.0) && BothUpDot) {
         li_44 = MathRand() + 1;
         l_name_48 = "QQE-" + li_44;
         ObjectCreate(l_name_48, OBJ_ARROW, 0, Time[li_4], Low[li_4] - Distance * Point);
         ObjectSet(l_name_48, OBJPROP_COLOR, BothUpColor);
         ObjectSet(l_name_48, OBJPROP_ARROWCODE, 108);
      }
      if ((g_ibuf_80[li_4 + 1] < g_ibuf_88[li_4 + 1] && (g_ibuf_80[li_4 + 1] < 50.0 && g_ibuf_80[li_4 + 2] >= 50.0)) || (g_ibuf_80[li_4 + 1] < g_ibuf_88[li_4 + 1] && g_ibuf_80[li_4 +
         2] > g_ibuf_88[li_4 + 2] && g_ibuf_80[li_4 + 1] < 50.0) && BothDownDot) {
         li_44 = MathRand() + 1;
         l_name_48 = "QQE-" + li_44;
         ObjectCreate(l_name_48, OBJ_ARROW, 0, Time[li_4], High[li_4] + Distance * Point);
         ObjectSet(l_name_48, OBJPROP_COLOR, BothDownColor);
         ObjectSet(l_name_48, OBJPROP_ARROWCODE, 108);
      }
   }
   if (g_ibuf_80[1] > 50.0 && g_ibuf_80[2] <= 50.0) {
      if (CrossFiftyAlert) {
         Print(Symbol(), " ", Period(), "M   ", FiftyUpMessage, "   @   ", Bid, " + ", Ask - Bid, " = ", Ask);
         Comment(Symbol(), " ", Period(), "M   ", FiftyUpMessage, "   @   ", Bid, " + ", Ask - Bid, " = ", Ask, 
         "\n", "TIME ON ALERT IS : ", TimeToStr(TimeCurrent()));
         PlaySound(FiftyUpSound);
      }
      if (CrossFiftyEmail) SendMail(FiftyUpMessage + Symbol(), " !!! ");
   }
   if (g_ibuf_80[1] < 50.0 && g_ibuf_80[2] >= 50.0) {
      if (CrossFiftyAlert) {
         Print(Symbol(), " ", Period(), "M   ", FiftyDownMessage, "   @   ", Bid);
         Comment(Symbol(), " ", Period(), "M   ", FiftyDownMessage, "   @   ", Bid, 
         "\n", "TIME ON ALERT IS : ", TimeToStr(TimeCurrent()));
         PlaySound(FiftyDownSound);
      }
      if (CrossFiftyEmail) SendMail(FiftyDownMessage + Symbol(), " !!! ");
   }
   if (g_ibuf_80[1] > g_ibuf_88[1] && g_ibuf_80[2] < g_ibuf_88[2]) {
      if (CrossLineAlert) {
         Print(Symbol(), " ", Period(), "M   ", QQECrossUpMessage, "   @   ", Bid, " + ", Ask - Bid, " = ", Ask);
         Comment(Symbol(), " ", Period(), "M   ", QQECrossUpMessage, "   @   ", Bid, " + ", Ask - Bid, " = ", Ask, 
         "\n", "TIME ON ALERT IS : ", TimeToStr(TimeCurrent()));
         PlaySound(QQECrossUpSound);
      }
      if (CrossLineEmail) SendMail(QQECrossUpMessage + Symbol(), " !!! ");
   }
   if (g_ibuf_80[1] < g_ibuf_88[1] && g_ibuf_80[2] > g_ibuf_88[2]) {
      if (CrossLineAlert) {
         Print(Symbol(), " ", Period(), "M   ", QQECrossDownMessage, "   @   ", Bid);
         Comment(Symbol(), " ", Period(), "M   ", QQECrossDownMessage, "   @   ", Bid, 
         "\n", "TIME ON ALERT IS : ", TimeToStr(TimeCurrent()));
         PlaySound(QQECrossDownSound);
      }
      if (CrossLineEmail) SendMail(QQECrossDownMessage + Symbol(), " !!! ");
   }
   if ((g_ibuf_80[li_4 + 1] > g_ibuf_88[1] && (g_ibuf_80[1] > 50.0 && g_ibuf_80[2] <= 50.0)) || (g_ibuf_80[1] > g_ibuf_88[li_4 + 1] && g_ibuf_80[2] < g_ibuf_88[2] && g_ibuf_80[1] > 50.0) &&
      BothUpDot) {
      if (BothAlert) {
         Print(Symbol(), " ", Period(), "M   ", BothUpMessage, "   @   ", Bid);
         Comment(Symbol(), " ", Period(), "M   ", BothUpMessage, "   @   ", Bid, 
         "\n", "TIME ON ALERT IS : ", TimeToStr(TimeCurrent()));
         PlaySound(BothUpSound);
      }
      if (BothEmail) SendMail(BothUpMessage + Symbol(), " !!! ");
   }
   if ((g_ibuf_80[1] < g_ibuf_88[1] && (g_ibuf_80[1] < 50.0 && g_ibuf_80[2] >= 50.0)) || (g_ibuf_80[1] < g_ibuf_88[1] && g_ibuf_80[2] > g_ibuf_88[2] && g_ibuf_80[1] < 50.0) &&
      BothDownDot) {
      if (BothAlert) {
         Print(Symbol(), " ", Period(), "M   ", BothDownMessage, "   @   ", Bid);
         Comment(Symbol(), " ", Period(), "M   ", BothDownMessage, "   @   ", Bid, 
         "\n", "TIME ON ALERT IS : ", TimeToStr(TimeCurrent()));
         PlaySound(BothDownSound);
      }
      if (BothEmail) SendMail(BothDownMessage + Symbol(), " !!! ");
   }
   gi_344 = Time[0];
   return (0);
}