Navigation:Home > Content >

ZigZag_with_alerts~.mq4

Time: 2012-11-23 | Download file:ZigZag_with_alerts~.mq4

#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red

extern int ExtDepth = 12;
extern int ExtDeviation = 5;
extern int ExtBackstep = 3;
extern bool alerts_On = FALSE;
extern bool alerts_Message = TRUE;
extern bool alerts_Sound = FALSE;
extern bool alerts_Email = FALSE;
double G_ibuf_104[];
double G_ibuf_108[];
string Gs_nothing_112 = "nothing";
int Gi_120;

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   IndicatorBuffers(2);
   SetIndexStyle(0, DRAW_SECTION);
   SetIndexBuffer(0, G_ibuf_104);
   SetIndexBuffer(1, G_ibuf_108);
   SetIndexEmptyValue(0, 0.0);
   IndicatorShortName("ZigZag(" + ExtDepth + "," + ExtDeviation + "," + ExtBackstep + ")");
   return (0);
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   double Ld_16;
   double Ld_24;
   double Ld_32;
   double Ld_40;
   double Ld_48;
   double Ld_56;
   bool Li_64;
   int Li_unused_68;
   bool Li_72;
   int Li_76;
   for (int Li_0 = Bars - ExtDepth; Li_0 >= 0; Li_0--) {
      Ld_16 = Low[iLowest(NULL, 0, MODE_LOW, ExtDepth, Li_0)];
      if (Ld_16 == Ld_56) Ld_16 = 0.0;
      else {
         Ld_56 = Ld_16;
         if (Low[Li_0] - Ld_16 > ExtDeviation * Point) Ld_16 = 0.0;
         else {
            for (int Li_4 = 1; Li_4 <= ExtBackstep; Li_4++) {
               Ld_24 = G_ibuf_104[Li_0 + Li_4];
               if (Ld_24 != 0.0 && Ld_24 > Ld_16) G_ibuf_104[Li_0 + Li_4] = 0.0;
            }
         }
      }
      G_ibuf_104[Li_0] = Ld_16;
      Ld_16 = High[iHighest(NULL, 0, MODE_HIGH, ExtDepth, Li_0)];
      if (Ld_16 == Ld_48) Ld_16 = 0.0;
      else {
         Ld_48 = Ld_16;
         if (Ld_16 - High[Li_0] > ExtDeviation * Point) Ld_16 = 0.0;
         else {
            for (Li_4 = 1; Li_4 <= ExtBackstep; Li_4++) {
               Ld_24 = G_ibuf_108[Li_0 + Li_4];
               if (Ld_24 != 0.0 && Ld_24 < Ld_16) G_ibuf_108[Li_0 + Li_4] = 0.0;
            }
         }
      }
      G_ibuf_108[Li_0] = Ld_16;
   }
   Ld_48 = -1;
   int Li_8 = -1;
   Ld_56 = -1;
   int Li_12 = -1;
   for (Li_0 = Bars - ExtDepth; Li_0 >= 0; Li_0--) {
      Ld_32 = G_ibuf_104[Li_0];
      Ld_40 = G_ibuf_108[Li_0];
      if (Ld_32 == 0.0 && Ld_40 == 0.0) continue;
      if (Ld_40 != 0.0) {
         if (Ld_48 > 0.0) {
            if (Ld_48 < Ld_40) G_ibuf_108[Li_8] = 0;
            else G_ibuf_108[Li_0] = 0;
         }
         if (Ld_48 < Ld_40 || Ld_48 < 0.0) {
            Ld_48 = Ld_40;
            Li_8 = Li_0;
         }
         Ld_56 = -1;
      }
      if (Ld_32 != 0.0) {
         if (Ld_56 > 0.0) {
            if (Ld_56 > Ld_32) G_ibuf_104[Li_12] = 0;
            else G_ibuf_104[Li_0] = 0;
         }
         if (Ld_32 < Ld_56 || Ld_56 < 0.0) {
            Ld_56 = Ld_32;
            Li_12 = Li_0;
         }
         Ld_48 = -1;
      }
   }
   for (Li_0 = Bars - 1; Li_0 >= 0; Li_0--) {
      if (Li_0 >= Bars - ExtDepth) G_ibuf_104[Li_0] = 0.0;
      else {
         Ld_24 = G_ibuf_108[Li_0];
         if (Ld_24 != 0.0) G_ibuf_104[Li_0] = Ld_24;
      }
   }
   if (alerts_On) {
      Li_64 = FALSE;
      Li_unused_68 = 0;
      Li_72 = FALSE;
      Li_76 = 0;
      for (Li_0 = 0; Li_0 < Bars; Li_0++) {
         if (G_ibuf_104[Li_0] != 0.0) {
            Li_76 = Li_0;
            Li_64 = TRUE;
            break;
         }
      }
      if (Li_64) {
         for (Li_0++; Li_0 < Bars; Li_0++) {
            if (G_ibuf_104[Li_0] != 0.0) {
               if (G_ibuf_104[Li_0] >= G_ibuf_104[Li_76]) break;
               Li_72 = TRUE;
               break;
            }
         }
      }
      if (Li_64) {
         if (Li_72) f0_0("ZigZag made a new upper peak at " + TimeToStr(Time[Li_76], TIME_DATE|TIME_SECONDS), Time[Li_76]);
         else f0_0("ZigZag made a new lower peak at " + TimeToStr(Time[Li_76], TIME_DATE|TIME_SECONDS), Time[Li_76]);
      }
   }
   return (0);
}

// DA717D55A7C333716E8D000540764674
void f0_0(string As_0, int Ai_8) {
   string str_concat_12;
   if (Gs_nothing_112 != As_0 || Gi_120 != Ai_8) {
      Gs_nothing_112 = As_0;
      Gi_120 = Ai_8;
      str_concat_12 = StringConcatenate(Symbol(), " at ", TimeToStr(TimeLocal(), TIME_SECONDS), " ZigZag : ", As_0);
      if (alerts_Message) Alert(str_concat_12);
      if (alerts_Email) SendMail("ZigZag : ", str_concat_12);
      if (alerts_Sound) PlaySound("alert2.wav");
   }
}

Recommend