Files
easy_tdx_max/strategies/trix_cross.py
T
GitHubandClaude Opus 4.8 7f1bc645c2 release: v1.8.2 - 5 new strategies, --show chart, 15 total
- New strategies: dmi_trend, cci_breakout, mfi_volume, trix_cross, mtm_momentum
- run_all_strategies.py --show: dual-axis equity curve vs stock price chart
- zhuoyao_momentum strategy (from earlier commit)
- README: updated strategy table (9→15), changelog, demo screenshots
- Bump version to 1.8.2

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-09 23:17:04 +08:00

32 lines
1.0 KiB
Python

"""TRIX 三重平滑趋势策略。
TRIX 上穿信号线(TRIX_MA)买入;下穿卖出。
TRIX 对收盘价做三次 EMA 平滑再算变化率,比 MACD 多一层过滤,
能有效屏蔽短期噪音,减少震荡市的假信号。
适合中长线趋势跟踪,信号比 MACD 更少但更干净。
用法::
easy-tdx backtest SZ 000001 --strategy-file strategies/trix_cross.py --count 2000 --table
"""
from easy_tdx import MyTT
from easy_tdx.backtest import Strategy, crossover
class TRIXCrossStrategy(Strategy):
"""TRIX 三重平滑趋势策略。"""
def init(self) -> None:
# TRIX 返回 2 个数组: TRIX, TRMA(信号线)
self.trix, self.trma = self.I(MyTT.TRIX, self.data.close)
self.golden = crossover(self.trix, self.trma)
self.death = crossover(self.trma, self.trix)
def next(self) -> None:
if self.golden[self._bar_index] and self.position["size"] == 0:
self.buy(size=0)
elif self.death[self._bar_index] and self.position["size"] > 0:
self.sell(size=0)