indicator-expert
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOpenAlgo Indicator Expert Skill
OpenAlgo 指标专家技能
Environment
环境
- Python with openalgo, pandas, numpy, plotly, dash, streamlit, numba
- Data sources: OpenAlgo (Indian markets via ,
client.history(),client.quotes()), yfinance (US/Global)client.depth() - Real-time: OpenAlgo WebSocket (,
client.connect(),subscribe_ltp,subscribe_quote)subscribe_depth - Indicators: openalgo.ta (ALWAYS — 100+ Numba-optimized indicators)
- Charts: Plotly with
template="plotly_dark" - Dashboards: Plotly Dash with OR Streamlit with
dash-bootstrap-componentsst.plotly_chart() - Custom indicators: Numba + NumPy
@njit(cache=True, nogil=True) - API keys loaded from single root via
.env+python-dotenv— never hardcode keysfind_dotenv() - Scripts go in appropriate directories (charts/, dashboards/, custom_indicators/, scanners/) created on-demand
- Never use icons/emojis in code or logger output
- 已安装 openalgo、pandas、numpy、plotly、dash、streamlit、numba 库的 Python 环境
- 数据源:OpenAlgo(通过 、
client.history()、client.quotes()获取印度市场数据)、yfinance(获取美国/全球市场数据)client.depth() - 实时数据:OpenAlgo WebSocket(、
client.connect()、subscribe_ltp、subscribe_quote)subscribe_depth - 指标库:openalgo.ta(必须使用,包含100+经 Numba 优化的指标)
- 图表:使用 Plotly,默认配置
template="plotly_dark" - 仪表盘:搭配 的 Plotly Dash,或是使用
dash-bootstrap-components的 Streamlitst.plotly_chart() - 自定义指标:使用 Numba + NumPy 实现
@njit(cache=True, nogil=True) - API 密钥通过 +
python-dotenv从根目录的find_dotenv()文件加载,绝对不要硬编码密钥.env - 脚本按需放置在对应目录(charts/、dashboards/、custom_indicators/、scanners/),目录不存在时自动创建
- 代码和日志输出中禁止使用图标/emoji
Critical Rules
关键规则
- ALWAYS use openalgo.ta for ALL technical indicators. Never reimplement what already exists in the library.
- Data normalization: Always convert DataFrame index to datetime, sort, and strip timezone after fetching.
- Signal cleaning: Always use after generating raw buy/sell signals. Always
ta.exrem()before exrem..fillna(False) - Plotly dark theme: All charts use with
template="plotly_dark"for candlesticks.xaxis type="category" - Numba for custom indicators: Use — never
@njit(cache=True, nogil=True)(breaks NaN handling).fastmath=True - Input flexibility: openalgo.ta accepts numpy arrays, pandas Series, or lists. Output matches input type.
- WebSocket feeds: Use ,
client.connect()/client.subscribe_ltp()/subscribe_quote()for real-time data.subscribe_depth() - Environment: Load from project root via
.env— never hardcode API keys.find_dotenv() - Market detection: If symbol looks Indian (SBIN, RELIANCE, NIFTY), use OpenAlgo. If US (AAPL, MSFT), use yfinance.
- Always explain chart outputs in plain language so traders understand what the indicator shows.
- 所有技术指标必须使用 openalgo.ta 实现,绝对不要重复开发库中已有的功能。
- 数据标准化:获取数据后必须将 DataFrame 索引转换为 datetime 格式、排序,并移除时区信息。
- 信号清洗:生成原始买卖信号后必须使用 处理,调用 exrem 前必须先执行
ta.exrem()。.fillna(False) - Plotly 深色主题:所有图表使用 ,K线图的x轴类型设置为
template="plotly_dark"。xaxis type="category" - 自定义指标使用 Numba 优化:使用 装饰器,禁止使用
@njit(cache=True, nogil=True)(会破坏 NaN 处理逻辑)。fastmath=True - 输入灵活性:openalgo.ta 支持 numpy 数组、pandas Series 或列表作为输入,输出类型与输入保持一致。
- WebSocket 数据推送:使用 、
client.connect()/client.subscribe_ltp()/subscribe_quote()获取实时数据。subscribe_depth() - 环境配置:通过 加载项目根目录的
find_dotenv()文件,绝对不要硬编码 API 密钥。.env - 市场自动识别:如果标的代码是印度市场格式(SBIN、RELIANCE、NIFTY),使用 OpenAlgo 数据源;如果是美国市场(AAPL、MSFT),使用 yfinance 数据源。
- 输出解释:始终用通俗易懂的语言解释图表输出,方便交易者理解指标含义。
Data Source Priority
数据源优先级
| Market | Data Source | Method | Example Symbols |
|---|---|---|---|
| India (equity) | OpenAlgo | | SBIN, RELIANCE, INFY |
| India (index) | OpenAlgo | | NIFTY, BANKNIFTY |
| India (F&O) | OpenAlgo | | NIFTY30DEC25FUT |
| US/Global | yfinance | | AAPL, MSFT, SPY |
| 市场 | 数据源 | 方法 | 示例标的 |
|---|---|---|---|
| 印度(股票) | OpenAlgo | | SBIN, RELIANCE, INFY |
| 印度(指数) | OpenAlgo | | NIFTY, BANKNIFTY |
| 印度(F&O) | OpenAlgo | | NIFTY30DEC25FUT |
| 美国/全球 | yfinance | | AAPL, MSFT, SPY |
OpenAlgo API Methods for Data
OpenAlgo 数据API方法
| Method | Purpose | Returns |
|---|---|---|
| OHLCV candles | DataFrame (timestamp, open, high, low, close, volume) |
| Real-time snapshot | Dict (open, high, low, ltp, bid, ask, prev_close, volume) |
| Multi-symbol quotes | List of quote dicts |
| Market depth (L5) | Dict (bids, asks, ohlc, volume, oi) |
| Available intervals | Dict (minutes, hours, days, weeks, months) |
| WebSocket connect | None (sets up WS connection) |
| Live LTP stream | Callback with |
| Live quote stream | Callback with |
| Live depth stream | Callback with |
| 方法 | 用途 | 返回值 |
|---|---|---|
| 获取 OHLCV K线数据 | DataFrame(包含 timestamp、open、high、low、close、volume 字段) |
| 获取实时快照数据 | Dict(包含 open、high、low、ltp、bid、ask、prev_close、volume 字段) |
| 获取多标的快照数据 | 行情 Dict 组成的列表 |
| 获取5档市场深度数据 | Dict(包含 bids、asks、ohlc、volume、oi 字段) |
| 获取可用的时间周期 | Dict(包含 minutes、hours、days、weeks、months 字段) |
| 建立 WebSocket 连接 | 无返回值(完成WS连接初始化) |
| 订阅实时最新成交价推送 | 回调返回 |
| 订阅实时行情推送 | 回调返回 |
| 订阅实时深度数据推送 | 回调返回 |
Indicator Library Reference
指标库参考
All indicators accessed via :
from openalgo import ta所有指标通过 导入使用:
from openalgo import taTrend (20)
趋势类(20个)
ta.smata.emata.wmata.demata.temata.hmata.vwmata.almata.kamata.zlemata.t3ta.framata.supertrendta.ichimokuta.chande_kroll_stopta.trimata.mcginleyta.vidyata.alligatorta.ma_envelopesta.smata.emata.wmata.demata.temata.hmata.vwmata.almata.kamata.zlemata.t3ta.framata.supertrendta.ichimokuta.chande_kroll_stopta.trimata.mcginleyta.vidyata.alligatorta.ma_envelopesMomentum (9)
动量类(9个)
ta.rsita.macdta.stochasticta.ccita.williams_rta.bopta.elder_rayta.fisherta.crsita.rsita.macdta.stochasticta.ccita.williams_rta.bopta.elder_rayta.fisherta.crsiVolatility (16)
波动率类(16个)
ta.atrta.bbandsta.keltnerta.donchianta.chaikin_volatilityta.natrta.rvita.ultimate_oscillatorta.true_rangeta.massindexta.bb_percentta.bb_widthta.chandelier_exitta.historical_volatilityta.ulcer_indexta.starcta.atrta.bbandsta.keltnerta.donchianta.chaikin_volatilityta.natrta.rvita.ultimate_oscillatorta.true_rangeta.massindexta.bb_percentta.bb_widthta.chandelier_exitta.historical_volatilityta.ulcer_indexta.starcVolume (14)
成交量类(14个)
ta.obvta.obv_smoothedta.vwapta.mfita.adlta.cmfta.emvta.force_indexta.nvita.pvita.voloscta.vrocta.kvota.pvtta.obvta.obv_smoothedta.vwapta.mfita.adlta.cmfta.emvta.force_indexta.nvita.pvita.voloscta.vrocta.kvota.pvtOscillators (20+)
震荡指标类(20+个)
ta.cmota.trixta.uo_oscillatorta.awesome_oscillatorta.accelerator_oscillatorta.ppota.pota.dpota.aroon_oscillatorta.stoch_rsita.rvi_oscillatorta.chota.chopta.kstta.tsita.vortexta.gator_oscillatorta.stcta.coppockta.rocta.cmota.trixta.uo_oscillatorta.awesome_oscillatorta.accelerator_oscillatorta.ppota.pota.dpota.aroon_oscillatorta.stoch_rsita.rvi_oscillatorta.chota.chopta.kstta.tsita.vortexta.gator_oscillatorta.stcta.coppockta.rocStatistical (9)
统计类(9个)
ta.linregta.lrslopeta.correlationta.betata.varianceta.tsfta.medianta.modeta.median_bandsta.linregta.lrslopeta.correlationta.betata.varianceta.tsfta.medianta.modeta.median_bandsHybrid (6+)
混合类(6+个)
ta.adxta.dmita.aroonta.pivot_pointsta.sarta.williams_fractalsta.rwita.adxta.dmita.aroonta.pivot_pointsta.sarta.williams_fractalsta.rwiUtilities
工具函数
ta.crossoverta.crossunderta.crossta.highestta.lowestta.changeta.rocta.stdevta.exremta.flipta.valuewhenta.risingta.fallingta.crossoverta.crossunderta.crossta.highestta.lowestta.changeta.rocta.stdevta.exremta.flipta.valuewhenta.risingta.fallingModular Rule Files
模块化规则文件
Detailed reference for each topic is in :
rules/| Rule File | Topic |
|---|---|
| indicator-catalog | Complete 100+ indicator reference with signatures and parameters |
| data-fetching | OpenAlgo history/quotes/depth, yfinance, data normalization |
| plotting | Plotly candlestick, overlay, subplot, multi-panel charts |
| custom-indicators | Building custom indicators with Numba + NumPy |
| websocket-feeds | Real-time LTP/Quote/Depth streaming via WebSocket |
| numba-optimization | Numba JIT patterns, cache, nogil, NaN handling |
| dashboard-patterns | Plotly Dash web applications with callbacks |
| streamlit-patterns | Streamlit web applications with sidebar, metrics, plotly charts |
| multi-timeframe | Multi-timeframe indicator analysis |
| signal-generation | Signal generation, cleaning, crossover/crossunder |
| indicator-combinations | Combining indicators for confluence analysis |
| symbol-format | OpenAlgo symbol format, exchange codes, index symbols |
各主题的详细参考文档存放于 目录:
rules/| 规则文件 | 主题 |
|---|---|
| indicator-catalog | 完整的100+指标参考,包含函数签名和参数说明 |
| data-fetching | OpenAlgo 行情/快照/深度数据获取、yfinance 使用、数据标准化 |
| plotting | Plotly K线、指标叠加、子图、多面板图表绘制 |
| custom-indicators | 基于 Numba + NumPy 开发自定义指标 |
| websocket-feeds | 通过 WebSocket 实现实时 LTP/行情/深度数据推送 |
| numba-optimization | Numba JIT 最佳实践、缓存、nogil、NaN 处理 |
| dashboard-patterns | 带回调功能的 Plotly Dash 网页应用开发 |
| streamlit-patterns | 带侧边栏、指标卡片、Plotly 图表的 Streamlit 网页应用开发 |
| multi-timeframe | 多时间周期指标分析 |
| signal-generation | 信号生成、清洗、金叉/死叉判断 |
| indicator-combinations | 多指标组合共振分析 |
| symbol-format | OpenAlgo 标的代码格式、交易所代码、指数标的说明 |
Chart Templates (in rules/assets/)
图表模板(位于 rules/assets/ 目录)
| Template | Path | Description |
|---|---|---|
| EMA Chart | | EMA overlay on candlestick |
| RSI Chart | | RSI with overbought/oversold zones |
| MACD Chart | | MACD line, signal, histogram |
| Supertrend | | Supertrend overlay with direction coloring |
| Bollinger | | Bollinger Bands with squeeze detection |
| Multi-Indicator | | Candlestick + EMA + RSI + MACD + Volume |
| Basic Dashboard | | Single-symbol Plotly Dash app |
| Multi Dashboard | | Multi-symbol multi-timeframe dashboard |
| Streamlit Basic | | Single-symbol Streamlit app |
| Streamlit Multi | | Multi-timeframe Streamlit app |
| Custom Indicator | | Numba custom indicator template |
| Live Feed | | WebSocket real-time indicator |
| Scanner | | Multi-symbol indicator scanner |
| 模板 | 路径 | 描述 |
|---|---|---|
| EMA 图表 | | K线图叠加 EMA 指标 |
| RSI 图表 | | 带超买超卖区域标注的 RSI 指标图 |
| MACD 图表 | | 包含 MACD 线、信号线、直方图的 MACD 指标图 |
| Supertrend | | 带方向颜色标注的 Supertrend 指标叠加图 |
| 布林带 | | 带挤压检测功能的布林带指标图 |
| 多指标组合 | | K线 + EMA + RSI + MACD + 成交量组合图 |
| 基础仪表盘 | | 单标的 Plotly Dash 应用 |
| 多标的仪表盘 | | 多标的多时间周期仪表盘 |
| 基础 Streamlit 应用 | | 单标的 Streamlit 应用 |
| 多周期 Streamlit 应用 | | 多时间周期 Streamlit 应用 |
| 自定义指标模板 | | Numba 自定义指标开发模板 |
| 实时数据模板 | | WebSocket 实时指标计算模板 |
| 扫描器模板 | | 多标的指标扫描器模板 |
Quick Template: Standard Indicator Chart Script
快速模板:标准指标图表脚本
python
import os
from datetime import datetime, timedelta
from pathlib import Path
import numpy as np
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from dotenv import find_dotenv, load_dotenv
from openalgo import api, tapython
import os
from datetime import datetime, timedelta
from pathlib import Path
import numpy as np
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from dotenv import find_dotenv, load_dotenv
from openalgo import api, ta--- Config ---
--- Config ---
script_dir = Path(file).resolve().parent
load_dotenv(find_dotenv(), override=False)
SYMBOL = "SBIN"
EXCHANGE = "NSE"
INTERVAL = "D"
script_dir = Path(file).resolve().parent
load_dotenv(find_dotenv(), override=False)
SYMBOL = "SBIN"
EXCHANGE = "NSE"
INTERVAL = "D"
--- Fetch Data ---
--- Fetch Data ---
client = api(
api_key=os.getenv("OPENALGO_API_KEY"),
host=os.getenv("OPENALGO_HOST", "http://127.0.0.1:5000"),
)
end_date = datetime.now().date()
start_date = end_date - timedelta(days=365)
df = client.history(
symbol=SYMBOL, exchange=EXCHANGE, interval=INTERVAL,
start_date=start_date.strftime("%Y-%m-%d"),
end_date=end_date.strftime("%Y-%m-%d"),
)
if "timestamp" in df.columns:
df["timestamp"] = pd.to_datetime(df["timestamp"])
df = df.set_index("timestamp")
else:
df.index = pd.to_datetime(df.index)
df = df.sort_index()
if df.index.tz is not None:
df.index = df.index.tz_convert(None)
close = df["close"]
high = df["high"]
low = df["low"]
volume = df["volume"]
client = api(
api_key=os.getenv("OPENALGO_API_KEY"),
host=os.getenv("OPENALGO_HOST", "http://127.0.0.1:5000"),
)
end_date = datetime.now().date()
start_date = end_date - timedelta(days=365)
df = client.history(
symbol=SYMBOL, exchange=EXCHANGE, interval=INTERVAL,
start_date=start_date.strftime("%Y-%m-%d"),
end_date=end_date.strftime("%Y-%m-%d"),
)
if "timestamp" in df.columns:
df["timestamp"] = pd.to_datetime(df["timestamp"])
df = df.set_index("timestamp")
else:
df.index = pd.to_datetime(df.index)
df = df.sort_index()
if df.index.tz is not None:
df.index = df.index.tz_convert(None)
close = df["close"]
high = df["high"]
low = df["low"]
volume = df["volume"]
--- Compute Indicators ---
--- Compute Indicators ---
ema_20 = ta.ema(close, 20)
rsi_14 = ta.rsi(close, 14)
ema_20 = ta.ema(close, 20)
rsi_14 = ta.rsi(close, 14)
--- Chart ---
--- Chart ---
fig = make_subplots(
rows=2, cols=1, shared_xaxes=True,
row_heights=[0.7, 0.3], vertical_spacing=0.03,
subplot_titles=[f"{SYMBOL} Price + EMA(20)", "RSI(14)"],
)
fig = make_subplots(
rows=2, cols=1, shared_xaxes=True,
row_heights=[0.7, 0.3], vertical_spacing=0.03,
subplot_titles=[f"{SYMBOL} Price + EMA(20)", "RSI(14)"],
)
Candlestick
Candlestick
x_labels = df.index.strftime("%Y-%m-%d")
fig.add_trace(go.Candlestick(
x=x_labels, open=df["open"], high=high, low=low, close=close,
name="Price",
), row=1, col=1)
x_labels = df.index.strftime("%Y-%m-%d")
fig.add_trace(go.Candlestick(
x=x_labels, open=df["open"], high=high, low=low, close=close,
name="Price",
), row=1, col=1)
EMA overlay
EMA overlay
fig.add_trace(go.Scatter(
x=x_labels, y=ema_20, mode="lines",
name="EMA(20)", line=dict(color="cyan", width=1.5),
), row=1, col=1)
fig.add_trace(go.Scatter(
x=x_labels, y=ema_20, mode="lines",
name="EMA(20)", line=dict(color="cyan", width=1.5),
), row=1, col=1)
RSI subplot
RSI subplot
fig.add_trace(go.Scatter(
x=x_labels, y=rsi_14, mode="lines",
name="RSI(14)", line=dict(color="yellow", width=1.5),
), row=2, col=1)
fig.add_hline(y=70, line_dash="dash", line_color="red", row=2, col=1)
fig.add_hline(y=30, line_dash="dash", line_color="green", row=2, col=1)
fig.update_layout(
template="plotly_dark", title=f"{SYMBOL} Technical Analysis",
xaxis_rangeslider_visible=False, xaxis_type="category",
xaxis2_type="category", height=700,
)
fig.show()
undefinedfig.add_trace(go.Scatter(
x=x_labels, y=rsi_14, mode="lines",
name="RSI(14)", line=dict(color="yellow", width=1.5),
), row=2, col=1)
fig.add_hline(y=70, line_dash="dash", line_color="red", row=2, col=1)
fig.add_hline(y=30, line_dash="dash", line_color="green", row=2, col=1)
fig.update_layout(
template="plotly_dark", title=f"{SYMBOL} Technical Analysis",
xaxis_rangeslider_visible=False, xaxis_type="category",
xaxis2_type="category", height=700,
)
fig.show()
undefined