pandas-ta

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

pandas-ta — Technical Analysis for Crypto Markets

pandas-ta — 加密货币市场的技术分析

pandas-ta is a Python library that extends pandas DataFrames with 130+ technical analysis indicators accessible via
df.ta
. It covers trend, momentum, volatility, volume, and overlap indicator categories — all callable with a single method on any OHLCV DataFrame.
pandas-ta是一个Python库,它为pandas DataFrame扩展了130+种技术分析指标,可通过
df.ta
调用。它涵盖趋势、动量、波动率、成交量和重叠指标类别——所有指标都可在任意OHLCV DataFrame上通过单一方法调用。

Installation

安装

bash
uv pip install pandas-ta pandas httpx
bash
uv pip install pandas-ta pandas httpx

Quick Start

快速开始

python
import pandas as pd
import pandas_ta as ta
python
import pandas as pd
import pandas_ta as ta

Assume df is a DataFrame with columns: open, high, low, close, volume

假设df是包含以下列的DataFrame:open, high, low, close, volume

All lowercase column names required

要求所有列名为小写

Single indicator

单个指标

df["rsi"] = df.ta.rsi(length=14) df["atr"] = df.ta.atr(length=14)
df["rsi"] = df.ta.rsi(length=14) df["atr"] = df.ta.atr(length=14)

Multiple indicators via strategy

通过策略调用多个指标

df.ta.strategy(ta.Strategy( name="Quick Check", ta=[ {"kind": "rsi", "length": 14}, {"kind": "macd", "fast": 12, "slow": 26, "signal": 9}, {"kind": "bbands", "length": 20, "std": 2.0}, ] ))
undefined
df.ta.strategy(ta.Strategy( name="Quick Check", ta=[ {"kind": "rsi", "length": 14}, {"kind": "macd", "fast": 12, "slow": 26, "signal": 9}, {"kind": "bbands", "length": 20, "std": 2.0}, ] ))
undefined

OHLCV DataFrame Format

OHLCV DataFrame格式

pandas-ta expects a DataFrame with lowercase column names:
python
import pandas as pd

df = pd.DataFrame({
    "open": [...],
    "high": [...],
    "low": [...],
    "close": [...],
    "volume": [...]
}, index=pd.DatetimeIndex([...]))
Important: Set the index to a
DatetimeIndex
for time-aware indicators like VWAP. Column names must be lowercase (
close
, not
Close
).
pandas-ta要求DataFrame使用小写列名:
python
import pandas as pd

df = pd.DataFrame({
    "open": [...],
    "high": [...],
    "low": [...],
    "close": [...],
    "volume": [...]
}, index=pd.DatetimeIndex([...]))
重要提示:将索引设置为
DatetimeIndex
以支持VWAP等时间感知型指标。列名必须为小写(如
close
,而非
Close
)。

Handling Missing Data

缺失数据处理

python
undefined
python
undefined

Drop rows with NaN in OHLCV columns

删除OHLCV列中包含NaN的行

df = df.dropna(subset=["open", "high", "low", "close", "volume"])
df = df.dropna(subset=["open", "high", "low", "close", "volume"])

Forward-fill small gaps (1-2 bars max)

向前填充小缺口(最多1-2根K线)

df = df.ffill(limit=2)
df = df.ffill(limit=2)

Verify no zero-volume bars for volume indicators

验证成交量指标无零成交量K线

df = df[df["volume"] > 0]
undefined
df = df[df["volume"] > 0]
undefined

Core Indicator Categories

核心指标类别

Trend Indicators

趋势指标

Identify market direction and trend strength.
IndicatorCallKey Signal
SMA
df.ta.sma(length=20)
Price above = bullish
EMA
df.ta.ema(length=20)
Faster than SMA, less lag
SuperTrend
df.ta.supertrend(length=10, multiplier=3)
Direction column: 1=bull, -1=bear
Ichimoku
df.ta.ichimoku()
Returns tuple of (span, lines) DataFrames
VWMA
df.ta.vwma(length=20)
Volume-weighted price trend
HMA
df.ta.hma(length=20)
Minimal lag, smooth trend
ADX
df.ta.adx(length=14)
>25 = trending, <20 = ranging
识别市场方向和趋势强度。
指标调用方式关键信号
SMA
df.ta.sma(length=20)
价格在均线上方=看涨
EMA
df.ta.ema(length=20)
比SMA反应更快,滞后更少
SuperTrend
df.ta.supertrend(length=10, multiplier=3)
方向列:1=看涨,-1=看跌
Ichimoku
df.ta.ichimoku()
返回(span, lines) DataFrames的元组
VWMA
df.ta.vwma(length=20)
成交量加权价格趋势
HMA
df.ta.hma(length=20)
滞后极小,趋势平滑
ADX
df.ta.adx(length=14)
>25=趋势明显,<20=区间震荡

Momentum Indicators

动量指标

Measure speed and magnitude of price changes.
IndicatorCallKey Signal
RSI
df.ta.rsi(length=14)
>70 overbought, <30 oversold
MACD
df.ta.macd(fast=12, slow=26, signal=9)
Histogram crossover = entry
Stochastic
df.ta.stoch(k=14, d=3, smooth_k=3)
>80 overbought, <20 oversold
CCI
df.ta.cci(length=20)
>100 overbought, <-100 oversold
Williams %R
df.ta.willr(length=14)
>-20 overbought, <-80 oversold
ROC
df.ta.roc(length=10)
Positive = upward momentum
MFI
df.ta.mfi(length=14)
Money flow version of RSI
衡量价格变化的速度和幅度。
指标调用方式关键信号
RSI
df.ta.rsi(length=14)
>70超买,<30超卖
MACD
df.ta.macd(fast=12, slow=26, signal=9)
柱状线交叉=入场信号
Stochastic
df.ta.stoch(k=14, d=3, smooth_k=3)
>80超买,<20超卖
CCI
df.ta.cci(length=20)
>100超买,<-100超卖
Williams %R
df.ta.willr(length=14)
>-20超买,<-80超卖
ROC
df.ta.roc(length=10)
正值=上涨动量
MFI
df.ta.mfi(length=14)
基于资金流的RSI变体

Volatility Indicators

波动率指标

Measure price dispersion and expected range.
IndicatorCallKey Signal
Bollinger Bands
df.ta.bbands(length=20, std=2)
Squeeze = breakout pending
ATR
df.ta.atr(length=14)
Position sizing, stop placement
Keltner Channels
df.ta.kc(length=20, scalar=1.5)
BB inside KC = squeeze
Donchian Channels
df.ta.donchian(lower_length=20, upper_length=20)
Breakout detection
衡量价格离散度和预期波动区间。
指标调用方式关键信号
Bollinger Bands
df.ta.bbands(length=20, std=2)
收缩=即将突破
ATR
df.ta.atr(length=14)
仓位 sizing,止损设置
Keltner Channels
df.ta.kc(length=20, scalar=1.5)
布林带在肯特纳通道内=收缩
Donchian Channels
df.ta.donchian(lower_length=20, upper_length=20)
突破检测

Volume Indicators

成交量指标

Confirm price moves with volume analysis.
IndicatorCallKey Signal
OBV
df.ta.obv()
Divergence from price = reversal
VWAP
df.ta.vwap()
Intraday fair value (needs DatetimeIndex)
CMF
df.ta.cmf(length=20)
>0 accumulation, <0 distribution
AD
df.ta.ad()
Accumulation/Distribution line
通过成交量分析确认价格走势。
指标调用方式关键信号
OBV
df.ta.obv()
与价格背离=反转信号
VWAP
df.ta.vwap()
日内公允价值(需要DatetimeIndex)
CMF
df.ta.cmf(length=20)
>0=积累,<0=派发
AD
df.ta.ad()
积累/派发线

Strategy Class

策略类

Run multiple indicators in a single call using
ta.Strategy
:
python
import pandas_ta as ta
使用
ta.Strategy
单次调用多个指标:
python
import pandas_ta as ta

Built-in "All" strategy runs every indicator

内置"All"策略运行所有指标

df.ta.strategy(ta.AllStrategy)
df.ta.strategy(ta.AllStrategy)

Custom strategy

自定义策略

my_strategy = ta.Strategy( name="Crypto Scalp", description="Fast indicators for crypto scalping", ta=[ {"kind": "ema", "length": 9}, {"kind": "ema", "length": 21}, {"kind": "rsi", "length": 7}, {"kind": "stoch", "k": 5, "d": 3, "smooth_k": 3}, {"kind": "atr", "length": 7}, {"kind": "bbands", "length": 10, "std": 2.0}, {"kind": "obv"}, ] ) df.ta.strategy(my_strategy)
undefined
my_strategy = ta.Strategy( name="Crypto Scalp", description="Fast indicators for crypto scalping", ta=[ {"kind": "ema", "length": 9}, {"kind": "ema", "length": 21}, {"kind": "rsi", "length": 7}, {"kind": "stoch", "k": 5, "d": 3, "smooth_k": 3}, {"kind": "atr", "length": 7}, {"kind": "bbands", "length": 10, "std": 2.0}, {"kind": "obv"}, ] ) df.ta.strategy(my_strategy)
undefined

Named Strategy Patterns

命名策略模式

python
undefined
python
undefined

Trend following

趋势跟踪

trend_strategy = ta.Strategy( name="Trend", ta=[ {"kind": "ema", "length": 20}, {"kind": "ema", "length": 50}, {"kind": "adx", "length": 14}, {"kind": "supertrend", "length": 10, "multiplier": 3}, {"kind": "atr", "length": 14}, ] )
trend_strategy = ta.Strategy( name="Trend", ta=[ {"kind": "ema", "length": 20}, {"kind": "ema", "length": 50}, {"kind": "adx", "length": 14}, {"kind": "supertrend", "length": 10, "multiplier": 3}, {"kind": "atr", "length": 14}, ] )

Mean reversion

均值回归

reversion_strategy = ta.Strategy( name="Mean Reversion", ta=[ {"kind": "rsi", "length": 14}, {"kind": "bbands", "length": 20, "std": 2.0}, {"kind": "stoch", "k": 14, "d": 3, "smooth_k": 3}, {"kind": "cci", "length": 20}, ] )
reversion_strategy = ta.Strategy( name="Mean Reversion", ta=[ {"kind": "rsi", "length": 14}, {"kind": "bbands", "length": 20, "std": 2.0}, {"kind": "stoch", "k": 14, "d": 3, "smooth_k": 3}, {"kind": "cci", "length": 20}, ] )

Momentum

动量策略

momentum_strategy = ta.Strategy( name="Momentum", ta=[ {"kind": "macd", "fast": 12, "slow": 26, "signal": 9}, {"kind": "rsi", "length": 14}, {"kind": "obv"}, {"kind": "roc", "length": 10}, {"kind": "mfi", "length": 14}, ] )
undefined
momentum_strategy = ta.Strategy( name="Momentum", ta=[ {"kind": "macd", "fast": 12, "slow": 26, "signal": 9}, {"kind": "rsi", "length": 14}, {"kind": "obv"}, {"kind": "roc", "length": 10}, {"kind": "mfi", "length": 14}, ] )
undefined

Crypto-Specific Considerations

加密货币专属注意事项

24/7 Markets

全天候市场

  • No session gaps — indicators that rely on open/close of sessions behave differently
  • VWAP resets at midnight UTC by default; consider anchored VWAP for custom periods
  • Weekend data is continuous — no Monday gap effects
  • 无交易时段缺口——依赖开盘/收盘的指标表现不同
  • VWAP默认在UTC午夜重置;可考虑锚定VWAP自定义周期
  • 周末数据连续——无周一缺口效应

High Volatility Adjustments

高波动率调整

  • Bollinger Bands: Use 2.5-3x standard deviation instead of the default 2x
  • RSI periods: Shorter periods (7-10) capture faster crypto cycles
  • ATR: Use for dynamic stop-losses; crypto ATR is typically 2-5x equity ATR
  • SuperTrend multiplier: 3-4x for crypto vs 2-3x for equities
  • 布林带:使用2.5-3倍标准差,而非默认的2倍
  • RSI周期:更短周期(7-10)捕捉加密货币更快的周期
  • ATR:用于动态止损;加密货币ATR通常是股票的2-5倍
  • SuperTrend乘数:加密货币用3-4倍,股票用2-3倍

Low-Cap Token Considerations

低市值代币注意事项

  • Volume indicators (OBV, CMF, MFI) are unreliable with thin order books
  • Prefer price-based indicators (RSI, BBands, SuperTrend) for low-liquidity tokens
  • ATR-based position sizing is critical — wide spreads amplify losses
  • Wash trading inflates volume; cross-reference with on-chain data
  • 成交量指标(OBV、CMF、MFI)在薄订单簿下不可靠
  • 优先选择基于价格的指标(RSI、布林带、SuperTrend)用于低流动性代币
  • 基于ATR的仓位 sizing至关重要——点差过大会放大损失
  • 洗盘交易会夸大成交量;需与链上数据交叉验证

Timeframe Selection

时间框架选择

TimeframeUse CaseRecommended Indicators
1m-5mScalping, PumpFunRSI(5-7), EMA(5,13), ATR(5)
15m-1hDay tradingMACD, RSI(14), BBands, EMA(20,50)
4h-1dSwing tradingSuperTrend, ADX, EMA(50,200)
1wPosition tradingSMA(20,50), RSI(14), monthly VWAP
时间框架使用场景推荐指标
1m-5m高频刷单、PumpFunRSI(5-7), EMA(5,13), ATR(5)
15m-1h日内交易MACD, RSI(14), 布林带, EMA(20,50)
4h-1d波段交易SuperTrend, ADX, EMA(50,200)
1w持仓交易SMA(20,50), RSI(14), 月度VWAP

Common Indicator Combinations

常见指标组合

Trend Following

趋势跟踪

python
undefined
python
undefined

EMA crossover + ADX confirmation + SuperTrend direction

EMA交叉 + ADX确认 + SuperTrend方向

ema_fast = df.ta.ema(length=20) ema_slow = df.ta.ema(length=50) adx_df = df.ta.adx(length=14) st_df = df.ta.supertrend(length=10, multiplier=3)
bullish = ( (ema_fast > ema_slow) & (adx_df["ADX_14"] > 25) & (st_df["SUPERTd_10_3.0"] == 1) )
undefined
ema_fast = df.ta.ema(length=20) ema_slow = df.ta.ema(length=50) adx_df = df.ta.adx(length=14) st_df = df.ta.supertrend(length=10, multiplier=3)
bullish = ( (ema_fast > ema_slow) & (adx_df["ADX_14"] > 25) & (st_df["SUPERTd_10_3.0"] == 1) )
undefined

Mean Reversion

均值回归

python
undefined
python
undefined

RSI oversold + price at lower BB + Stochastic oversold

RSI超卖 + 价格触及布林带下轨 + 随机指标超卖

rsi = df.ta.rsi(length=14) bb = df.ta.bbands(length=20, std=2.5) stoch = df.ta.stoch(k=14, d=3, smooth_k=3)
buy_signal = ( (rsi < 30) & (df["close"] <= bb["BBL_20_2.5"]) & (stoch["STOCHk_14_3_3"] < 20) )
undefined
rsi = df.ta.rsi(length=14) bb = df.ta.bbands(length=20, std=2.5) stoch = df.ta.stoch(k=14, d=3, smooth_k=3)
buy_signal = ( (rsi < 30) & (df["close"] <= bb["BBL_20_2.5"]) & (stoch["STOCHk_14_3_3"] < 20) )
undefined

Momentum Confirmation

动量确认

python
undefined
python
undefined

MACD histogram positive + RSI above 50 + OBV rising

MACD柱状线为正 + RSI高于50 + OBV上升

macd = df.ta.macd(fast=12, slow=26, signal=9) rsi = df.ta.rsi(length=14) obv = df.ta.obv()
momentum_bull = ( (macd["MACDh_12_26_9"] > 0) & (rsi > 50) & (obv > obv.shift(1)) )
undefined
macd = df.ta.macd(fast=12, slow=26, signal=9) rsi = df.ta.rsi(length=14) obv = df.ta.obv()
momentum_bull = ( (macd["MACDh_12_26_9"] > 0) & (rsi > 50) & (obv > obv.shift(1)) )
undefined

Volatility Breakout (BB Squeeze)

波动率突破(布林带收缩)

python
undefined
python
undefined

Bollinger Band width contracting + volume spike

布林带宽度收缩 + 成交量激增

bb = df.ta.bbands(length=20, std=2.0) atr = df.ta.atr(length=14) vol_sma = df["volume"].rolling(20).mean()
bb_width = (bb["BBU_20_2.0"] - bb["BBL_20_2.0"]) / bb["BBM_20_2.0"] squeeze = bb_width < bb_width.rolling(120).quantile(0.1) vol_spike = df["volume"] > (vol_sma * 2.0)
breakout_setup = squeeze & vol_spike
undefined
bb = df.ta.bbands(length=20, std=2.0) atr = df.ta.atr(length=14) vol_sma = df["volume"].rolling(20).mean()
bb_width = (bb["BBU_20_2.0"] - bb["BBL_20_2.0"]) / bb["BBM_20_2.0"] squeeze = bb_width < bb_width.rolling(120).quantile(0.1) vol_spike = df["volume"] > (vol_sma * 2.0)
breakout_setup = squeeze & vol_spike
undefined

Integration with Other Skills

与其他工具集成

  • birdeye-api: Fetch OHLCV data → feed into pandas-ta for indicator computation
  • vectorbt: Use pandas-ta indicators as signal inputs for backtesting
  • trading-visualization: Plot indicator overlays on price charts
  • slippage-modeling: Combine ATR with slippage estimates for realistic execution modeling
  • position-sizing: Use ATR-based sizing from pandas-ta output
  • birdeye-api:获取OHLCV数据→输入到pandas-ta计算指标
  • vectorbt:将pandas-ta指标作为信号输入用于回测
  • trading-visualization:在价格图表上绘制指标叠加层
  • slippage-modeling:将ATR与滑点估计结合进行真实执行建模
  • position-sizing:使用pandas-ta输出的基于ATR的仓位 sizing

Files

文件

References

参考资料

  • references/indicator_guide.md
    — Top 20 crypto indicators with syntax, parameters, and interpretation
  • references/strategy_patterns.md
    — Pre-built strategy combinations for scalping, day trading, and swing trading
  • references/common_pitfalls.md
    — Common mistakes with technical indicators in crypto markets
  • references/indicator_guide.md
    — 20种顶级加密货币指标,包含语法、参数和解读
  • references/strategy_patterns.md
    — 预构建的策略组合,适用于高频刷单、日内交易和波段交易
  • references/common_pitfalls.md
    — 加密货币市场中使用技术指标的常见误区

Scripts

脚本

  • scripts/compute_indicators.py
    — Fetch OHLCV data and compute standard indicator set with signal summary
  • scripts/multi_indicator_scan.py
    — Run multiple strategy profiles and score current signal alignment
  • scripts/compute_indicators.py
    — 获取OHLCV数据并计算标准指标集,附带信号摘要
  • scripts/multi_indicator_scan.py
    — 运行多个策略配置文件并评分当前信号一致性