Loading...
Loading...
C-optimized technical analysis with 150+ functions and 61 candlestick pattern recognition functions via TA-Lib
npx skill4agent add agiprolabs/claude-trading-skills ta-libTA-Libtalib# macOS
brew install ta-lib
uv pip install TA-Lib numpy pandas
# Ubuntu/Debian
sudo apt-get install -y ta-lib
uv pip install TA-Lib numpy pandas
# From source (any platform)
wget https://github.com/ta-lib/ta-lib/releases/download/v0.6.4/ta-lib-0.6.4-src.tar.gz
tar -xzf ta-lib-0.6.4-src.tar.gz
cd ta-lib-0.6.4
./configure --prefix=/usr/local
make && sudo make install
uv pip install TA-Lib numpy pandasimport talibImportError| Criterion | TA-Lib | pandas-ta |
|---|---|---|
| Speed | C-optimized, 10-100x faster | Pure Python, slower on large data |
| Candlestick patterns | 61 built-in patterns | Limited pattern support |
| Installation | Requires C library | |
| API style | NumPy arrays | DataFrame |
| Indicator count | 150+ | 130+ |
| Streaming | Single-value update possible | Recompute entire series |
| Dependencies | C lib + numpy | pandas only |
import numpy as np
import talib
# Create sample data
close = np.random.randn(100).cumsum() + 50
high = close + np.abs(np.random.randn(100))
low = close - np.abs(np.random.randn(100))
open_ = close + np.random.randn(100) * 0.5
volume = np.random.randint(1000, 10000, 100).astype(float)
# Function API — pass arrays directly
rsi = talib.RSI(close, timeperiod=14)
macd, signal, hist = talib.MACD(close, fastperiod=12, slowperiod=26, signalperiod=9)
upper, middle, lower = talib.BBANDS(close, timeperiod=20, nbdevup=2, nbdevdn=2)
atr = talib.ATR(high, low, close, timeperiod=14)
# Candlestick patterns — return +100 (bullish), -100 (bearish), or 0
doji = talib.CDLDOJI(open_, high, low, close)
hammer = talib.CDLHAMMER(open_, high, low, close)
engulfing = talib.CDLENGULFING(open_, high, low, close)import talib
rsi = talib.RSI(close, timeperiod=14)
sma = talib.SMA(close, timeperiod=20)
upper, mid, lower = talib.BBANDS(close)from talib import abstract
inputs = {"open": open_, "high": high, "low": low, "close": close, "volume": volume}
# Call by function name
rsi = abstract.RSI(inputs, timeperiod=14)
macd = abstract.MACD(inputs) # returns (macd, signal, hist)sma = talib.SMA(close, timeperiod=20)
ema = talib.EMA(close, timeperiod=12)
upper, mid, lower = talib.BBANDS(close, timeperiod=20, nbdevup=2, nbdevdn=2)
sar = talib.SAR(high, low, acceleration=0.02, maximum=0.2)
mama, fama = talib.MAMA(close, fastlimit=0.5, slowlimit=0.05)rsi = talib.RSI(close, timeperiod=14)
macd, signal, hist = talib.MACD(close, fastperiod=12, slowperiod=26, signalperiod=9)
slowk, slowd = talib.STOCH(high, low, close)
cci = talib.CCI(high, low, close, timeperiod=14)
willr = talib.WILLR(high, low, close, timeperiod=14)
adx = talib.ADX(high, low, close, timeperiod=14)
mfi = talib.MFI(high, low, close, volume, timeperiod=14)obv = talib.OBV(close, volume)
ad = talib.AD(high, low, close, volume)
adosc = talib.ADOSC(high, low, close, volume, fastperiod=3, slowperiod=10)atr = talib.ATR(high, low, close, timeperiod=14)
natr = talib.NATR(high, low, close, timeperiod=14)
trange = talib.TRANGE(high, low, close)+100-1000# Single patterns
doji = talib.CDLDOJI(open_, high, low, close)
hammer = talib.CDLHAMMER(open_, high, low, close)
engulfing = talib.CDLENGULFING(open_, high, low, close)
# Scan all 61 patterns at once
candle_names = talib.get_function_groups()["Pattern Recognition"]
for name in candle_names:
func = getattr(talib, name)
result = func(open_, high, low, close)
hits = np.nonzero(result)[0]
if len(hits) > 0:
print(f"{name}: {len(hits)} detections")references/candlestick_patterns.mdNaNrsi = talib.RSI(close, timeperiod=14)
# First 14 values will be NaN
valid_rsi = rsi[~np.isnan(rsi)]float64# Convert to float64 for TA-Lib compatibility
close = df["close"].values.astype(np.float64)
high = df["high"].values.astype(np.float64)
low = df["low"].values.astype(np.float64)import pandas_ta as ta
# pandas-ta auto-detects TA-Lib and uses it for supported indicators
# Set explicitly:
ta.Imports["talib"] = True # Force TA-Lib backend
df.ta.rsi(length=14) # Uses TA-Lib under the hood if availableimport vectorbt as vbt
# Use TA-Lib indicators in vectorbt
rsi = vbt.talib("RSI").run(close, timeperiod=14)
entries = rsi.real_crossed_below(30)
exits = rsi.real_crossed_above(70)# After fetching OHLCV from birdeye-api or dexscreener-api
close = np.array(ohlcv_data["close"], dtype=np.float64)
rsi = talib.RSI(close, timeperiod=14)import talib
# All function groups
groups = talib.get_function_groups()
for group, funcs in groups.items():
print(f"{group}: {len(funcs)} functions")
# All function names
all_funcs = talib.get_functions()
print(f"Total: {len(all_funcs)} functions")
# Info about a specific function
info = talib.abstract.Function("RSI").info
print(info["display_name"], info["group"])| File | Description |
|---|---|
| Most useful functions by category with syntax and parameters |
| All 61 candlestick patterns grouped by type with reliability ratings |
| Computes common indicators with TA-Lib/fallback comparison |
| Scans OHLCV data for all 61 candlestick patterns |