其他
用 OpenAlgo 构建技术指标图表…
当需要用 OpenAlgo 的 openalgo.ta 库计算技术指标、绘制 Plotly 图表、搭建 Dash/Streamlit 仪表盘、做实时 WebSocket 行情或选股扫描时使用。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 35/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 55/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 38/100 ×0.15
适用场景
用 OpenAlgo 构建技术指标图表、特定
解决思路
- 所有技术指标一律使用 openalgo.ta,绝不重新实现库中已有的指标。
- 数据规范化:获取数据后始终把 DataFrame 索引转为 datetime、排序、并去除时区。
- 信号清洗:生成原始买卖信号后始终用 ta.exrem() 处理,且在 exrem 之前先 .fillna(False)。
- Plotly 图表统一使用 template="plotly_dark",K 线图设置 xaxis type="category"。
- 自定义指标:用 openalgo.ta 原语(ta.sma、ta.stdev、ta.bbands 等)加向量化 NumPy 组合实现,不重写内置指标,无需 JIT 或预热。
- openalgo.ta 接受 numpy 数组、pandas Series 或列表,输出类型与输入类型一致。
- 实时数据用 client.connect() 配合 client.subscribe_ltp() / subscribe_quote() / subscribe_depth()。
- 环境变量:通过 find_dotenv() 从项目根目录加载 .env,绝不硬编码 API key。
- 市场判断:印度标的(SBIN、RELIANCE、NIFTY)用 OpenAlgo,美国标的(AAPL、MSFT)用 yfinance。
- 始终用通俗语言解释图表输出,让交易者理解指标含义。
- 印度股票数据用 client.history();印度指数用 client.history(exchange="NSE_INDEX");印度 F&O 用 client.history(exchange="NFO");美国/全球用 yf.download()。
- 取数 API:client.history() 取 OHLCV K 线,client.quotes() 取实时快照,client.multiquotes() 取多标的报价,client.depth() 取五档盘口,client.intervals() 取可用周期,client.optionchain() 取期权链,client.optiongreeks() 取希腊值与 IV,client.expiry() 取到期日列表。
- 趋势类指标用 ta.sma、ta.ema、ta.wma、ta.dema、ta.tema、ta.hma、ta.vwma、ta.alma、ta.kama、ta.zlema、ta.t3、ta.frama、ta.supertrend、ta.ichimoku、ta.chande_kroll_stop、ta.trima、ta.mcginley、ta.vidya、ta.alligator、ta.ma_envelopes。
- 动量类指标用 ta.rsi、ta.macd、ta.stochastic、ta.cci、ta.williams_r、ta.bop、ta.elder_ray、ta.fisher、ta.crsi。
- 波动率类指标用 ta.atr、ta.bbands、ta.keltner、ta.donchian、ta.chaikin_volatility、ta.natr、ta.rvi、ta.ultimate_oscillator、ta.true_range、ta.massindex、ta.bb_percent、ta.bb_width、ta.chandelier_exit、ta.historical_volatility、ta.ulcer_index、ta.starc。
- 成交量类指标用 ta.obv、ta.obv_smoothed、ta.vwap、ta.mfi、ta.adl、ta.cmf、ta.emv、ta.force_index、ta.nvi、ta.pvi、ta.volosc、ta.vroc、ta.kvo、ta.pvt、ta.rvol。
- 振荡器类指标用 ta.cmo、ta.trix、ta.uo_oscillator、ta.awesome_oscillator、ta.accelerator_oscillator、ta.ppo、ta.po、ta.dpo、ta.aroon_oscillator、ta.stoch_rsi、ta.rvi_oscillator、ta.cho、ta.chop、ta.kst、ta.tsi、ta.vortex、ta.gator_oscillator、ta.stc、ta.coppock、ta.roc。
- 统计类指标用 ta.linreg、ta.lrslope、ta.correlation、ta.beta、ta.variance、ta.tsf、ta.median、ta.mode、ta.median_bands。
- 混合类指标用 ta.adx、ta.dmi、ta.aroon、ta.pivot_points、ta.sar、ta.williams_fractals、ta.rwi。
- TA-Lib 兼容指标用 ta.mom、ta.rocp、ta.rocr、ta.rocr100、ta.apo、ta.midpoint、ta.midprice、ta.avgprice、ta.medprice、ta.typprice、ta.wclprice、ta.plus_dm、ta.minus_dm、ta.dx、ta.adxr、ta.stochf、ta.linregangle、ta.linregintercept。
- 工具函数用 ta.crossover、ta.crossunder、ta.cross、ta.highest、ta.lowest、ta.change、ta.roc、ta.stdev、ta.exrem、ta.flip、ta.valuewhen、ta.rising、ta.falling。
- 按主题查阅 rules/ 下的规则文件:indicator-catalog、data-fetching、plotting、custom-indicators、websocket-feeds、performance、dashboard-patterns、streamlit-patterns、multi-timeframe、signal-generation、indicator-combinations、symbol-format。
- 复用 rules/assets/ 下的图表模板:ema_chart、rsi_chart、macd_chart、supertrend_chart、bollinger_chart、multi_indicator、dashboard_basic、dashboard_multi、streamlit_basic、streamlit_multi、custom_indicator、live_feed、scanner。
- 标准图表脚本流程:加载 .env,用 api(api_key, host) 创建 client,调用 client.history() 取数,规范化索引,用 ta.ema/ta.rsi 等计算指标,用 make_subplots 绘制 K 线加指标子图,设置 plotly_dark 与 xaxis_type="category",最后 fig.show()。
- 仪表盘默认用 Plotly Dash 加 dash-bootstrap-components,仅在用户明确要求时才用 Streamlit 的 st.plotly_chart()。
- 脚本按用途放入 charts/、dashboards/、custom_indicators/、scanners/ 等目录,按需创建。
- 代码与日志输出中不使用图标或 emoji。
适用边界 · 注意事项
- 不依赖 OpenAlgo 或 openalgo.ta 库、且不需要印度市场数据与实时 WebSocket 行情的场景。
- 用户明确要求使用其他指标库(如 TA-Lib、pandas-ta)或非 Plotly 绘图库时。
- 没有 OpenAlgo API key 或无法访问 OpenAlgo 服务的环境。