抬高入场门槛

This commit is contained in:
zhangkun9038@dingtalk.com 2025-08-22 22:22:33 +08:00
parent 482e4ec3af
commit c9677546e1

View File

@ -204,7 +204,7 @@ class FreqaiPrimer(IStrategy):
}
},
"fit_live_predictions_candles": 100,
"live_retrain_candles": 100,
"live_retrain_candles": 50, # 加快训练频率每50根K线重新训练
}
@staticmethod
@ -775,18 +775,18 @@ class FreqaiPrimer(IStrategy):
entry_tag = ""
if is_green_channel:
# 🟢 牛市绿色通道持仓≤2个25USDT入场5条件需要满足4个
cond1 = (dataframe["&-price_value_divergence"] < self.buy_threshold * 1.8) # 超宽松偏离度
cond2 = (dataframe["volume_z_score"] > volume_z_score_threshold * 0.4) # 超低成交量要求
cond3 = (dataframe["rsi"] < rsi_threshold * 1.4) # 超宽松RSI
cond4 = (dataframe["close"] <= dataframe["bb_upperband"] * 1.05) # 允许上轨附近
cond5 = (dataframe["stochrsi_k"] < stochrsi_threshold * 1.4) # 超宽松STOCHRSI
# 🟢 牛市绿色通道持仓≤2个25USDT入场6条件需要满足5个适度提高门槛
cond1 = (dataframe["&-price_value_divergence"] < self.buy_threshold * 1.1) # 稍微收紧偏离度要求
cond2 = (dataframe["volume_z_score"] > volume_z_score_threshold * 0.9) # 稍微提高成交量要求
cond3 = (dataframe["rsi"] < rsi_threshold * 1.05) # 稍微收紧RSI要求
cond4 = (dataframe["close"] <= dataframe["bb_lowerband"] * 1.01) # 稍微收紧布林带要求
cond5 = (dataframe["stochrsi_k"] < stochrsi_threshold * 0.95) # 稍微收紧STOCHRSI要求
cond6 = (dataframe["close"] < dataframe["ema200"] * 0.99) # 新增价格略低于EMA200
core_conditions = [cond1, cond2, cond3, cond4, cond5]
# 使用向量化操作计算满足条件的数量
satisfied_count_vector = cond1.astype(int) + cond2.astype(int) + cond3.astype(int) + cond4.astype(int) + cond5.astype(int)
buy_condition = satisfied_count_vector >= 4
entry_tag = "bull_green_channel"
core_conditions = [cond1, cond2, cond3, cond4, cond5, cond6]
satisfied_count_vector = cond1.astype(int) + cond2.astype(int) + cond3.astype(int) + cond4.astype(int) + cond5.astype(int) + cond6.astype(int)
buy_condition = satisfied_count_vector >= 5 # 6条件需满足5个
entry_tag = "bull_green_channel_moderate"
# 仅在日志中使用最后一行的值
if len(dataframe) > 0:
@ -794,43 +794,48 @@ class FreqaiPrimer(IStrategy):
logger.info(f"[{pair}] 🟢 牛市绿色通道:持仓{open_trades}≤2个25USDT入场5条件需要满足{satisfied_count}/4个")
elif trend_status == "bullish":
# 牛市正常通道:持仓>2个75USDT入场必须满足全部7个条件
cond1 = (dataframe["&-price_value_divergence"] < self.buy_threshold * 1.5) # 放宽到1.5倍
cond2 = (dataframe["volume_z_score"] > volume_z_score_threshold * 0.7) # 降低成交量要求
cond3 = (dataframe["rsi"] < rsi_threshold * 1.2) # 放宽RSI要求
cond4 = (dataframe["close"] <= dataframe["bb_upperband"]) # 可以在上轨附近入场
cond5 = (dataframe["stochrsi_k"] < stochrsi_threshold * 1.2) # 放宽STOCHRSI要求
cond6 = pd.Series([True] * len(dataframe), index=dataframe.index) # 取消熊市过滤
cond7 = pd.Series([True] * len(dataframe), index=dataframe.index) # 取消超买过滤
buy_condition = cond1 & cond2 & cond3 & cond4 & cond5 & cond6 & cond7
entry_tag = "bull_normal"
logger.info(f"[{pair}] 🚀 牛市正常通道:持仓{open_trades}>2个75USDT入场必须满足全部7个条件")
# 牛市正常通道:持仓>2个时适度提高门槛
cond1 = (dataframe["&-price_value_divergence"] < self.buy_threshold * 0.95) # 稍微收紧偏离度
cond2 = (dataframe["volume_z_score"] > volume_z_score_threshold * 1.05) # 稍微提高成交量要求
cond3 = (dataframe["rsi"] < rsi_threshold * 0.95) # 稍微收紧RSI要求
cond4 = (dataframe["close"] <= dataframe["bb_lowerband"] * 0.99) # 稍微收紧布林带要求
cond5 = (dataframe["stochrsi_k"] < stochrsi_threshold * 0.9) # 稍微收紧STOCHRSI要求
cond6 = pd.Series([True] * len(dataframe), index=dataframe.index) # 保持取消熊市过滤
cond7 = pd.Series([True] * len(dataframe), index=dataframe.index) # 保持取消超买过滤
cond8 = (dataframe["close"] < dataframe["ema200"] * 0.97) # 新增价格略低于EMA200
buy_condition = cond1 & cond2 & cond3 & cond4 & cond5 & cond6 & cond7 & cond8
entry_tag = "bull_normal_moderate"
logger.info(f"[{pair}] 🚀 牛市正常通道:持仓{open_trades}>2个适度提高门槛")
elif trend_status == "bearish":
# 下跌趋势:严格入场条件,只抄底
cond1 = (dataframe["&-price_value_divergence"] < self.buy_threshold * 0.7) # 严格到0.7倍
cond2 = (dataframe["volume_z_score"] > volume_z_score_threshold * 1.3) # 提高成交量要求
cond3 = (dataframe["rsi"] < rsi_threshold * 0.8) # 严格RSI要求
cond4 = (dataframe["close"] <= dataframe["bb_lowerband"] * 0.95) # 必须跌破下轨
cond5 = (dataframe["stochrsi_k"] < stochrsi_threshold * 0.8) # 严格STOCHRSI要求
# 下跌趋势:适度提高门槛
cond1 = (dataframe["&-price_value_divergence"] < self.buy_threshold * 0.8) # 稍微收紧偏离度
cond2 = (dataframe["volume_z_score"] > volume_z_score_threshold * 1.2) # 稍微提高成交量要求
cond3 = (dataframe["rsi"] < rsi_threshold * 0.85) # 稍微收紧RSI要求
cond4 = (dataframe["close"] <= dataframe["bb_lowerband"] * 0.95) # 稍微收紧布林带
cond5 = (dataframe["stochrsi_k"] < stochrsi_threshold * 0.85) # 稍微收紧STOCHRSI
cond6 = ~bearish_signal_aligned # 保持熊市过滤
cond7 = ~stochrsi_overbought_aligned # 保持超买过滤
buy_condition = cond1 & cond2 & cond3 & cond4 & cond5 & cond6 & cond7
entry_tag = "bearish"
logger.info(f"[{pair}] 📉 下跌趋势策略:严格入场条件")
cond8 = (dataframe["close"] < dataframe["ema200"] * 0.95) # 新增价格低于EMA200
cond9 = (dataframe["volume"] > dataframe["volume"].rolling(20).mean() * 1.1) # 稍微提高放量确认
buy_condition = cond1 & cond2 & cond3 & cond4 & cond5 & cond6 & cond7 & cond8 & cond9
entry_tag = "bearish_moderate"
logger.info(f"[{pair}] 📉 下跌趋势:适度提高门槛")
else: # ranging
# 震荡趋势:使用原策略
cond1 = (dataframe["&-price_value_divergence"] < self.buy_threshold)
cond2 = (dataframe["volume_z_score"] > volume_z_score_threshold)
cond3 = (dataframe["rsi"] < rsi_threshold)
cond4 = (dataframe["close"] <= dataframe["bb_lowerband"])
cond5 = (dataframe["stochrsi_k"] < stochrsi_threshold)
# 震荡趋势:适度提高门槛
cond1 = (dataframe["&-price_value_divergence"] < self.buy_threshold * 0.9) # 稍微收紧偏离度
cond2 = (dataframe["volume_z_score"] > volume_z_score_threshold * 1.1) # 稍微提高成交量要求
cond3 = (dataframe["rsi"] < rsi_threshold * 0.9) # 稍微收紧RSI要求
cond4 = (dataframe["close"] <= dataframe["bb_lowerband"] * 0.97) # 稍微收紧布林带
cond5 = (dataframe["stochrsi_k"] < stochrsi_threshold * 0.9) # 稍微收紧STOCHRSI
cond6 = ~bearish_signal_aligned
cond7 = ~stochrsi_overbought_aligned
buy_condition = cond1 & cond2 & cond3 & cond4 & cond5 & cond6 & cond7
entry_tag = "ranging"
logger.info(f"[{pair}] ⚖️ 震荡趋势策略:标准入场条件")
cond8 = (dataframe["close"] < dataframe["ema200"] * 0.98) # 新增价格略低于EMA200
cond9 = (dataframe["adx"] > 20) # 保持趋势强度过滤
buy_condition = cond1 & cond2 & cond3 & cond4 & cond5 & cond6 & cond7 & cond8 & cond9
entry_tag = "ranging_moderate"
logger.info(f"[{pair}] ⚖️ 震荡趋势:适度提高门槛")
# 绿色通道和趋势状态的条件已经设置好buy_condition
conditions.append(buy_condition)
@ -865,7 +870,7 @@ class FreqaiPrimer(IStrategy):
# 存储信号强度到dataframe
dataframe.loc[buy_condition, 'signal_strength'] = signal_strength
dataframe.loc[buy_condition, 'immediate_entry'] = signal_strength >= 75 # 75分以上立即入场
dataframe.loc[buy_condition, 'immediate_entry'] = signal_strength >= 80 # 80分以上立即入场
# 调试日志 - 仅在日志中使用最后一行的值
if len(dataframe) > 0: