Skip to main content
Version: v5

divergences

Detect regular and hidden divergences between price swings and an oscillator.

Examples​

from openbb import obb
# RSI divergences on daily SPY.
data = obb.equity.price.historical(symbol='SPY', start_date='2022-01-01', provider='yfinance').results
events = obb.technical.divergences(data=data, indicator='rsi')
obb.technical.signals.divergences(data=[{'date': '2023-01-02', 'open': 110.0, 'high': 120.0, 'low': 100.0, 'close': 115.0, 'volume': 10000.0}, {'date': '2023-01-03', 'open': 165.0, 'high': 180.0, 'low': 150.0, 'close': 172.5, 'volume': 15000.0}, {'date': '2023-01-04', 'open': 146.67, 'high': 160.0, 'low': 133.33, 'close': 153.33, 'volume': 13333.33}, {'date': '2023-01-05', 'open': 137.5, 'high': 150.0, 'low': 125.0, 'close': 143.75, 'volume': 12500.0}, {'date': '2023-01-06', 'open': 132.0, 'high': 144.0, 'low': 120.0, 'close': 138.0, 'volume': 12000.0}], indicator='rsi')

Parameters​

data: Data | DataFrame | Series | dict | list | list[DataFrame] | list[Data] | list[Series] | ndarray
OHLC price series.

indicator: str
Oscillator paired with price for divergence detection.

index: str
Default: date
Index column name in data.

indicator_length: int
Default: 14
Lookback length used inside the oscillator.

target: str
Default: close
Price column used for swings.

lookback: int
Default: 60
Number of recent bars in which to search for swing pairs.

min_swing_distance: int
Default: 5
Minimum number of bars separating two swing points. Also doubles as the half-window for local-extreme detection.


Returns​

results: list[DivergenceEvent]

Serializable results.

provider: str

Provider name.

warnings: Optional[list[Warning_]]

List of warnings.

chart: Optional[Chart]

Chart object.

extra: dict[str, Any]

Extra info.


Data​

confirmation_date: date | datetime | str
Bar of the later (confirming) swing.

prior_swing_date: date | datetime | str
Bar of the earlier swing in the pair.

kind: str
regular_bullish / regular_bearish flag reversal signals; hidden_* flag trend-continuation signals.

price_at_prior: float
Target-column price at prior_swing_date.

price_at_confirmation: float
Target-column price at confirmation_date.

indicator_at_prior: float
Oscillator value at prior_swing_date.

indicator_at_confirmation: float
Oscillator value at confirmation_date.

strength: float
0-1 score combining the relative price and indicator displacements. Higher means a wider, more emphatic divergence.