To create the divergence index in Matt Storz's "Quantifying Divergence with the Divergence Index," you must first
create two User-Functions, PeakDivergence and TroughDivergence. The code for both is listed below. Be sure you
create and verify these before you build the indicator. Since I have built them as User-Functions, you can now call
these functions from any other study or system without having to recreate the code.
Inputs: Strength(NumericSimple), OSC(NumericSeries);
Vars: Hc(0), Hp(0), Hh(0), HL(0), Ic(0), Ih(0), Ip(0), IL(0);
If Value1<>-1 then begin