You can find an example in indicators.c, look for the code of the ZigZag indicator.