export between zigzag times

 

hi,

I've been trying to export the number of bars between every zigzag top and bottom, and while the biggest part of the output is correct, there are error values every now and then in the data, and i can't figure the problem. Can someone help please?

Function to get values:

double zigzagtime(string ccy, int tf, int i, int welke){
   double a;
   
   double swing.value[2]={0,0,0,0};
      datetime swing.date[2]={0,0,0,0};
      int found=0;
      double tmp=0;
      while(found<2){
         if(iCustom(ccy,tf,"ZigZag",12,5,3,0,i)!=0){
            swing.value[found]=iCustom(ccy,tf,"ZigZag",12,5,3,0,i);
            swing.date[found]=iTime(ccy,tf,i);
            found++;
         }
         i++;
      }
      if(welke == 1) a = -1*(iBarShift(ccy,tf,swing.date[0]) - iBarShift(ccy,tf,swing.date[1]));
      if(welke == 2) a = swing.value[0];
      if(welke == 3) a = swing.value[1];
   return(a);
}


Thanks in advance,

Simon

 

The problem with zz is the repainting part, i suggest to skip the first zigzag value..

otherwise your code seems good except that you try to initialise arrays with size 2 with 4 values..

double swing.value[2]={0,0,0,0};
Reason: