ZigZag inflections

Hi, I know I can get arrays of zig zag peaks and troughs, but what’s the easiest way to get a single interleaved array of peaks and troughs? (it would be nice to have a function for this, something like PeakTroughs(array,change)

Thanks!

Zig() function already gives you interleaved array of peaks and troughs.

But I think Zig() gives you not only the peaks and troughs but all the interpolated values of the straight line segments connecting the peaks and troughs. I’m more looking for an array of just the interleaved peaks and troughs so you can, for example, do this:

Zig(C,5,n=1) … to get the value of the n-th peak(or trough) ago

There are about dozens of ways to get that using Zig/Peak/Trough/PeakBars/TroughBars functions. Really it is not that difficult. Three lines of code. You could easily come up with that yourself:

function PeakTrough( array, change )
{
 tb = TroughBars( array, change );
 pb = PeakBars( array, change );
 return IIf( pb < tb, Peak( array, change ), Trough( array, change ) );
}
1 Like

I was getting lost in for loops. Thanks Tomasz for a concise and clear code.