hsliuping/TradingAgents-CN · error · ValueError
不支持的指标: {name}
Error message
不支持的指标: {name} What it means
compute_indicator dispatches on the indicator name against the SUPPORTED set {'ma','ema','macd','rsi','boll','atr','kdj'}. An unrecognized name falls through all branches to this ValueError listing nothing but the name, so the caller can correct the spec. It is the single entry point also used by compute_many, so bad specs in batch lists surface here too.
Source
Thrown at tradingagents/tools/analysis/indicators.py:246
return out
if name == "atr":
_require_cols(df, ["high", "low", "close"])
n = int(params.get("n", 14))
out[f"atr{n}"] = atr(df["high"], df["low"], df["close"], n=n)
return out
if name == "kdj":
_require_cols(df, ["high", "low", "close"])
n = int(params.get("n", 9))
m1 = int(params.get("m1", 3))
m2 = int(params.get("m2", 3))
kdj_df = kdj(df["high"], df["low"], df["close"], n=n, m1=m1, m2=m2)
for c in kdj_df.columns:
out[c] = kdj_df[c]
return out
raise ValueError(f"不支持的指标: {name}")
def compute_many(df: pd.DataFrame, specs: List[IndicatorSpec]) -> pd.DataFrame:
if not specs:
return df.copy()
# 粗略去重(按 name+sorted(params))
def key(s: IndicatorSpec):
p = s.params or {}
items = tuple(sorted(p.items()))
return (s.name.lower(), items)
unique_specs: List[IndicatorSpec] = []
seen = set()
for s in specs:
k = key(s)
if k not in seen:
seen.add(k)
unique_specs.append(s)View on GitHub (pinned to 74783e8817)
Solutions
- Check the SUPPORTED constant at the top of indicators.py and use one of: ma, ema, macd, rsi, boll, atr, kdj.
- Validate spec names against indicators.SUPPORTED before calling compute_many with config-driven lists.
- Compute unsupported indicators separately with custom pandas/TA-Lib code and merge the resulting columns.
Example fix
# before out = compute_indicator(df, "bollinger", n=20) # after from tradingagents.tools.analysis.indicators import SUPPORTED name = "bollinger" if "bollinger" in SUPPORTED else "boll" out = compute_indicator(df, name, n=20)
Defensive patterns
Strategy: validation
Validate before calling
from tradingagents.tools.analysis.indicators import SUPPORTED
name = name.strip().lower()
if name not in SUPPORTED:
raise ConfigError(f"indicator {name!r} not supported; choose from {sorted(SUPPORTED)}")
out = compute_indicator(df, name, **params) Type guard
from tradingagents.tools.analysis.indicators import SUPPORTED
def is_supported_indicator(name: str) -> bool:
"""Type guard against the library's SUPPORTED indicator set."""
return isinstance(name, str) and name in SUPPORTED Try / catch
try:
out = compute_indicator(df, name, **params)
except ValueError as e:
if "不支持的指标" in str(e):
log.warning("skipping unsupported indicator %s", name)
out = df.copy()
else:
raise Prevention
- Validate config-driven indicator lists against indicators.SUPPORTED at config load time.
- Compute exotic indicators (stoch, cci, willr) with TA-Lib/pandas separately and merge columns.
- Fail fast on unknown names in batch specs before calling compute_many.
When it happens
Trigger: Calling compute_indicator(df, 'stoch') or compute_indicator(df, 'cci'); passing a typo like 'macd2', 'MA' (if case-sensitive), or 'bollinger'; or a compute_many spec list containing an unsupported name.
Common situations: Porting indicator lists from other TA libraries (TA-Lib names like 'STOCH', 'CCI', 'WILLR'); assuming a longer indicator menu than the 7 supported ones; case/format mismatches between config-driven indicator lists and SUPPORTED.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Indicator {indicator} is not supported. Please choose from:
- REDDIT FETCHING ERROR: max limit is less than the number of
- Trading Agents Graph Setup Error: no analysts selected!
- QIANFAN_API_KEY格式错误,应为: bce-v3/ALTAK-xxx/xxx
- 不支持的OpenAI兼容提供商: {provider}
AI-assisted analysis of hsliuping/TradingAgents-CN@74783e8817 (2026-08-28).
Data as JSON: /api/errors/92577eee8e332565.
Report an issue: GitHub.