sortefi-ta

Our free, open-source Python library: the same technical calculations that run inside Sortefi. It has 121 indicators, 59 candlestick patterns and chart patterns, uses pure numpy and pandas, and is MIT licensed. GitHub · PyPI

Get started in four steps

1

Install

Needs Python 3.10 or newer. numpy and pandas are installed with it. There is no C library to compile.

pip install sortefi-ta
2

Load your candles

Any pandas DataFrame with open, high, low, close and volume columns, oldest row first. Use candles from your broker, an exchange or a CSV file.

df = pd.read_csv("candles.csv")
3

Call a function

Every function takes the DataFrame and returns a dictionary of arrays, one value per row.

rsi = ta.calc_rsi(df, period=14)["rsi"]
4

Read the latest value

Index [-1] is the most recent candle. The first few rows are blank (NaN) while the indicator warms up.

rsi[-1]

Quick start

import pandas as pd
import sortefi_ta as ta

df = pd.read_csv("candles.csv")   # columns: open, high, low, close, volume

rsi  = ta.calc_rsi(df, period=14)["rsi"]
ema  = ta.calc_ema(df, period=20)["ema"]
macd = ta.calc_macd(df)           # {"macd", "signal", "histogram"}

print(rsi[-1])                    # RSI of the latest candle
print(df["close"].iloc[-1] > ema[-1])   # is price above the 20 EMA?

Candlestick patterns

Each pattern returns 1.0 on candles where it formed, and 0 everywhere else. The patterns describe shape only, so a hammer is a hammer whatever came before it. To find a hammer after a downtrend, combine it with a trend tool such as a moving-average slope or ADX.

pats = ta.calc_candlestick_patterns(df, ["hammer", "bullish_engulfing"])

if pats["hammer"][-1] == 1.0:
    print("The latest candle is a hammer")

Screen many symbols

Run the same check over every symbol you have candles for, then keep the ones that pass.

# candles = {"AAPL": df_aapl, "MSFT": df_msft, ...}
oversold = []
for symbol, df in candles.items():
    rsi = ta.calc_rsi(df, period=14)["rsi"]
    if rsi[-1] < 30:
        oversold.append(symbol)

print(oversold)

What's inside

GroupCountExamples
Momentum29RSI, MACD, stochastic, CCI, Williams %R, squeeze, divergences
Trend & moving averages24SMA, EMA, HMA, ADX, Ichimoku, Supertrend, PSAR
Volatility18ATR, Bollinger Bands, Keltner, Donchian, historical volatility
Volume15VWAP, anchored VWAP, OBV, CMF, relative volume
Price maths14change, gaps, ranges, distance from high/low, wick ratio
Statistics7z-score, standard deviation, skew, kurtosis
Support & resistance6pivot points, Fibonacci, fractals, fair value gaps
Chart patterns6cup and handle, VCP, high tight flag, NR7
Candlestick patterns59hammer, engulfing, doji, morning star, harami and more

Find every function and its settings from Python:

print(len(ta.INDICATOR_FUNCTIONS))      # every function by name
help(ta.calc_bbands)                     # settings and outputs of one function

Every rule is readable

Each indicator and pattern lives in its own short file with its rule written out, so you can check exactly how a hammer or a squeeze is defined. Think a definition is wrong? Open an issue on GitHub and make your case. We want this to be a shared reference for how technical calculations are defined.

Rather not write code?

Describe the screen in plain English, and Sortefi finds the symbols across crypto, US and Indian stocks, ETFs and forex.

Open app