v5
Added chk_prev_bar flag as an argument to the divergence checks, which will check for divergence using the indicator value from the prior bar. This is necessary in some cases where the indicator is using a different price source than the one passed into the divergence function.
Updated:
div_bull(pS, iS, chk_prev_bar, cp_length_after, cp_length_before, pivot_length, lookback, lookback_pivs, no_broken, pW, iW, hidW, regW)
Test for bullish divergence
Parameters:
pS: Price series (float)
iS: Indicator series (float)
chk_prev_bar: Flag to check for divergence using the indicator value from the prior bar. This is necessary in some cases where the indicator is using a different price source than the one passed in pS.
cp_length_after: Bars after current (divergent) pivot low to be considered a valid pivot (optional int)
cp_length_before: Bars before current (divergent) pivot low to be considered a valid pivot (optional int)
pivot_length: Bars before and after prior pivot low to be considered valid pivot (optional int)
lookback: Bars back to search for prior pivot low (optional int)
lookback_pivs: Pivots back to search for prior pivot low (optional int)
no_broken: Flag to only consider divergence valid if the pivot-to-pivot trendline is unbroken (optional bool)
pW: Weight of change in price, used in degree of divergence calculation (optional float)
iW: Weight of change in indicator, used in degree of divergence calculation (optional float)
hidW: Weight of hidden divergence, used in degree of divergence calculation (optional float)
regW: Weight of regular divergence, used in degree of divergence calculation (optional float)
Returns: [flag,degree,type,lx1,ly1,lx2,ly2]
flag = true if divergence exists (bool)
degree = degree (strength) of divergence (float)
type = 1 = regular, 2 = hidden (int)
lx1 = x coordinate 1 (int)
ly1 = y coordinate 1 (float)
lx2 = x coordinate 2 (int)
ly2 = y coordinate 2 (float)
div_bear(pS, iS, chk_prev_bar, cp_length_after, cp_length_before, pivot_length, lookback, lookback_pivs, no_broken, pW, iW, hidW, regW)
Test for bearish divergence
Parameters:
pS: Price series (float)
iS: Indicator series (float)
chk_prev_bar: Flag to check for divergence using the indicator value from the prior bar. This is necessary in some cases where the indicator is using a different price source than the one passed in pS.
cp_length_after: Bars after current (divergent) pivot high to be considered a valid pivot (optional int)
cp_length_before: Bars before current (divergent) pivot highto be considered a valid pivot (optional int)
pivot_length: Bars before and after prior pivot high to be considered valid pivot (optional int)
lookback: Bars back to search for prior pivot high (optional int)
lookback_pivs: Pivots back to search for prior pivot high (optional int)
no_broken: Flag to only consider divergence valid if the pivot-to-pivot trendline is unbroken (optional bool)
pW: Weight of change in price, used in degree of divergence calculation (optional float)
iW: Weight of change in indicator, used in degree of divergence calculation (optional float)
hidW: Weight of hidden divergence, used in degree of divergence calculation (optional float)
regW: Weight of regular divergence, used in degree of divergence calculation (optional float)
Returns: [flag,degree,type,lx1,ly1,lx2,ly2]
flag = true if divergence exists (bool)
degree = degree (strength) of divergence (float)
type = 1 = regular, 2 = hidden (int)
lx1 = x coordinate 1 (int)
ly1 = y coordinate 1 (float)
lx2 = x coordinate 2 (int)
ly2 = y coordinate 2 (float)