PINE LIBRARY
已更新 lib_divergence

Library "lib_divergence"
offers a commonly usable function to detect divergences. This will take the default RSI or other symbols / indicators / oscillators as source data.
divergence(osc, pivot_left_bars, pivot_right_bars, div_min_range, div_max_range, ref_low, ref_high, min_divergence_offset_fraction, min_divergence_offset_dev_len, min_divergence_offset_atr_mul)
Detects Divergences between Price and Oscillator action. For bullish divergences, look at trend lines between lows. For bearish divergences, look at trend lines between highs. (strong) oscillator trending, price opposing it | (medium) oscillator trending, price trend flat | (weak) price opposite trending, oscillator trend flat | (hidden) price trending, oscillator opposing it. Pivot detection is only properly done in oscillator data, reference price data is only compared at the oscillator pivot (speed optimization)
Parameters:
osc (float): (series float) oscillator data (can be anything, even another instrument price)
pivot_left_bars (simple int): (simple int) optional number of bars left of a confirmed pivot point, confirming it is the highest/lowest in the range before and up to the pivot (default: 5)
pivot_right_bars (simple int): (simple int) optional number of bars right of a confirmed pivot point, confirming it is the highest/lowest in the range from and after the pivot (default: 5)
div_min_range (simple int): (simple int) optional minimum distance to the pivot point creating a divergence (default: 5)
div_max_range (simple int): (simple int) optional maximum amount of bars in a divergence (default: 50)
ref_low (float): (series float) optional reference range to compare the oscillator pivot points to. (default: low)
ref_high (float): (series float) optional reference range to compare the oscillator pivot points to. (default: high)
min_divergence_offset_fraction (simple float): (simple float) optional scaling factor for the offset zone (xDeviation) around the last oscillator H/L detecting following equal H/Ls (default: 0.01)
min_divergence_offset_dev_len (simple int): (simple int) optional lookback distance for the deviation detection for the offset zone around the last oscillator H/L detecting following equal H/Ls. Used as well for the ATR that does the equal H/L detection for the reference price. (default: 14)
min_divergence_offset_atr_mul (simple float): (simple float) optional scaling factor for the offset zone (xATR) around the last price H/L detecting following equal H/Ls (default: 1)
return A tuple of deviation flags. [strong_bull, strong_bear, medium_bull, medium_bear, weak_bull, weak_bear, hidden_bull, hidden_bear, pivot_h, pivot_l]
offers a commonly usable function to detect divergences. This will take the default RSI or other symbols / indicators / oscillators as source data.
divergence(osc, pivot_left_bars, pivot_right_bars, div_min_range, div_max_range, ref_low, ref_high, min_divergence_offset_fraction, min_divergence_offset_dev_len, min_divergence_offset_atr_mul)
Detects Divergences between Price and Oscillator action. For bullish divergences, look at trend lines between lows. For bearish divergences, look at trend lines between highs. (strong) oscillator trending, price opposing it | (medium) oscillator trending, price trend flat | (weak) price opposite trending, oscillator trend flat | (hidden) price trending, oscillator opposing it. Pivot detection is only properly done in oscillator data, reference price data is only compared at the oscillator pivot (speed optimization)
Parameters:
osc (float): (series float) oscillator data (can be anything, even another instrument price)
pivot_left_bars (simple int): (simple int) optional number of bars left of a confirmed pivot point, confirming it is the highest/lowest in the range before and up to the pivot (default: 5)
pivot_right_bars (simple int): (simple int) optional number of bars right of a confirmed pivot point, confirming it is the highest/lowest in the range from and after the pivot (default: 5)
div_min_range (simple int): (simple int) optional minimum distance to the pivot point creating a divergence (default: 5)
div_max_range (simple int): (simple int) optional maximum amount of bars in a divergence (default: 50)
ref_low (float): (series float) optional reference range to compare the oscillator pivot points to. (default: low)
ref_high (float): (series float) optional reference range to compare the oscillator pivot points to. (default: high)
min_divergence_offset_fraction (simple float): (simple float) optional scaling factor for the offset zone (xDeviation) around the last oscillator H/L detecting following equal H/Ls (default: 0.01)
min_divergence_offset_dev_len (simple int): (simple int) optional lookback distance for the deviation detection for the offset zone around the last oscillator H/L detecting following equal H/Ls. Used as well for the ATR that does the equal H/L detection for the reference price. (default: 14)
min_divergence_offset_atr_mul (simple float): (simple float) optional scaling factor for the offset zone (xATR) around the last price H/L detecting following equal H/Ls (default: 1)
return A tuple of deviation flags. [strong_bull, strong_bear, medium_bull, medium_bear, weak_bull, weak_bear, hidden_bull, hidden_bear, pivot_h, pivot_l]
發行說明
v2 improved performance, fixed bug in 'weak bear' detection, improved naming and comments for function parametersUpdated:
divergence(osc, pivot_confirmation_bars_left, pivot_confirmation_bars_right, pivot_min_x_distance, pivot_max_x_distance, ref_low, ref_high, pivot_min_y_distance_len, pivot_min_y_distance_dev_mult, pivot_min_y_distance_atr_mult)
Detects Divergences between Price and Oscillator action. For bullish divergences, look at trend lines between lows. For bearish divergences, look at trend lines between highs. (strong) oscillator trending, price opposing it | (medium) oscillator trending, price trend flat | (weak) price opposite trending, oscillator trend flat | (hidden) price trending, oscillator opposing it. Pivot detection is only properly done in oscillator data, reference price data is only compared at the oscillator pivot (speed optimization)
Parameters:
osc (float): (series float) oscillator data (can be anything, even another instrument price)
pivot_confirmation_bars_left (simple int): (simple int) optional number of bars left of a confirmed pivot point, confirming it is the highest/lowest in the range before and up to the pivot (default: 5)
pivot_confirmation_bars_right (simple int): (simple int) optional number of bars right of a confirmed pivot point, confirming it is the highest/lowest in the range from and after the pivot (default: 3)
pivot_min_x_distance (simple int): (simple int) optional minimum distance between pivot points considered for a divergence (should not be bigger than pivot_leftbars) (default: 5)
pivot_max_x_distance (simple int): (simple int) optional maximum distance between pivot points considered for a divergence (should not be bigger than pivot_leftbars) (default: 50)
ref_low (float): (series float) optional reference range to compare the oscillator pivot points to. (default: low)
ref_high (float): (series float) optional reference range to compare the oscillator pivot points to. (default: high)
pivot_min_y_distance_len (simple int): (simple int) optional lookback distance for the deviation detection for the offset zone around the last oscillator H/L when detecting following equal H/Ls. Used as well for the ATR that does the equal H/L detection for the reference price. (default: 14)
pivot_min_y_distance_dev_mult (simple float): (simple float) optional scaling factor for the offset zone (xDeviation) around the last oscillator H/L when detecting following equal H/Ls (default: 0.1)
pivot_min_y_distance_atr_mult (simple float): (simple float) optional scaling factor for the offset zone (xATR) around the last price H/L when detecting following equal H/Ls (default: 0.1)
return A tuple of deviation flags. [strong_bull, strong_bear, medium_bull, medium_bear, weak_bull, weak_bear, hidden_bull, hidden_bear, osc_pivot_h, osc_pivot_l]
Pine腳本庫
秉持 TradingView 一貫的共享精神,作者將此 Pine 程式碼發佈為開源庫,讓社群中的其他 Pine 程式設計師能夠重複使用。向作者致敬!您可以在私人專案或其他開源發佈中使用此庫,但在公開發佈中重複使用該程式碼需遵守社群規範。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
Pine腳本庫
秉持 TradingView 一貫的共享精神,作者將此 Pine 程式碼發佈為開源庫,讓社群中的其他 Pine 程式設計師能夠重複使用。向作者致敬!您可以在私人專案或其他開源發佈中使用此庫,但在公開發佈中重複使用該程式碼需遵守社群規範。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。