custom-indicator by marketcalls/openalgo-indicator-skills
npx skills add https://github.com/marketcalls/openalgo-indicator-skills --skill custom-indicator使用 Numba JIT 编译创建自定义技术指标,以获得生产级速度。
$0 = 指标名称(例如:zscore、squeeze、vwap-bands、custom-rsi、mean-reversion)。必需。如果未提供参数,则询问用户想要构建什么指标。
rules/custom-indicators.md — Numba 模式和模板rules/numba-optimization.md — 性能最佳实践rules/indicator-catalog.md — 检查指标是否已存在于 openalgo.ta 中openalgo.ta 中,请告知用户并展示现有的 APIcustom_indicators/{indicator_name}/ 目录(按需){indicator_name}.py 文件,内容如下:广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
"""
{Indicator Name} — 自定义指标
描述:{测量内容}
类别:{趋势/动量/波动率/成交量/振荡器}
"""
import numpy as np
from numba import njit
import pandas as pd
# --- 核心计算 (Numba JIT) ---
@njit(cache=True, nogil=True)
def _compute_{name}(data: np.ndarray, period: int) -> np.ndarray:
"""Numba 编译的核心计算函数。"""
n = len(data)
result = np.full(n, np.nan)
# ... O(n) 算法 ...
return result
# --- 公共 API ---
def {name}(data, period=20):
"""
{Indicator Name}
参数:
data: 收盘价(numpy 数组、pandas Series 或列表)
period: 回溯周期(默认:20)
返回:
与输入类型相同的指标值
"""
if isinstance(data, pd.Series):
idx = data.index
result = _compute_{name}(data.values.astype(np.float64), period)
return pd.Series(result, index=idx, name="{Name}({period})")
arr = np.asarray(data, dtype=np.float64)
return _compute_{name}(arr, period)
5. 创建用于可视化的 chart.py 文件:
"""使用 Plotly 绘制自定义指标图表。"""
import os
from pathlib import Path
from datetime import datetime, timedelta
from dotenv import find_dotenv, load_dotenv
from openalgo import api, ta
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from {indicator_name} import {name}
# ... 获取数据、计算指标、创建图表 ...
6. 创建用于性能测试的 benchmark.py 文件:
"""对自定义指标进行性能基准测试。"""
import numpy as np
import time
from {indicator_name} import {name}
# 预热
data = np.random.randn(1000)
_ = {name}(data, 20)
# 对不同规模的数据进行基准测试
for size in [10_000, 100_000, 500_000]:
data = np.random.randn(size)
t0 = time.perf_counter()
_ = {name}(data, 20)
elapsed = (time.perf_counter() - t0) * 1000
print(f"{size:>10,} bars: {elapsed:>8.2f}ms")
@njit(cache=True, nogil=True)np.full(n, np.nan) 初始化输出数组np.isnan() 进行 NaN 检查for 循环(Numba 会编译为机器码)fastmath=True(会破坏 np.isnan())@njit 内部使用 pandas@njit 内部使用 try/except、字典、集合、字符串@njit 内部调用非 JIT 编译的函数以下现有函数可以在 @njit 内部调用:
from openalgo.indicators.utils import (
sma, ema, ema_wilder, stdev, true_range, atr_wilder,
highest, lowest, rolling_sum, crossover, crossunder
)
| 模式 | 实现 |
|---|---|
| Z-Score | (value - rolling_mean) / rolling_stdev |
| Squeeze | 布林带在肯特纳通道内部 |
| VWAP Bands | VWAP + N * (close - vwap) 的滚动标准差 |
| Momentum Score | RSI + MACD + ADX 条件的加权和 |
| Mean Reversion | 距离 SMA 的百分比 + 阈值 |
| Range Filter | 基于 ATR 的动态收盘价过滤器 |
| Trend Strength | ADX + 方向性运动组合 |
/custom-indicator zscore /custom-indicator squeeze-momentum /custom-indicator vwap-bands /custom-indicator range-filter
每周安装量
91
代码仓库
GitHub 星标
5
首次出现
2026年2月28日
安全审计
安装于
opencode91
codex91
gemini-cli90
github-copilot89
amp89
cline89
Create a custom technical indicator with Numba JIT compilation for production-grade speed.
$0 = indicator name (e.g., zscore, squeeze, vwap-bands, custom-rsi, mean-reversion). Required.If no arguments, ask the user what indicator they want to build.
rules/custom-indicators.md — Numba patterns and templatesrules/numba-optimization.md — Performance best practicesrules/indicator-catalog.md — Check if indicator already exists in openalgo.taopenalgo.ta, tell the user and show the existing APIcustom_indicators/{indicator_name}/ directory (on-demand){indicator_name}.py with:"""
{Indicator Name} — Custom Indicator
Description: {what it measures}
Category: {trend/momentum/volatility/volume/oscillator}
"""
import numpy as np
from numba import njit
import pandas as pd
# --- Core Computation (Numba JIT) ---
@njit(cache=True, nogil=True)
def _compute_{name}(data: np.ndarray, period: int) -> np.ndarray:
"""Numba-compiled core computation."""
n = len(data)
result = np.full(n, np.nan)
# ... O(n) algorithm ...
return result
# --- Public API ---
def {name}(data, period=20):
"""
{Indicator Name}
Args:
data: Close prices (numpy array, pandas Series, or list)
period: Lookback period (default: 20)
Returns:
Same type as input with indicator values
"""
if isinstance(data, pd.Series):
idx = data.index
result = _compute_{name}(data.values.astype(np.float64), period)
return pd.Series(result, index=idx, name="{Name}({period})")
arr = np.asarray(data, dtype=np.float64)
return _compute_{name}(arr, period)
5. Create chart.py for visualization:
"""Chart the custom indicator with Plotly."""
import os
from pathlib import Path
from datetime import datetime, timedelta
from dotenv import find_dotenv, load_dotenv
from openalgo import api, ta
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from {indicator_name} import {name}
# ... fetch data, compute indicator, create chart ...
6. Create benchmark.py for performance testing:
"""Benchmark the custom indicator."""
import numpy as np
import time
from {indicator_name} import {name}
# Warmup
data = np.random.randn(1000)
_ = {name}(data, 20)
# Benchmark on different sizes
for size in [10_000, 100_000, 500_000]:
data = np.random.randn(size)
t0 = time.perf_counter()
_ = {name}(data, 20)
elapsed = (time.perf_counter() - t0) * 1000
print(f"{size:>10,} bars: {elapsed:>8.2f}ms")
@njit(cache=True, nogil=True) on all compute functionsnp.full(n, np.nan) to initialize output arraysnp.isnan() for NaN checksfor loops (Numba compiles to machine code)fastmath=True (breaks np.isnan())@njit@njit@njitThese existing functions can be called inside @njit:
from openalgo.indicators.utils import (
sma, ema, ema_wilder, stdev, true_range, atr_wilder,
highest, lowest, rolling_sum, crossover, crossunder
)
| Pattern | Implementation |
|---|---|
| Z-Score | (value - rolling_mean) / rolling_stdev |
| Squeeze | Bollinger inside Keltner channel |
| VWAP Bands | VWAP + N * rolling stdev of (close - vwap) |
| Momentum Score | Weighted sum of RSI + MACD + ADX conditions |
| Mean Reversion | Distance from SMA as % + threshold |
| Range Filter | ATR-based dynamic filter on close |
| Trend Strength | ADX + directional movement composite |
/custom-indicator zscore /custom-indicator squeeze-momentum /custom-indicator vwap-bands /custom-indicator range-filter
Weekly Installs
91
Repository
GitHub Stars
5
First Seen
Feb 28, 2026
Security Audits
Gen Agent Trust HubWarnSocketPassSnykPass
Installed on
opencode91
codex91
gemini-cli90
github-copilot89
amp89
cline89
GSAP时间轴动画教程:创建多步骤序列动画与关键帧控制
3,600 周安装