pandas-ta
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesepandas-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 . It covers trend, momentum, volatility, volume, and overlap indicator categories — all callable with a single method on any OHLCV DataFrame.
df.tapandas-ta是一个Python库,它为pandas DataFrame扩展了130+种技术分析指标,可通过调用。它涵盖趋势、动量、波动率、成交量和重叠指标类别——所有指标都可在任意OHLCV DataFrame上通过单一方法调用。
df.taInstallation
安装
bash
uv pip install pandas-ta pandas httpxbash
uv pip install pandas-ta pandas httpxQuick Start
快速开始
python
import pandas as pd
import pandas_ta as tapython
import pandas as pd
import pandas_ta as taAssume 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},
]
))
undefineddf.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},
]
))
undefinedOHLCV 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 for time-aware indicators like VWAP. Column names must be lowercase (, not ).
DatetimeIndexcloseClosepandas-ta要求DataFrame使用小写列名:
python
import pandas as pd
df = pd.DataFrame({
"open": [...],
"high": [...],
"low": [...],
"close": [...],
"volume": [...]
}, index=pd.DatetimeIndex([...]))重要提示:将索引设置为以支持VWAP等时间感知型指标。列名必须为小写(如,而非)。
DatetimeIndexcloseCloseHandling Missing Data
缺失数据处理
python
undefinedpython
undefinedDrop 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]
undefineddf = df[df["volume"] > 0]
undefinedCore Indicator Categories
核心指标类别
Trend Indicators
趋势指标
Identify market direction and trend strength.
| Indicator | Call | Key Signal |
|---|---|---|
| SMA | | Price above = bullish |
| EMA | | Faster than SMA, less lag |
| SuperTrend | | Direction column: 1=bull, -1=bear |
| Ichimoku | | Returns tuple of (span, lines) DataFrames |
| VWMA | | Volume-weighted price trend |
| HMA | | Minimal lag, smooth trend |
| ADX | | >25 = trending, <20 = ranging |
识别市场方向和趋势强度。
| 指标 | 调用方式 | 关键信号 |
|---|---|---|
| SMA | | 价格在均线上方=看涨 |
| EMA | | 比SMA反应更快,滞后更少 |
| SuperTrend | | 方向列:1=看涨,-1=看跌 |
| Ichimoku | | 返回(span, lines) DataFrames的元组 |
| VWMA | | 成交量加权价格趋势 |
| HMA | | 滞后极小,趋势平滑 |
| ADX | | >25=趋势明显,<20=区间震荡 |
Momentum Indicators
动量指标
Measure speed and magnitude of price changes.
| Indicator | Call | Key Signal |
|---|---|---|
| RSI | | >70 overbought, <30 oversold |
| MACD | | Histogram crossover = entry |
| Stochastic | | >80 overbought, <20 oversold |
| CCI | | >100 overbought, <-100 oversold |
| Williams %R | | >-20 overbought, <-80 oversold |
| ROC | | Positive = upward momentum |
| MFI | | Money flow version of RSI |
衡量价格变化的速度和幅度。
| 指标 | 调用方式 | 关键信号 |
|---|---|---|
| RSI | | >70超买,<30超卖 |
| MACD | | 柱状线交叉=入场信号 |
| Stochastic | | >80超买,<20超卖 |
| CCI | | >100超买,<-100超卖 |
| Williams %R | | >-20超买,<-80超卖 |
| ROC | | 正值=上涨动量 |
| MFI | | 基于资金流的RSI变体 |
Volatility Indicators
波动率指标
Measure price dispersion and expected range.
| Indicator | Call | Key Signal |
|---|---|---|
| Bollinger Bands | | Squeeze = breakout pending |
| ATR | | Position sizing, stop placement |
| Keltner Channels | | BB inside KC = squeeze |
| Donchian Channels | | Breakout detection |
衡量价格离散度和预期波动区间。
| 指标 | 调用方式 | 关键信号 |
|---|---|---|
| Bollinger Bands | | 收缩=即将突破 |
| ATR | | 仓位 sizing,止损设置 |
| Keltner Channels | | 布林带在肯特纳通道内=收缩 |
| Donchian Channels | | 突破检测 |
Volume Indicators
成交量指标
Confirm price moves with volume analysis.
| Indicator | Call | Key Signal |
|---|---|---|
| OBV | | Divergence from price = reversal |
| VWAP | | Intraday fair value (needs DatetimeIndex) |
| CMF | | >0 accumulation, <0 distribution |
| AD | | Accumulation/Distribution line |
通过成交量分析确认价格走势。
| 指标 | 调用方式 | 关键信号 |
|---|---|---|
| OBV | | 与价格背离=反转信号 |
| VWAP | | 日内公允价值(需要DatetimeIndex) |
| CMF | | >0=积累,<0=派发 |
| AD | | 积累/派发线 |
Strategy Class
策略类
Run multiple indicators in a single call using :
ta.Strategypython
import pandas_ta as ta使用单次调用多个指标:
ta.Strategypython
import pandas_ta as taBuilt-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)
undefinedmy_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)
undefinedNamed Strategy Patterns
命名策略模式
python
undefinedpython
undefinedTrend 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},
]
)
undefinedmomentum_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},
]
)
undefinedCrypto-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
时间框架选择
| Timeframe | Use Case | Recommended Indicators |
|---|---|---|
| 1m-5m | Scalping, PumpFun | RSI(5-7), EMA(5,13), ATR(5) |
| 15m-1h | Day trading | MACD, RSI(14), BBands, EMA(20,50) |
| 4h-1d | Swing trading | SuperTrend, ADX, EMA(50,200) |
| 1w | Position trading | SMA(20,50), RSI(14), monthly VWAP |
| 时间框架 | 使用场景 | 推荐指标 |
|---|---|---|
| 1m-5m | 高频刷单、PumpFun | RSI(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
undefinedpython
undefinedEMA 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)
)
undefinedema_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)
)
undefinedMean Reversion
均值回归
python
undefinedpython
undefinedRSI 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)
)
undefinedrsi = 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)
)
undefinedMomentum Confirmation
动量确认
python
undefinedpython
undefinedMACD 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))
)
undefinedmacd = 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))
)
undefinedVolatility Breakout (BB Squeeze)
波动率突破(布林带收缩)
python
undefinedpython
undefinedBollinger 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
undefinedbb = 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
undefinedIntegration 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
参考资料
- — Top 20 crypto indicators with syntax, parameters, and interpretation
references/indicator_guide.md - — Pre-built strategy combinations for scalping, day trading, and swing trading
references/strategy_patterns.md - — Common mistakes with technical indicators in crypto markets
references/common_pitfalls.md
- — 20种顶级加密货币指标,包含语法、参数和解读
references/indicator_guide.md - — 预构建的策略组合,适用于高频刷单、日内交易和波段交易
references/strategy_patterns.md - — 加密货币市场中使用技术指标的常见误区
references/common_pitfalls.md
Scripts
脚本
- — Fetch OHLCV data and compute standard indicator set with signal summary
scripts/compute_indicators.py - — Run multiple strategy profiles and score current signal alignment
scripts/multi_indicator_scan.py
- — 获取OHLCV数据并计算标准指标集,附带信号摘要
scripts/compute_indicators.py - — 运行多个策略配置文件并评分当前信号一致性
scripts/multi_indicator_scan.py