Skip to main content

Technical Analysis

The Technical Analysis module is a toolkit for analyzing time-series data, at any resolution. The functions are a collection of formulas that fit into broad categories, and they are mostly derived from the pandas_ta library:

  • Momentum
  • Overlap (Moving Averages)
  • Trend
  • Volatility
  • Volume
  • Other (Fibonacci)

How to Use

Every SDK function also has a secondary _chart command. The table below is a brief description of each SDK function within the ta module; for simplicity, _chart has been omitted. Technical Analysis functions specific to stocks are included as a sub-module, openbb.stocks.ta.

PathCategoryDescription
openbb.ta.adVolumeAccumulation/Distribution Line
openbb.ta.adoscVolumeChaikin Oscillator
openbb.ta.adxTrendAverage Directional Movement Index
openbb.ta.aroonTrendAroon Indicator
openbb.ta.atrVolatilityAverage True Range
openbb.ta.bbandsVoaltilityBollinger Bands
openbb.ta.cciMomentumCommodity Channel Index
openbb.ta.cgMomentumCenter of Gravity
openbb.ta.clenowMomentumClenow Volatility Adjusted Momentum
openbb.ta.demarkMomentumTom Demark's Sequential Indicator (Unofficial)
openbb.ta.donchianVolatilityDonchian Channels
openbb.ta.emaOverlapExponential Moving Average
openbb.ta.fibOtherFibonacci Retracement
openbb.ta.fisherMomentumFisher Transform
openbb.ta.hmaOverlapHull Moving Average
openbb.ta.kcVolatilityKeltner Channels
openbb.ta.maOverlapMoving Averages (For Charting)
openbb.ta.macdMomentumMoving Average Convergence/Divergence
openbb.ta.obvVolumeOn-Balance Volume
openbb.ta.rsiMomentumRelative Strength Index
openbb.ta.smaOverlapSimple Moving Average
openbb.ta.stochMomentumStochastic Oscillator
openbb.ta.vwapOverlapVolume-Weighted Average Price
openbb.ta.wmaOverlapWeighted Moving Average
openbb.ta.zlmaOverlapZero-Lag Moving Average

The syntax for the data argument can be:

  • data = ohlcv_df

    Where functions only require a single column, data = ohlcv_df['Adj Close']

  • data = openbb.stocks.load("ticker")

    Target intraday by adding the interval argument to the load syntax.

Best practice is to deploy the first method because the latter will work only with the commands requiring OHLC+V data as inputs. An error message will be returned if this is the case.

openbb.ta.obv(data = openbb.stocks.load('QQQ'))
dateOBV
2019-11-15 00:00:001.84279e+07
2019-11-18 00:00:003.67938e+07
2019-11-19 00:00:005.37171e+07
2019-11-20 00:00:001.70881e+07
2022-11-15 00:00:00-1.09017e+08
2022-11-16 00:00:00-1.57876e+08
2022-11-17 00:00:00-2.13339e+08
2022-11-18 00:00:00-1.59987e+08

The error message:

openbb.ta.rsi(data = openbb.stocks.load('QQQ'))
Please send a series and not a DataFrame.

_chart

To display the chart, instead of raw data, add _chart to the syntax before the (arguments).

openbb.ta.obv_chart(data= openbb.stocks.load('QQQ', start_date = '2022-11-18', interval = 5, prepost = True))

openbb.ta.obv_chart

Examples

Import Statements

The examples here assume that this code block is at the top of the Python script of Notebook file:

import pandas as pd
from openbb_terminal.sdk import openbb
# %matplotlib inline (uncomment for Jupyter environments)

MA (Moving Averages)

The different types of moving averages, which also are individual functions (e.g., openbb.ta.ema), are available as an argument (ma_type) to the ma command. There are five accepted arguments, they are listed below in brackets:

  • Simple (SMA)
  • Exponential (EMA)
  • Hull (HMA)
  • Weighted (WMA)
  • Zero-Lag (ZLMA)

The window argument anticipates a list of integers representing the interval (minutes, days, weeks, months, etc.) to measure against the timestamp of the DataFrame's index. The example below is a daily timeseries of S&P E-Mini Futures:

es = openbb.stocks.load("ES=F")

openbb.ta.ma_chart(
data = es['Adj Close'],
symbol = 'E-Mini S&P Futures',
ma_type = 'SMA',
window = [21, 150])

openbb.ta.ma_chart

Changing, ma_type, to, ZLMA:

openbb.ta.ma_chart

ATR (Average True Range)

The atr command requires OHLC data, the data argument can be the load function.

ticker = 'ES=F'
start = '2000-01-01'

df_atr = openbb.ta.atr(data = openbb.stocks.load(f"{ticker}", start_date = f"{start}", monthly = True), window = 6)

df_atr.tail(5)
dateATRe_6
2022-07-01 00:00:00454.457
2022-08-01 00:00:00431.612
2022-09-01 00:00:00469.08
2022-10-01 00:00:00455.7
2022-11-01 00:00:00424.5

Donchian

To use the same data for multiple functions, it is more efficient to first load to a Pandas DataFrame:

ticker = 'ES=F'
start = '2000-01-01'
data_df: pd.DataFrame = openbb.stocks.load(f"{ticker}", start_date = f"{start}", monthly = True)

openbb.ta.donchian_chart(data_df)

openbb.ta.donchian_chart

The output from a function can be joined to the OHLC data:

ticker = 'ES=F'
start = '2000-01-01'
data_df: pd.DataFrame = openbb.stocks.load(f"{ticker}", start_date = f"{start}", monthly = True)

donchian = openbb.ta.donchian(data_df)

data_df = data_df.join(donchian)

data_df.tail(5)
dateOpenHighLowCloseAdj CloseVolumeDCL_20_20DCM_20_20DCU_20_20
2022-07-01 00:00:00378241443723.754133.54133.53.40941e+0731984003.124808.25
2022-08-01 00:00:004137.54327.539533956.53956.53.84732e+0732254016.624808.25
2022-09-01 00:00:00395841583595.253601.53601.54.68698e+073595.254201.754808.25
2022-10-01 00:00:003593.253924.253502388338834.80686e+0735024155.124808.25
2022-11-01 00:00:0038844050.753704.25397439742.65215e+0735024155.124808.25