Divergence (Function)
The Divergence function identifies occurrences of divergences in two pivot high or low conditions for the bullishdivergence and the BearishDivergence functions.
A BullishDivergence is normally identified when a price (Low) makes a Pivot low that is lower than the previous Pivot low, and an oscillator (Stochastic, RSI, BollingerBands) makes a Pivot low that is higher than the previous Pivot low.
A BearishDivergence is normally identified when a price (High) makes a Pivot high that is higher than the previous Pivot high, and an oscillator (Stochastic, RSI, BollingerBands) makes a Pivot high that is lower than the previous Pivot high.
Syntax
Divergence(Price1,Price2,Strength,Length,HiLo)
Returns (Integer)
The function returns a positive one (1) if the divergence condition is found true for the current bar and returns a zero (0) if the divergence condition is not found for the current bar.
Parameters
Name | Type | Description |
Price1 | Numeric | Specifies which bar value (price, function, or formula) to use for the first pivot point. |
Price2 | Numeric | Specifies which bar value (price, function, or formula) to use for the second pivot point. |
Strength | Numeric | Sets the number of bars on either side of the pivot high point. |
Length | Numeric | Sets the maximum number of trailing bars between pivot high points. |
HiLo | Numeric | Set the type of divergence to calculate. -1 = bullish divergence, 1 = bearish divergence. |
Remarks
The input parameters Price1 and Price2 can be a bar value such as Close, High, Low, Open, or Volume. They can also be any mathematical calculation such as High + Low) / 2, or a numeric function such as RSI, Stochastic, or ADX.
Increasing the Strength input parameter will normally decrease the number of True occurrences.
Increasing the Length input parameter will normally increase the chances for True of occurrences.
The value for the Length and Strength input parameters should always be a whole number greater than 0.
The HiLo input parameter is a switch, when HiLo = -1, the bullish divergence is identified, when HiLo = 1, the bearish divergence is identified.
Example
Plots a ShowMe on the High when a bearish divergence occurs between a Pivot High and the Pivot high of the RSI oscillator on any bar, where the Pivot Strength is 2 and the Pivot Length is 20:
if Divergence(High, RSI(Close,14), 2, 20, 1) = 1 then
Plot1(High, "BearDrvg");
Reference
Wilder, Welles, Jr. New Concepts in Technical Trading Systems. Trend Research. McLeansville, NC.