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
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
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")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"]
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
| Group | Count | Examples |
|---|---|---|
| Momentum | 29 | RSI, MACD, stochastic, CCI, Williams %R, squeeze, divergences |
| Trend & moving averages | 24 | SMA, EMA, HMA, ADX, Ichimoku, Supertrend, PSAR |
| Volatility | 18 | ATR, Bollinger Bands, Keltner, Donchian, historical volatility |
| Volume | 15 | VWAP, anchored VWAP, OBV, CMF, relative volume |
| Price maths | 14 | change, gaps, ranges, distance from high/low, wick ratio |
| Statistics | 7 | z-score, standard deviation, skew, kurtosis |
| Support & resistance | 6 | pivot points, Fibonacci, fractals, fair value gaps |
| Chart patterns | 6 | cup and handle, VCP, high tight flag, NR7 |
| Candlestick patterns | 59 | hammer, 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