没有入场信号

This commit is contained in:
Ubuntu 2025-08-31 18:59:58 +08:00
parent aed02ad8e9
commit 4c10aeb152

View File

@ -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