ZigZag_Real_Sep





//+------------------------------------------------------------------+
//|                                             ZigZag_Real_Sep.mq4  |
//|                                                                  |
//+------------------------------------------------------------------+


#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Green
#property indicator_color2 Blue
#property indicator_color3 Red

//---- input parameters
extern bool Alert_message = true;
extern int Length=6;
extern int CountBars=300;
//---- buffers

double LL,HH,BH,BL,NH,NL;

double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
double AlertTime=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   IndicatorBuffers(4);
   SetIndexBuffer(0, Buffer1);
   SetIndexStyle(0,DRAW_SECTION);
   SetIndexBuffer(1, Buffer2);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,233);
   SetIndexBuffer(2, Buffer3);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,234);
   SetIndexBuffer(3, Buffer4);
//---- name for DataWindow and indicator subwindow label
   //short_name="";
   //IndicatorShortName(short_name);
   //SetIndexLabel(0,short_name);
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| z                                                       |
//+------------------------------------------------------------------+
int start()
  {
   if (CountBars>Bars) CountBars=Bars;
   SetIndexDrawBegin(0,Bars-CountBars+1);
   SetIndexDrawBegin(1,Bars-CountBars+1);
   int shift,i,Swing_n,Swing,uzl,zu,zd,counted_bars=IndicatorCounted();
   int a,b;
   
   if(Bars<=CountBars-1) return(0);

//---- initial zero
//   if(counted_bars<1)
//      for(i=1;i<=SMA_Period;i++) MomBuffer[Bars-i]=0.0;
//----
   Swing_n=0;Swing=0;//uzl=0;
   BH =High[CountBars];BL=Low[CountBars];zu=CountBars;zd=CountBars; 
   shift=CountBars-1;
//   if(counted_bars>=SMA_Period) i=Bars-counted_bars-1;
   while(shift>=0)
     {
     
     
LL=10000000;HH=-100000000;
for (i=shift+Length ; i>=shift+1; i--)

{ 
if (Low[i]<LL) LL=Low[i];
if (High[i]>HH) HH=High[i];
}



if ((Low[shift]<LL) && (High[shift]>HH))
{ 
Swing=2; 
if (Swing_n==1) zu=shift+1;
if (Swing_n==-1) zd=shift+1;
} 
else 
{ 
if (Low[shift]<LL) Swing=-1;
if (High[shift]>HH) Swing=1;
}

if ((Swing != Swing_n) && (Swing_n != 0))
{ 
if (Swing==2) {Swing=-Swing_n;BH = High[shift];BL = Low[shift];}

if (Swing == 1) {Buffer4[shift]=BL;Buffer1[zd]=BL;}
if (Swing ==- 1) {Buffer4[shift]=BH;Buffer1[zu]=BH;}

BH = High[shift];BL = Low[shift]; 
}

if (Swing == 1) { if (High[shift] >= BH) {BH=High[shift]; zu=shift;} } 
if (Swing == -1) { if (Low[shift]<=BL) {BL=Low[shift]; zd=shift;} } 
Swing_n=Swing;      
      

      shift--;
     }
     
for (i=CountBars; i>=0; i--)
{      
   Buffer2[i]=EMPTY_VALUE; Buffer3[i]=EMPTY_VALUE;
   if (Buffer4[i]>=High[i]) Buffer3[i]=Buffer4[i];
   if (Buffer4[i]<=Low [i]) Buffer2[i]=Buffer4[i];
}     
//---- Alert
     if (Alert_message==true && CurTime()>AlertTime && Buffer2[0]!=EMPTY_VALUE)
     { 
     Alert(" ",Symbol()," - ZigZag_Real(", Period(), ")  -  BUY !!!  ");
     AlertTime=CurTime() + (Period() - MathMod(TimeMinute(CurTime()), Period()))*60;
     }
     
     if (Alert_message==true && CurTime()>AlertTime && Buffer3[0]!=EMPTY_VALUE)
     { 
     Alert(" ",Symbol()," - ZigZag_Real(", Period(), ")  -  SELL !!!  ");
     AlertTime=CurTime() + (Period() - MathMod(TimeMinute(CurTime()), Period()))*60;
     }
//---- 
   return(0);
  }
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar


Indicator Curves created:


Implements a curve of type DRAW_SECTION
Implements a curve of type DRAW_ARROW

Indicators Used:



Custom Indicators Used:

Order Management characteristics:

Other Features:

It issuies visual alerts to the screen