/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2007 Forex Trend System"
#property link      "www.forextrendsystem.com"

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 LightGray
#property indicator_color4 LightGray
#property indicator_color5 Black

extern int TPeriod = 34;
extern int TType = 3;
extern int TPrice = 0;
extern int TShift = 0;
extern bool Alerts = TRUE;
extern bool SoundON = TRUE;
extern bool EmailAlert = TRUE;
double g_ibuf_104[];
double g_ibuf_108[];
double g_ibuf_112[];
double g_ibuf_116[];
double g_ibuf_120[];
double g_ibuf_124[];
double g_ibuf_128[];
int gi_132 = 0;

int init() {
   gi_132 = TimeCurrent() - TimeCurrent() % (60 * Period()) - 60 * Period();
   SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID);
   SetIndexBuffer(0, g_ibuf_104);
   SetIndexLabel(0, NULL);
   SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID);
   SetIndexBuffer(1, g_ibuf_108);
   SetIndexLabel(1, NULL);
   SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID);
   SetIndexBuffer(2, g_ibuf_112);
   SetIndexLabel(2, NULL);
   SetIndexStyle(3, DRAW_HISTOGRAM, STYLE_SOLID);
   SetIndexBuffer(3, g_ibuf_116);
   SetIndexLabel(3, NULL);
   SetIndexStyle(4, DRAW_LINE);
   SetIndexBuffer(4, g_ibuf_120);
   SetIndexEmptyValue(4, 0.0);
   SetIndexStyle(5, DRAW_ARROW, STYLE_SOLID, 3);
   SetIndexBuffer(5, g_ibuf_124);
   SetIndexArrow(5, 234);
   SetIndexStyle(6, DRAW_ARROW, STYLE_SOLID, 3);
   SetIndexBuffer(6, g_ibuf_128);
   SetIndexArrow(6, 233);
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   double l_ima_24;
   double l_ima_32;
   double l_ima_40;
   int li_12 = IndicatorCounted();
   if (li_12 < 0) return (-1);
   if (li_12 > 0) li_12--;
   int li_16 = Bars - li_12;
   for (int li_20 = 1; li_20 < li_16 && li_20 + 2 < Bars; li_20++) {
      l_ima_24 = iMA(NULL, 0, TPeriod, TShift, TType, TPrice, li_20);
      l_ima_32 = iMA(NULL, 0, TPeriod, TShift, TType, TPrice, li_20 + 1);
      l_ima_40 = iMA(NULL, 0, TPeriod, TShift, TType, TPrice, li_20 + 2);
      g_ibuf_120[li_20] = l_ima_24;
      if (li_20 == 1) {
         if (l_ima_24 < l_ima_32 && l_ima_32 > l_ima_40) AlertMe(StringConcatenate("Short setup on ", Symbol(), " ", Period(), " min (", TimeToStr(Time[1]), ")"), 0);
         if (l_ima_24 > l_ima_32 && l_ima_32 < l_ima_40) AlertMe(StringConcatenate("Long setup on ", Symbol(), " ", Period(), " min (", TimeToStr(Time[1]), ")"), 1);
      }
      if (l_ima_24 < l_ima_32) {
         g_ibuf_104[li_20] = Low[li_20];
         g_ibuf_108[li_20] = High[li_20];
         g_ibuf_112[li_20] = Low[li_20];
         g_ibuf_116[li_20] = Low[li_20];
      } else {
         if (l_ima_24 > l_ima_32) {
            g_ibuf_104[li_20] = High[li_20];
            g_ibuf_108[li_20] = Low[li_20];
            g_ibuf_112[li_20] = Low[li_20];
            g_ibuf_116[li_20] = Low[li_20];
         }
      }
   }
   return (0);
}

void AlertMe(string as_0, bool ai_8) {
   string ls_12;
   if (gi_132 < Time[1]) {
      gi_132 = Time[1];
      if (Alerts) Alert(as_0);
      if (SoundON) {
         if (ai_8) ls_12 = "Long";
         else ls_12 = "Short";
         if (ai_8) PlaySound("ringing.wav");
         else PlaySound("ringing2.wav");
      }
      if (EmailAlert) {
         SendMail("" + ls_12 + " Trade Setup on " + Symbol() + "", "Date/Time: " + TimeToStr(TimeLocal()) 
            + "\nCurrency: " + Symbol() + " " + ls_12 + " trade setup - wait for indicators to confirm!\nPrice: " + DoubleToStr(Ask, Digits) 
         + "\nwww.forextrendsystem.com\nsupport@forextrendsystem.com");
      }
   }
}