新增实盘策略:ITrendStrategy(SA)

This commit is contained in:
2026-01-25 23:26:03 +08:00
parent 4a37652269
commit fa4749b02e
66 changed files with 44943 additions and 5961 deletions

View File

@@ -38,6 +38,7 @@ class SpectralTrendStrategy(Strategy):
order_direction: Optional[List[str]] = None,
indicators: Indicator = None,
model_indicator: Indicator = None,
holding_indicators: Indicator = None,
reverse: bool = False,
):
super().__init__(context, main_symbol, enable_log)
@@ -62,6 +63,7 @@ class SpectralTrendStrategy(Strategy):
self.order_direction = order_direction
self.model_indicator = model_indicator or Empty()
self.indicators = indicators or Empty()
self.holding_indicators = holding_indicators or Empty()
self.reverse = reverse
# 计算窗口大小
@@ -208,6 +210,13 @@ class SpectralTrendStrategy(Strategy):
self.log(f'trend_strength: {trend_strength:.2f}')
avg_entry_price = self.get_average_position_price(self.symbol)
if not self.holding_indicators.is_condition_met(*self.get_indicator_tuple()):
direction = "CLOSE_LONG" if volume > 0 else "CLOSE_SHORT"
self.log(f"Exit (Signal): {direction} | Strength={trend_strength:.2f} < {self.exit_threshold}")
self.close_position(direction, abs(volume))
self.entry_time = None
self.position_direction = None
# 确保 ATR 和 均价 有效
if current_atr > 0 and avg_entry_price > 0:
is_stop_loss = False