indicator-expert

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

OpenAlgo Indicator Expert Skill

OpenAlgo 指标专家技能

Environment

环境

  • Python with openalgo, pandas, numpy, plotly, dash, streamlit, numba
  • Data sources: OpenAlgo (Indian markets via
    client.history()
    ,
    client.quotes()
    ,
    client.depth()
    ), yfinance (US/Global)
  • 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
    dash-bootstrap-components
    OR Streamlit with
    st.plotly_chart()
  • Custom indicators: Numba
    @njit(cache=True, nogil=True)
    + NumPy
  • API keys loaded from single root
    .env
    via
    python-dotenv
    +
    find_dotenv()
    — never hardcode keys
  • 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()
    client.depth()
    获取印度市场数据)、yfinance(获取美国/全球市场数据)
  • 实时数据:OpenAlgo WebSocket(
    client.connect()
    subscribe_ltp
    subscribe_quote
    subscribe_depth
  • 指标库:openalgo.ta(必须使用,包含100+经 Numba 优化的指标)
  • 图表:使用 Plotly,默认配置
    template="plotly_dark"
  • 仪表盘:搭配
    dash-bootstrap-components
    的 Plotly Dash,或是使用
    st.plotly_chart()
    的 Streamlit
  • 自定义指标:使用 Numba
    @njit(cache=True, nogil=True)
    + NumPy 实现
  • API 密钥通过
    python-dotenv
    +
    find_dotenv()
    从根目录的
    .env
    文件加载,绝对不要硬编码密钥
  • 脚本按需放置在对应目录(charts/、dashboards/、custom_indicators/、scanners/),目录不存在时自动创建
  • 代码和日志输出中禁止使用图标/emoji

Critical Rules

关键规则

  1. ALWAYS use openalgo.ta for ALL technical indicators. Never reimplement what already exists in the library.
  2. Data normalization: Always convert DataFrame index to datetime, sort, and strip timezone after fetching.
  3. Signal cleaning: Always use
    ta.exrem()
    after generating raw buy/sell signals. Always
    .fillna(False)
    before exrem.
  4. Plotly dark theme: All charts use
    template="plotly_dark"
    with
    xaxis type="category"
    for candlesticks.
  5. Numba for custom indicators: Use
    @njit(cache=True, nogil=True)
    — never
    fastmath=True
    (breaks NaN handling).
  6. Input flexibility: openalgo.ta accepts numpy arrays, pandas Series, or lists. Output matches input type.
  7. WebSocket feeds: Use
    client.connect()
    ,
    client.subscribe_ltp()
    /
    subscribe_quote()
    /
    subscribe_depth()
    for real-time data.
  8. Environment: Load
    .env
    from project root via
    find_dotenv()
    — never hardcode API keys.
  9. Market detection: If symbol looks Indian (SBIN, RELIANCE, NIFTY), use OpenAlgo. If US (AAPL, MSFT), use yfinance.
  10. Always explain chart outputs in plain language so traders understand what the indicator shows.
  1. 所有技术指标必须使用 openalgo.ta 实现,绝对不要重复开发库中已有的功能。
  2. 数据标准化:获取数据后必须将 DataFrame 索引转换为 datetime 格式、排序,并移除时区信息。
  3. 信号清洗:生成原始买卖信号后必须使用
    ta.exrem()
    处理,调用 exrem 前必须先执行
    .fillna(False)
  4. Plotly 深色主题:所有图表使用
    template="plotly_dark"
    ,K线图的x轴类型设置为
    xaxis type="category"
  5. 自定义指标使用 Numba 优化:使用
    @njit(cache=True, nogil=True)
    装饰器,禁止使用
    fastmath=True
    (会破坏 NaN 处理逻辑)。
  6. 输入灵活性:openalgo.ta 支持 numpy 数组、pandas Series 或列表作为输入,输出类型与输入保持一致。
  7. WebSocket 数据推送:使用
    client.connect()
    client.subscribe_ltp()
    /
    subscribe_quote()
    /
    subscribe_depth()
    获取实时数据。
  8. 环境配置:通过
    find_dotenv()
    加载项目根目录的
    .env
    文件,绝对不要硬编码 API 密钥。
  9. 市场自动识别:如果标的代码是印度市场格式(SBIN、RELIANCE、NIFTY),使用 OpenAlgo 数据源;如果是美国市场(AAPL、MSFT),使用 yfinance 数据源。
  10. 输出解释:始终用通俗易懂的语言解释图表输出,方便交易者理解指标含义。

Data Source Priority

数据源优先级

MarketData SourceMethodExample Symbols
India (equity)OpenAlgo
client.history()
SBIN, RELIANCE, INFY
India (index)OpenAlgo
client.history(exchange="NSE_INDEX")
NIFTY, BANKNIFTY
India (F&O)OpenAlgo
client.history(exchange="NFO")
NIFTY30DEC25FUT
US/Globalyfinance
yf.download()
AAPL, MSFT, SPY
市场数据源方法示例标的
印度(股票)OpenAlgo
client.history()
SBIN, RELIANCE, INFY
印度(指数)OpenAlgo
client.history(exchange="NSE_INDEX")
NIFTY, BANKNIFTY
印度(F&O)OpenAlgo
client.history(exchange="NFO")
NIFTY30DEC25FUT
美国/全球yfinance
yf.download()
AAPL, MSFT, SPY

OpenAlgo API Methods for Data

OpenAlgo 数据API方法

MethodPurposeReturns
client.history(symbol, exchange, interval, start_date, end_date)
OHLCV candlesDataFrame (timestamp, open, high, low, close, volume)
client.quotes(symbol, exchange)
Real-time snapshotDict (open, high, low, ltp, bid, ask, prev_close, volume)
client.multiquotes(symbols=[...])
Multi-symbol quotesList of quote dicts
client.depth(symbol, exchange)
Market depth (L5)Dict (bids, asks, ohlc, volume, oi)
client.intervals()
Available intervalsDict (minutes, hours, days, weeks, months)
client.connect()
WebSocket connectNone (sets up WS connection)
client.subscribe_ltp(instruments, callback)
Live LTP streamCallback with
{symbol, exchange, ltp}
client.subscribe_quote(instruments, callback)
Live quote streamCallback with
{symbol, exchange, ohlc, ltp, volume}
client.subscribe_depth(instruments, callback)
Live depth streamCallback with
{symbol, exchange, bids, asks}
方法用途返回值
client.history(symbol, exchange, interval, start_date, end_date)
获取 OHLCV K线数据DataFrame(包含 timestamp、open、high、low、close、volume 字段)
client.quotes(symbol, exchange)
获取实时快照数据Dict(包含 open、high、low、ltp、bid、ask、prev_close、volume 字段)
client.multiquotes(symbols=[...])
获取多标的快照数据行情 Dict 组成的列表
client.depth(symbol, exchange)
获取5档市场深度数据Dict(包含 bids、asks、ohlc、volume、oi 字段)
client.intervals()
获取可用的时间周期Dict(包含 minutes、hours、days、weeks、months 字段)
client.connect()
建立 WebSocket 连接无返回值(完成WS连接初始化)
client.subscribe_ltp(instruments, callback)
订阅实时最新成交价推送回调返回
{symbol, exchange, ltp}
client.subscribe_quote(instruments, callback)
订阅实时行情推送回调返回
{symbol, exchange, ohlc, ltp, volume}
client.subscribe_depth(instruments, callback)
订阅实时深度数据推送回调返回
{symbol, exchange, bids, asks}

Indicator Library Reference

指标库参考

All indicators accessed via
from openalgo import ta
:
所有指标通过
from openalgo import ta
导入使用:

Trend (20)

趋势类(20个)

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.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

Momentum (9)

动量类(9个)

ta.rsi
,
ta.macd
,
ta.stochastic
,
ta.cci
,
ta.williams_r
,
ta.bop
,
ta.elder_ray
,
ta.fisher
,
ta.crsi
ta.rsi
,
ta.macd
,
ta.stochastic
,
ta.cci
,
ta.williams_r
,
ta.bop
,
ta.elder_ray
,
ta.fisher
,
ta.crsi

Volatility (16)

波动率类(16个)

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.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

Volume (14)

成交量类(14个)

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.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

Oscillators (20+)

震荡指标类(20+个)

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.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

Statistical (9)

统计类(9个)

ta.linreg
,
ta.lrslope
,
ta.correlation
,
ta.beta
,
ta.variance
,
ta.tsf
,
ta.median
,
ta.mode
,
ta.median_bands
ta.linreg
,
ta.lrslope
,
ta.correlation
,
ta.beta
,
ta.variance
,
ta.tsf
,
ta.median
,
ta.mode
,
ta.median_bands

Hybrid (6+)

混合类(6+个)

ta.adx
,
ta.dmi
,
ta.aroon
,
ta.pivot_points
,
ta.sar
,
ta.williams_fractals
,
ta.rwi
ta.adx
,
ta.dmi
,
ta.aroon
,
ta.pivot_points
,
ta.sar
,
ta.williams_fractals
,
ta.rwi

Utilities

工具函数

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
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

Modular Rule Files

模块化规则文件

Detailed reference for each topic is in
rules/
:
Rule FileTopic
indicator-catalogComplete 100+ indicator reference with signatures and parameters
data-fetchingOpenAlgo history/quotes/depth, yfinance, data normalization
plottingPlotly candlestick, overlay, subplot, multi-panel charts
custom-indicatorsBuilding custom indicators with Numba + NumPy
websocket-feedsReal-time LTP/Quote/Depth streaming via WebSocket
numba-optimizationNumba JIT patterns, cache, nogil, NaN handling
dashboard-patternsPlotly Dash web applications with callbacks
streamlit-patternsStreamlit web applications with sidebar, metrics, plotly charts
multi-timeframeMulti-timeframe indicator analysis
signal-generationSignal generation, cleaning, crossover/crossunder
indicator-combinationsCombining indicators for confluence analysis
symbol-formatOpenAlgo symbol format, exchange codes, index symbols
各主题的详细参考文档存放于
rules/
目录:
规则文件主题
indicator-catalog完整的100+指标参考,包含函数签名和参数说明
data-fetchingOpenAlgo 行情/快照/深度数据获取、yfinance 使用、数据标准化
plottingPlotly K线、指标叠加、子图、多面板图表绘制
custom-indicators基于 Numba + NumPy 开发自定义指标
websocket-feeds通过 WebSocket 实现实时 LTP/行情/深度数据推送
numba-optimizationNumba JIT 最佳实践、缓存、nogil、NaN 处理
dashboard-patterns带回调功能的 Plotly Dash 网页应用开发
streamlit-patterns带侧边栏、指标卡片、Plotly 图表的 Streamlit 网页应用开发
multi-timeframe多时间周期指标分析
signal-generation信号生成、清洗、金叉/死叉判断
indicator-combinations多指标组合共振分析
symbol-formatOpenAlgo 标的代码格式、交易所代码、指数标的说明

Chart Templates (in rules/assets/)

图表模板(位于 rules/assets/ 目录)

TemplatePathDescription
EMA Chart
assets/ema_chart/chart.py
EMA overlay on candlestick
RSI Chart
assets/rsi_chart/chart.py
RSI with overbought/oversold zones
MACD Chart
assets/macd_chart/chart.py
MACD line, signal, histogram
Supertrend
assets/supertrend_chart/chart.py
Supertrend overlay with direction coloring
Bollinger
assets/bollinger_chart/chart.py
Bollinger Bands with squeeze detection
Multi-Indicator
assets/multi_indicator/chart.py
Candlestick + EMA + RSI + MACD + Volume
Basic Dashboard
assets/dashboard_basic/app.py
Single-symbol Plotly Dash app
Multi Dashboard
assets/dashboard_multi/app.py
Multi-symbol multi-timeframe dashboard
Streamlit Basic
assets/streamlit_basic/app.py
Single-symbol Streamlit app
Streamlit Multi
assets/streamlit_multi/app.py
Multi-timeframe Streamlit app
Custom Indicator
assets/custom_indicator/template.py
Numba custom indicator template
Live Feed
assets/live_feed/template.py
WebSocket real-time indicator
Scanner
assets/scanner/template.py
Multi-symbol indicator scanner
模板路径描述
EMA 图表
assets/ema_chart/chart.py
K线图叠加 EMA 指标
RSI 图表
assets/rsi_chart/chart.py
带超买超卖区域标注的 RSI 指标图
MACD 图表
assets/macd_chart/chart.py
包含 MACD 线、信号线、直方图的 MACD 指标图
Supertrend
assets/supertrend_chart/chart.py
带方向颜色标注的 Supertrend 指标叠加图
布林带
assets/bollinger_chart/chart.py
带挤压检测功能的布林带指标图
多指标组合
assets/multi_indicator/chart.py
K线 + EMA + RSI + MACD + 成交量组合图
基础仪表盘
assets/dashboard_basic/app.py
单标的 Plotly Dash 应用
多标的仪表盘
assets/dashboard_multi/app.py
多标的多时间周期仪表盘
基础 Streamlit 应用
assets/streamlit_basic/app.py
单标的 Streamlit 应用
多周期 Streamlit 应用
assets/streamlit_multi/app.py
多时间周期 Streamlit 应用
自定义指标模板
assets/custom_indicator/template.py
Numba 自定义指标开发模板
实时数据模板
assets/live_feed/template.py
WebSocket 实时指标计算模板
扫描器模板
assets/scanner/template.py
多标的指标扫描器模板

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, ta
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, 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()
undefined
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()
undefined