TATrend
TA.TEMA() - 三重指数移动平均线
Triple Exponential Moving Average (TEMA) 三重指数移动平均线,进一步减少滞后,响应最快的移动平均线。
语法
python
TA.TEMA(data)
TA.TEMA(data, timeperiod=30)参数
| 参数 | 类型 | 说明 | 默认值 |
|---|---|---|---|
| data | array | 价格数据(通常为收盘价) | - |
| timeperiod | int | 计算周期 | 30 |
返回值
返回三重指数移动平均线数组。
计算方法
plaintext
TEMA = 3 × EMA1 - 3 × EMA2 + EMA3
其中:
EMA1 = EMA(Close, N)
EMA2 = EMA(EMA1, N)
EMA3 = EMA(EMA2, N)通过三次指数平滑并加权组合,实现最小滞后。
特点
- 最低滞后:移动平均线中响应最快
- 最高灵敏:快速捕捉价格变化
- 噪音较多:容易产生假信号
- 趋势跟踪:适合快速趋势市场
基础示例
python
def main():
records = exchange.GetRecords()
if len(records) < 100:
return
closes = [r['Close'] for r in records]
tema = TA.TEMA(closes, 20)
price = closes[-1]
# 价格与TEMA关系
if price > tema[-1]:
Log("价格在TEMA上方,看涨")
else:
Log("价格在TEMA下方,看跌")
# TEMA斜率
slope = (tema[-1] - tema[-5]) / 5
if slope > 0:
Log("TEMA上升趋势")
else:
Log("TEMA下降趋势")高级应用
TEMA + ATR过滤策略
python
def tema_atr_filter():
records = exchange.GetRecords()
closes = [r['Close'] for r in records]
tema = TA.TEMA(closes, 20)
atr = TA.ATR(records, 14)
price = closes[-1]
volatility_filter = atr[-1] / price > 0.02 # 波动率>2%
if not volatility_filter:
return # 波动率太低不交易
# 突破TEMA做多
if price > tema[-1] and closes[-2] <= tema[-2]:
exchange.Buy(-1, 1)
Log("TEMA突破做多")
# 跌破TEMA做空
elif price < tema[-1] and closes[-2] >= tema[-2]:
exchange.Sell(-1, 1)
Log("TEMA跌破做空")TEMA多周期共振
python
def tema_multi_timeframe():
records_1h = exchange.GetRecords(PERIOD_H1)
records_15m = exchange.GetRecords(PERIOD_M15)
if len(records_1h) < 50 or len(records_15m) < 50:
return
closes_1h = [r['Close'] for r in records_1h]
closes_15m = [r['Close'] for r in records_15m]
tema_1h = TA.TEMA(closes_1h, 20)
tema_15m = TA.TEMA(closes_15m, 20)
price = closes_15m[-1]
# 多周期同向
h1_bullish = price > tema_1h[-1]
m15_bullish = price > tema_15m[-1]
if h1_bullish and m15_bullish:
# 双周期看涨
if closes_15m[-2] <= tema_15m[-2]:
exchange.Buy(-1, 1)
Log("多周期TEMA共振做多")
elif not h1_bullish and not m15_bullish:
# 双周期看跌
if closes_15m[-2] >= tema_15m[-2]:
exchange.Sell(-1, 1)
Log("多周期TEMA共振做空")参数优化
| 场景 | 周期 | 说明 |
|---|---|---|
| 超短线 | 5-10 | 日内快速交易 |
| 短线 | 10-20 | 短期波段 |
| 中线 | 20-50 | 中期趋势 |
| 长线 | 50-100 | 长期趋势 |
与其他MA对比
响应速度排序:TEMA > DEMA > EMA > WMA > SMA
| 指标 | 滞后期(相对) | 假信号率 | 适用场景 |
|---|---|---|---|
| SMA | 100% | 低 | 长期确认 |
| EMA | 60% | 中 | 通用 |
| DEMA | 30% | 中高 | 快速趋势 |
| TEMA | 10% | 高 | 极速趋势 |
注意事项
- 假信号多:必须配合过滤器(ATR/ADX/成交量)
- 震荡市场:表现差,建议避免
- 趋势市场:表现优异,快速入场
- 参数选择:周期过短噪音太大,建议20以上
实战技巧
- 趋势确认:结合ADX>25使用
- 止损设置:TEMA下方1-2个ATR
- 止盈目标:风险回报比至少1:2
- 仓位管理:因假信号多,建议轻仓