Zig Zag Time?

 
Dear community,

After publishing couple of times, here I am asking for a suggestion! :-)
I am working on an indicator based on the ZigZag, but in order to draw some nice rectangles, I should need the time at wich the maximum/minimum has been created.

I am able to get the ZigZag values through this function

double getExtreme(int ne)
{
   int k=iBars(Symbol(),0);
   int ke=0;
   for (int i=0; i<k; i++)
   {double zz=iCustom(Symbol(), 0, "ZigZag",ZigZagDepth,ZigZagDeviation,ZigZagBackStep, 0, i);
    if (zz!=0) {ke++; if (ke>ne) return(zz);}
   }
} 
However, to calculate the time I am just using this function:
int getTime(double value, int start, string type)
{
   for(int x=start;x<999;x++)
      {if(Low[x]==value && type=="Valley"){return(x);}
       if(High[x]==value && type=="Peak"){return(x);} 
      }
   return (Time[0]);
}
In which the caller specifies whether he is looking for time of a peak of valley.

Is there a more elegant approach to this??
Thanks!! :-)

David
Reason: