技术分析
ta 命名空间中的 57+ 个内置技术分析函数
ta 命名空间提供 57+ 个技术分析函数,涵盖移动平均线、震荡指标、波动率、成交量、趋势检测和统计。
移动平均线
| 函数 | 说明 |
|---|---|
ta.sma(source, length) | 简单移动平均线 |
ta.ema(source, length) | 指数移动平均线 |
ta.wma(source, length) | 加权移动平均线 |
ta.vwma(source, length) | 成交量加权移动平均线 |
ta.rma(source, length) | 滚动/运行移动平均线(Wilder 平滑法) |
ta.hma(source, length) | 赫尔移动平均线 |
ta.alma(source, length, offset?, sigma?) | Arnaud Legoux 移动平均线 |
ta.swma(source) | 对称加权移动平均线 |
ta.linreg(source, length, offset?) | 线性回归 |
ta.vwap | 成交量加权平均价(变量) |
ta.vwap(source) | 成交量加权平均价(函数) |
const fast = ta.ema(close, 9);
const slow = ta.ema(close, 21);
plot(fast, 'Fast EMA', { color: '#2962FF' });
plot(slow, 'Slow EMA', { color: '#FF6D00' });震荡指标与动量
| 函数 | 返回 | 说明 |
|---|---|---|
ta.rsi(source, length) | number | 相对强弱指数 |
ta.macd(source, fast, slow, signal) | [macd, signal, hist] | MACD(返回元组) |
ta.stoch(source, high, low, length) | number | 随机指标 |
ta.cci(source, length) | number | 商品通道指数 |
ta.mfi(series, length) | number | 资金流量指数 |
ta.mom(source, length) | number | 动量 |
ta.roc(source, length) | number | 变动率 |
ta.tsi(source, short, long) | number | 真实强度指数 |
ta.cmo(source, length) | number | 钱德动量振荡指标 |
ta.cog(source, length) | number | 重心指标 |
ta.wpr(length) | number | 威廉 %R |
ta.change(source, length?) | number | N 根 K 线内的价格变化 |
const rsi = ta.rsi(close, 14);
const [macdLine, signalLine, hist] = ta.macd(close, 12, 26, 9);波动率与区间
| 函数 | 返回 | 说明 |
|---|---|---|
ta.atr(length) | number | 平均真实波幅 |
ta.bb(source, length, mult) | [middle, upper, lower] | 布林带(元组) |
ta.bbw(source, length, mult) | number | 布林带宽度 |
ta.kc(source, length, mult) | [middle, upper, lower] | 肯特纳通道(元组) |
ta.kcw(source, length, mult) | number | 肯特纳通道宽度 |
ta.stdev(source, length) | number | 标准差 |
ta.dev(source, length) | number | 平均绝对偏差 |
ta.variance(source, length) | number | 方差 |
ta.range(source, length) | number | 范围(最高 - 最低) |
ta.tr | number | 真实波幅(变量) |
ta.tr(handleNa?) | number | 真实波幅(函数) |
const [middle, upper, lower] = ta.bb(close, 20, 2);
const atr = ta.atr(14);成交量指标
这些以变量形式访问(而非函数调用):
| 变量 | 说明 |
|---|---|
ta.obv | 能量潮 |
ta.accdist | 累积/派发 |
ta.pvt | 价量趋势 |
ta.wad | 威廉累积/派发 |
ta.wvad | 威廉可变累积/派发 |
ta.nvi | 负成交量指数 |
ta.pvi | 正成交量指数 |
ta.iii | 日内强度指数 |
plot(ta.obv, 'OBV');
plot(ta.accdist, 'A/D');趋势分析
| 函数 | 返回 | 说明 |
|---|---|---|
ta.crossover(a, b) | boolean | 当 a 上穿 b 时为真 |
ta.crossunder(a, b) | boolean | 当 a 下穿 b 时为真 |
ta.cross(a, b) | boolean | 当 a 在任一方向交叉 b 时为真 |
ta.rising(source, length) | boolean | 当 source 连续 length 根 K 线上升时为真 |
ta.falling(source, length) | boolean | 当 source 连续 length 根 K 线下降时为真 |
ta.supertrend(factor, atrLength) | [value, direction] | 超级趋势(元组) |
ta.sar(start, inc, max) | number | 抛物线转向 |
ta.dmi(diLength, adxSmoothing) | [plus, minus, adx] | 动向指数(元组) |
if (ta.crossover(fast, slow)) {
plotshape(close, 'Buy', { style: shape.triangleup, location: location.belowbar });
}统计函数
| 函数 | 说明 |
|---|---|
ta.highest(source, length) | N 根 K 线内的最高值 |
ta.lowest(source, length) | N 根 K 线内的最低值 |
ta.highestbars(source, length) | 自最高值以来的 K 线数 |
ta.lowestbars(source, length) | 自最低值以来的 K 线数 |
ta.median(source, length) | 中位数 |
ta.mode(source, length) | 众数 |
ta.percentile_linear_interpolation(source, length, pct) | 百分位数(线性) |
ta.percentile_nearest_rank(source, length, pct) | 百分位数(最近秩) |
ta.percentrank(source, length) | 百分位排名 |
ta.correlation(a, b, length) | 相关系数 |
实用函数
| 函数 | 说明 |
|---|---|
ta.barssince(condition) | 条件为真以来的 K 线数 |
ta.valuewhen(condition, source, occurrence) | 条件为真时的值 |
ta.cum(source) | 累积和 |
支撑与阻力
| 函数 | 说明 |
|---|---|
ta.pivothigh(source, leftbars, rightbars) | 检测枢轴高点 |
ta.pivotlow(source, leftbars, rightbars) | 检测枢轴低点 |