Navigation:Home > Content >

ZigZag_AleksD.mq4

Time: 2014-01-28 | Download file:ZigZag_AleksD.mq4

//+------------------------------------------------------------------+
//|                                                ZigZag_AleksD.mq4 |
//|                                         Copyright © 2008, AleksD |
//|                                                 http://ideal.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, AleksD"
#property link      "http://ideal.com"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red

extern int       History=120;
extern int       Speed=6;

double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(0,DRAW_SECTION);
   SetIndexBuffer(0,ExtMapBuffer1);
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int Swing,Swing_n,i,zu,zd;
   double LL,HH,BH,BL; 

   for (i=History;i>=0;i--)
   { 
      LL=Low[iLowest(NULL,0,MODE_LOW,Speed,i+1)];
      HH=High[iHighest(NULL,0,MODE_HIGH,Speed,i+1)];
      if (Low[i]HH) { Swing=2; if (Swing_n==1) zu=i+1; if (Swing_n==-1) zd=i+1; }
      else {  if (Low[i]HH) Swing=1; }

      if (Swing!=Swing_n && Swing_n!=0)
      {
         if (Swing==2) { Swing=-Swing_n; BH = High[i]; BL = Low[i]; }
         if (Swing==1) ExtMapBuffer1[zd]=BL;
         if (Swing==-1) ExtMapBuffer1[zu]=BH;
         BH = High[i];
         BL = Low[i]; 
      }
      if (Swing==1)
      {
         if (High[i]>=BH) { BH=High[i]; zu=i; }
      } 
      if (Swing==-1)
      {
         if (Low[i]<=BL) { BL=Low[i]; zd=i; }
      } 
      Swing_n=Swing;
   } 
   return(0);
}
//+------------------------------------------------------------------+

Recommend