The divergences code is not using the zero line, to find peaks and troughs, it uses the crosses of the oscillator with a moving average, a smart way to avoid loops and arrays by storing these crosses into variables. If a cross occurs it means that the oscillator is returning to its mean (the center of the oscillator) and forming a new highest high or lowest low.