From 4c10aeb152ae2c3ea395004bac4cb42b1178b6bb Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 31 Aug 2025 18:59:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=85=A5=E5=9C=BA=E4=BF=A1?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- freqtrade/templates/freqaiprimer.py | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/freqtrade/templates/freqaiprimer.py b/freqtrade/templates/freqaiprimer.py index d7d4f65b..b44e1397 100644 --- a/freqtrade/templates/freqaiprimer.py +++ b/freqtrade/templates/freqaiprimer.py @@ -386,6 +386,43 @@ class FreqaiPrimer(IStrategy): logger.info(f"[{metadata['pair']}] 触发出场信号数量: {dataframe['exit_long'].sum()}") return dataframe + + def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: + # 入场信号主要依据1小时周期 + # 条件1: 价格接近布林带下轨 + close_to_bb_lower_1h = (dataframe['close'] <= dataframe['bb_lower_1h'] * 1.02) + + # 条件2: RSI 不高于阈值 + rsi_condition_1h = dataframe['rsi_1h'] < self.rsi_oversold + + # 条件3: StochRSI 处于超卖区域 + stochrsi_condition_1h = (dataframe['stochrsi_k_1h'] < 20) & (dataframe['stochrsi_d_1h'] < 20) + + # 条件4: MACD 上升趋势 + macd_condition_1h = dataframe['macd_1h'] > dataframe['macd_signal_1h'] + + # 辅助条件: 3m 和 15m 趋势确认 + trend_confirmation = (dataframe['trend_3m'] == 1) & (dataframe['trend_15m'] == 1) + + # 合并所有条件 + final_condition = close_to_bb_lower_1h & rsi_condition_1h & stochrsi_condition_1h & macd_condition_1h & trend_confirmation + + # 设置入场信号 + dataframe.loc[final_condition, 'enter_long'] = 1 + + # 增强调试信息 + logger.info(f"[{metadata['pair']}] 入场条件检查:") + logger.info(f" - 价格接近布林带下轨: {close_to_bb_lower_1h.sum()} 次") + logger.info(f" - RSI 超卖: {rsi_condition_1h.sum()} 次") + logger.info(f" - StochRSI 超卖: {stochrsi_condition_1h.sum()} 次") + logger.info(f" - MACD 上升趋势: {macd_condition_1h.sum()} 次") + logger.info(f" - 趋势确认: {trend_confirmation.sum()} 次") + + # 日志记录 + if dataframe['enter_long'].sum() > 0: + logger.info(f"[{metadata['pair']}] 发现入场信号数量: {dataframe['enter_long'].sum()}") + + return dataframe # 缓存数据框以便在trailing_stop_positive属性中使用 self._dataframe_cache = dataframe