技术分析

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?)numberN 根 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.trnumber真实波幅(变量)
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)检测枢轴低点