diff --git a/freqtrade/templates/freqaiprimer.py b/freqtrade/templates/freqaiprimer.py index afd0147f..962f96f7 100644 --- a/freqtrade/templates/freqaiprimer.py +++ b/freqtrade/templates/freqaiprimer.py @@ -725,41 +725,6 @@ class FreqaiPrimer(IStrategy): if holding_time >= self.exit_max_hold_hours.value: logger.info(f"[{pair}] 持仓时间超过{self.exit_max_hold_hours.value}小时,立即强制平仓") return 1.0 # 全部退出 - - # 在最小和最大持仓时间之间,寻找最佳退出时机 - if 8 <= holding_time < self.exit_max_hold_hours.value: - # 检查是否满足最佳退出时机条件 - # 1. 当前价格接近近期高点(过去24根K线) - dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe) - recent_high = dataframe['high'].rolling(window=24).max().iloc[-1] - price_near_high = (current_rate >= recent_high * self.exit_recent_high_threshold.value) # 价格接近近期高点 - - # 2. RSI处于超买区域(基于小时级RSI) - if 'rsi_1h' in dataframe.columns: - rsi_overbought = dataframe['rsi_1h'].iloc[-1] > self.exit_rsi_threshold.value - else: - rsi_overbought = False - - # 3. MACD出现死叉或下行趋势 - macd_bearish = False - if 'macd_1h' in dataframe.columns and 'macd_signal_1h' in dataframe.columns: - macd_bearish = dataframe['macd_1h'].iloc[-1] < dataframe['macd_signal_1h'].iloc[-1] - - # 4. 成交量明显放大,可能是见顶信号 - volume_spike = False - if 'volume' in dataframe.columns and 'volume_ma' in dataframe.columns: - volume_spike = dataframe['volume'].iloc[-1] > dataframe['volume_ma'].iloc[-1] * self.exit_volume_spike_multiplier.value - - # 如果满足2个或更多条件,认为是较好的退出时机 - exit_conditions_count = sum([price_near_high, rsi_overbought, macd_bearish, volume_spike]) - if exit_conditions_count >= 2: - logger.info(f"[{pair}] 持仓时间在8-{self.exit_max_hold_hours.value}小时区间,满足{exit_conditions_count}个最佳退出条件,执行平仓") - return 1.0 # 全部退出 - - # 如果有利润保护,也可以考虑在这段时间内逐步止盈 - if current_profit > self.exit_profit_threshold.value: # 利润超过阈值 - logger.info(f"[{pair}] 持仓时间在8-{self.exit_max_hold_hours.value}小时区间,利润{current_profit:.2%}超过阈值{self.exit_profit_threshold.value:.2%},执行止盈") - return 1.0 # 全部退出 """渐进式止盈逻辑""" # 获取当前市场状态