With zigzag indicator

 

Hi

I'm a beginner in mql programming I am trying to program my first expert I need to call zigzag Indicator and do some thing (a code) 

after zigzag set last line the expert calculate the number of bars of this line for example (image1) and do some code with this result (number of bars) also with conditions (I will do that by my self)

I try to do the expert by my self but it difficile because the zigzag indicator is complex for me, so I hope to help me to do the code and I will complete what the rest.





 
Jek So:

Hi

I'm a beginner in mql programming I am trying to program my first expert I need to call zigzag Indicator and do some thing (a code) 

after zigzag set last line the expert calculate the number of bars of this line for example (image1) and do some code with this result (number of bars) also with conditions (I will do that by my self)

I try to do the expert by my self but it difficile because the zigzag indicator is complex for me, so I hope to help me to do the code and I will complete what the rest.

#property strict

#include <ChartObjects\ChartObjectsLines.mqh>

struct   Zigs{datetime time;double price;int shift;};
MqlRates r[];

void OnStart()
{ 
   ArraySetAsSeries(r,true);
   CopyRates(Symbol(),Period(),0,Bars(Symbol(),Period()),r);
   Zigs zz[5]; //Check bars between the past 5 swings
   PrintBarsBetweenZigs(zz);
}
//+------------------------------------------------------------------+
void PrintBarsBetweenZigs(Zigs &zz[])
{
   GetZZ(zz);
   for(int i=0;i<ArraySize(zz)-1;i++)
   {
      Print("The number of bars from index[",i,"] to index[",i+1,"] is ",zz[i+1].shift - zz[i].shift," bars");
   }
}
//+------------------------------------------------------------------+
void GetZZ(Zigs &zz[])
{
   for(int i=0,cnt=0;i<ArraySize(r)&&cnt<ArraySize(zz);i++)
   {
      double val = iCustom(Symbol(),Period(),"ZigZag",50,5,3,0,i);
      if(val > 0 && val != EMPTY_VALUE)
      {
         zz[cnt].time = r[i].time;
         zz[cnt].shift = i;
         if(r[i].close < val || r[i].high == val)
            zz[cnt].price = r[i].high;
         else
            zz[cnt].price = r[i].low;
         cnt++;
      }
   }
}
//+------------------------------------------------------------------+

Reason: