Get values from Zigzag indicator - performance issue 16

Hello,

I want to get calculated values from the Zigzag indicator.

My code looks like this:

bool GetZigZagValues(double &get_values[],datetime &get_times[],int handle)
{
double values[];         // An array for the values of the zigzag
datetime times[];        // An array to get time
int size=10000;            // Size of the array
int n=20;
ResetLastError();
//--- Copy the last 100 values of the indicator
int copied=CopyBuffer(handle,0,0,size,values);
//--- Check the number of values copied
if(copied<size)
{
PrintFormat("%s: Failed to copy %d values of the indicator with the handle=%d. Error code %d",
__FUNCTION__,size,handle,GetLastError());
return false;
}
//--- Define the order of access to the arrays as in a timeseries
ArraySetAsSeries(times,true);   ArraySetAsSeries(get_times,true);
if(CopyTime(_Symbol,_Period,0,size,times)<=0)
{
PrintFormat("%s: Failed to copy %d values from CopyTime(). Error code %d",
__FUNCTION__,size,GetLastError());
return false;
}
//--- Define the order of access to the array as in a timeseries
ArraySetAsSeries(values,true);
//--- Write here the numbers of bars, in which fractures were found
int positions[];
//--- Set array sizes
ArrayResize(get_values,n); ArrayResize(get_times,n); ArrayResize(positions,n);
//--- Counters
int i=0,k=0;
//--- Start to search for fractures
while(k<n)
{
double v=values[i];
//--- We are not interested in empty values
if(v!=0.0)
{
//--- Remember the bar number
positions[k]=i;
//--- Remember the value of a zigzag on the fracture
get_values[k]=values[i];
get_times[k]=times[i];
PrintFormat("%s: Zigzag[%d]=%G",__FUNCTION__,i,values[i]);
//--- Increase the counter
k++;
}
i++;
}
//--- Successful
return true;
}

Now my problem is that the copy operation causes bad performance, because the method will be called in the OnTick() method.

Furthermore, I am dependent on the size variable, because I might not get X zig zag values from Y bars, which will cause an ArrayOutOfBound exception.

Any ideas how I can make this more dynamic (without the size variable) and faster? 6046

int found;
int i;
double zz;
int ExtDepth =12
int ExtDeviation = 5;
int ExtBackstep =5;
double ZZ;

while(found<10)
{
if(i > Bars - 1) break;

zz = iCustom(Symbol(),Period(),"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0,i);
if( zz != 0)
{
ZZ[found] = zz;
found++;
}
i++;
}

Put last 10 zz into array. Maybe that helps.