Please Explain Zig function

Please Explain the usage of Zig function.
Also Explain the following code. How it is working?

Sens=Param("Sens",4.75, 0.5, 15, 0.25);

BarPK=BarsSince(Zig(C,Sens)==Peak(C,Sens)); 

BarTGH= BarsSince(Zig(C,Sens)==Trough(C,Sens));

I am new to afl programming and new to trading.
Please explain above code in details.

Google is your friend, use it.

See:
http://www.amibroker.com/guide/afl/zig.html


https://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:zigzag

Generally, Zig function looks into the future and can NOT be directly used in trading system UNLESS you wait for last leg to stabilize. Traders' Tips article shows how to do that
http://traders.com/Documentation/FEEDbk_docs/2003/11/TradersTips/TradersTips.html#amibroker