TATrend
TA.T3() - T3移动平均线
Tillson T3 Moving Average,通过多重指数平滑实现的低滞后、高平滑度移动平均线。
语法
python
TA.T3(data)
TA.T3(data, timeperiod=5, vfactor=0)参数
| 参数 | 类型 | 说明 | 默认值 |
|---|---|---|---|
| data | array | 价格数据 | - |
| timeperiod | int | 计算周期 | 5 |
| vfactor | float | 容积因子(0-1),越大越平滑 | 0 |
返回值
返回T3移动平均线数组。
计算方法
plaintext
通过6次EMA计算,结合容积因子:
a = vfactor
c1 = -a³
c2 = 3a² + 3a³
c3 = -6a² - 3a - 3a³
c4 = 1 + 3a + a³ + 3a²
e1 = EMA(Close, N)
e2 = EMA(e1, N)
...
e6 = EMA(e5, N)
T3 = c1×e6 + c2×e5 + c3×e4 + c4×e3特点
- 低滞后:比传统MA滞后更少
- 高平滑:保持良好平滑度
- 可调平滑度:vfactor参数控制
- 适合趋势:趋势市场表现优异
基础示例
python
def main():
records = exchange.GetRecords()
if len(records) < 50:
return
closes = [r['Close'] for r in records]
t3 = TA.T3(closes, 5, 0.7)
price = closes[-1]
# 价格与T3关系
if price > t3[-1]:
Log("价格在T3上方,看涨")
else:
Log("价格在T3下方,看跌")
# T3方向
if t3[-1] > t3[-2]:
Log("T3上升")
else:
Log("T3下降")高级应用
T3双线策略
python
def t3_dual_line():
records = exchange.GetRecords()
closes = [r['Close'] for r in records]
t3_fast = TA.T3(closes, 5, 0.7)
t3_slow = TA.T3(closes, 10, 0.7)
# 快慢线交叉
if t3_fast[-1] > t3_slow[-1] and t3_fast[-2] <= t3_slow[-2]:
exchange.Buy(-1, 1)
Log("T3快线上穿慢线,做多")
elif t3_fast[-1] < t3_slow[-1] and t3_fast[-2] >= t3_slow[-2]:
exchange.Sell(-1, 1)
Log("T3快线下穿慢线,做空")T3 + ATR动态止损
python
def t3_atr_stop():
records = exchange.GetRecords()
closes = [r['Close'] for r in records]
t3 = TA.T3(closes, 8, 0.7)
atr = TA.ATR(records, 14)
price = closes[-1]
# 多头入场
if price > t3[-1] and closes[-2] <= t3[-2]:
stop_loss = t3[-1] - 1.5 * atr[-1]
exchange.Buy(-1, 1)
Log(f"突破T3做多,止损: {stop_loss}")
# 空头入场
elif price < t3[-1] and closes[-2] >= t3[-2]:
stop_loss = t3[-1] + 1.5 * atr[-1]
exchange.Sell(-1, 1)
Log(f"跌破T3做空,止损: {stop_loss}")参数优化
周期选择
| 场景 | timeperiod | vfactor | 说明 |
|---|---|---|---|
| 日内 | 3-5 | 0.6-0.8 | 快速响应 |
| 短线 | 5-8 | 0.7 | 平衡 |
| 中线 | 8-15 | 0.5-0.7 | 平滑 |
vfactor影响
- 0:最快响应,噪音最多
- 0.5:平衡
- 0.7:推荐值,平滑度好
- 1:最平滑,滞后较大
与其他MA对比
| 指标 | 滞后性 | 平滑度 | 复杂度 | 适用 |
|---|---|---|---|---|
| EMA | 中 | 低 | 低 | 通用 |
| DEMA | 低 | 中 | 中 | 快速 |
| TEMA | 最低 | 中 | 中 | 极速 |
| T3 | 低 | 高 | 高 | 平衡 |
| KAMA | 自适应 | 自适应 | 高 | 智能 |
注意事项
- vfactor调整需谨慎测试
- 周期较短时效果最佳
- 震荡市中可能产生假信号
- 建议配合趋势过滤器
实战技巧
- 参数组合:timeperiod=8, vfactor=0.7 较常用
- 止损位置:T3下方1-1.5个ATR
- 趋势确认:结合ADX>25
- 入场时机:等待回踩T3后反弹