入场收紧1.02倍

This commit is contained in:
zhangkun9038@dingtalk.com 2025-08-22 23:31:56 +08:00
parent e9b0731475
commit 4280366682

View File

@ -92,9 +92,9 @@ class FreqaiPrimer(IStrategy):
exit_ranging_trend_score_threshold = IntParameter(80, 90, default=85, space="sell", optimize=True, load=True)
# 🎯 入场折扣率参数可通过hyperopt优化
entry_discount_bull_normal = DecimalParameter(0.005, 0.03, default=0.010, decimals=3, space="buy", optimize=True, load=True) # 牛市正常通道折扣 (默认1%)
entry_discount_ranging = DecimalParameter(0.001, 0.02, default=0.0075, decimals=3, space="buy", optimize=True, load=True) # 震荡市折扣 (默认0.75%)
entry_discount_bearish = DecimalParameter(0.001, 0.015, default=0.005, decimals=3, space="buy", optimize=True, load=True) # 熊市折扣 (默认0.5%)
entry_discount_bull_normal = DecimalParameter(0.005, 0.03, default=0.010 * 0.98, decimals=3, space="buy", optimize=True, load=True) # 牛市正常通道折扣 (收紧:*0.98)
entry_discount_ranging = DecimalParameter(0.001, 0.02, default=0.0075 * 0.98, decimals=3, space="buy", optimize=True, load=True) # 震荡市折扣 (收紧:*0.98)
entry_discount_bearish = DecimalParameter(0.001, 0.015, default=0.005 * 0.98, decimals=3, space="buy", optimize=True, load=True) # 熊市折扣 (收紧:*0.98)
# 🎯 加仓策略参数(统一标准,移除趋势判断)
ADD_PROGRESSION_FACTOR = 1.09 # 递进系数每次加仓阈值递增1.09倍
@ -760,11 +760,11 @@ class FreqaiPrimer(IStrategy):
# 市场状态影响入场严格程度
regime_adjustments = {
0: {"threshold_mult": 1.5, "strict_mult": 0.7}, # 低波动震荡:更宽松入场
1: {"threshold_mult": 1.2, "strict_mult": 0.8}, # 正常趋势:较宽松
2: {"threshold_mult": 1.0, "strict_mult": 1.0}, # 高波动趋势:标准
3: {"threshold_mult": 0.8, "strict_mult": 1.2}, # 极端波动:更严格
4: {"threshold_mult": 0.6, "strict_mult": 1.5}, # 黑天鹅状态:最严格
0: {"threshold_mult": 1.5 * 0.98, "strict_mult": 0.7 * 1.02}, # 低波动震荡:收紧阈值
1: {"threshold_mult": 1.2 * 0.98, "strict_mult": 0.8 * 1.02}, # 正常趋势:收紧阈值
2: {"threshold_mult": 1.0 * 0.98, "strict_mult": 1.0 * 1.02}, # 高波动趋势:收紧阈值
3: {"threshold_mult": 0.8 * 0.98, "strict_mult": 1.2 * 1.02}, # 极端波动:收紧阈值
4: {"threshold_mult": 0.6 * 0.98, "strict_mult": 1.5 * 1.02}, # 黑天鹅状态:收紧阈值
}
regime_adj = regime_adjustments.get(market_regime, regime_adjustments[2])
@ -795,11 +795,11 @@ class FreqaiPrimer(IStrategy):
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要求
cond1 = (dataframe["&-price_value_divergence"] < self.buy_threshold * 1.5 * 0.98) # 收紧1.5*0.98=1.47
cond2 = (dataframe["volume_z_score"] > volume_z_score_threshold * 0.7 * 1.02) # 收紧0.7*1.02=0.714倍
cond3 = (dataframe["rsi"] < rsi_threshold * 1.2 * 0.98) # 收紧1.2*0.98=1.176倍
cond4 = (dataframe["close"] <= dataframe["bb_upperband"] * 0.98) # 收紧:上轨附近*0.98
cond5 = (dataframe["stochrsi_k"] < stochrsi_threshold * 1.2 * 0.98) # 收紧1.2*0.98=1.176倍
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
@ -808,11 +808,11 @@ class FreqaiPrimer(IStrategy):
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.7 * 0.98) # 收紧0.7*0.98=0.686
cond2 = (dataframe["volume_z_score"] > volume_z_score_threshold * 1.3 * 1.02) # 收紧1.3*1.02=1.326倍
cond3 = (dataframe["rsi"] < rsi_threshold * 0.8 * 0.98) # 收紧0.8*0.98=0.784倍
cond4 = (dataframe["close"] <= dataframe["bb_lowerband"] * 0.95 * 0.98) # 收紧0.95*0.98=0.931倍
cond5 = (dataframe["stochrsi_k"] < stochrsi_threshold * 0.8 * 0.98) # 收紧0.8*0.98=0.784倍
cond6 = ~bearish_signal_aligned # 保持熊市过滤
cond7 = ~stochrsi_overbought_aligned # 保持超买过滤
buy_condition = cond1 & cond2 & cond3 & cond4 & cond5 & cond6 & cond7
@ -821,11 +821,11 @@ class FreqaiPrimer(IStrategy):
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.98) # 收紧:*0.98
cond2 = (dataframe["volume_z_score"] > volume_z_score_threshold * 1.02) # 收紧:*1.02
cond3 = (dataframe["rsi"] < rsi_threshold * 0.98) # 收紧:*0.98
cond4 = (dataframe["close"] <= dataframe["bb_lowerband"] * 0.98) # 收紧:*0.98
cond5 = (dataframe["stochrsi_k"] < stochrsi_threshold * 0.98) # 收紧:*0.98
cond6 = ~bearish_signal_aligned
cond7 = ~stochrsi_overbought_aligned
buy_condition = cond1 & cond2 & cond3 & cond4 & cond5 & cond6 & cond7
@ -1104,26 +1104,26 @@ class FreqaiPrimer(IStrategy):
# 条件 1高阈值 &-price_value_divergence
cond1 = (
(dataframe["&-price_value_divergence"] > self.sell_threshold * float(self.exit_divergence_multiplier.value)) &
(dataframe["adx"] > float(self.exit_adx_threshold.value)) # 趋势强度过滤
(dataframe["&-price_value_divergence"] > self.sell_threshold * float(self.exit_divergence_multiplier.value) * 1.02) &
(dataframe["adx"] > float(self.exit_adx_threshold.value) * 1.02) # 收紧:提高阈值
)
# 条件 2超买信号
cond2 = (
(dataframe["rsi"] > float(self.exit_rsi_threshold.value)) &
(dataframe["stochrsi_k"] > float(self.exit_stochrsi_threshold.value)) & # StochRSI 超买
(dataframe["adx"] > float(self.exit_adx_threshold_overbought.value)) # 趋势强度
(dataframe["rsi"] > float(self.exit_rsi_threshold.value) * 1.02) &
(dataframe["stochrsi_k"] > float(self.exit_stochrsi_threshold.value) * 1.02) & # 收紧:提高阈值
(dataframe["adx"] > float(self.exit_adx_threshold_overbought.value) * 1.02) # 收紧:提高阈值
)
# 条件 3快速拉升退出
# 检测最近 5 根 K 线(约 15 分钟)涨幅超过阈值,且有最低利润要求
min_profit = float(self.exit_min_profit_threshold.value) # 最低利润要求
rapid_rise_threshold = self.linear_map(trend_score, 0, 100, float(self.exit_rapid_rise_bear.value), float(self.exit_rapid_rise_bull.value))
min_profit = float(self.exit_min_profit_threshold.value) * 1.02 # 收紧:提高最低利润要求
rapid_rise_threshold = self.linear_map(trend_score, 0, 100, float(self.exit_rapid_rise_bear.value) * 1.02, float(self.exit_rapid_rise_bull.value) * 1.02) # 收紧:提高阈值
cond3 = (
(dataframe["short_term_return"] > rapid_rise_threshold) & # 短期快速拉升
(dataframe["close"] / dataframe["close"].shift(5) - 1 > min_profit) & # 确保最低利润
(dataframe["stochrsi_k"] > float(self.exit_stochrsi_rapid.value)) & # 超买确认
(dataframe["volume_z_score"] > float(self.exit_volume_threshold.value))
(dataframe["stochrsi_k"] > float(self.exit_stochrsi_rapid.value) * 1.02) & # 收紧:提高阈值
(dataframe["volume_z_score"] > float(self.exit_volume_threshold.value) * 1.02) # 收紧:提高阈值
)
# 检测趋势状态
@ -1137,18 +1137,18 @@ class FreqaiPrimer(IStrategy):
return dataframe
# 上涨趋势下需要更强的卖出信号
cond1_bullish = (dataframe["&-price_value_divergence"] > self.sell_threshold * float(self.exit_bullish_divergence_mult.value))
cond2_bullish = (dataframe["rsi"] > float(self.exit_bullish_rsi.value)) & (dataframe["stochrsi_k"] > float(self.exit_bullish_stochrsi.value)) & (dataframe["adx"] > float(self.exit_bullish_adx.value))
cond3_bullish = (dataframe["short_term_return"] > float(self.exit_bullish_return.value)) & (dataframe["stochrsi_k"] > float(self.exit_bullish_stochrsi_rapid.value))
cond1_bullish = (dataframe["&-price_value_divergence"] > self.sell_threshold * float(self.exit_bullish_divergence_mult.value) * 1.02)
cond2_bullish = (dataframe["rsi"] > float(self.exit_bullish_rsi.value) * 1.02) & (dataframe["stochrsi_k"] > float(self.exit_bullish_stochrsi.value) * 1.02) & (dataframe["adx"] > float(self.exit_bullish_adx.value) * 1.02)
cond3_bullish = (dataframe["short_term_return"] > float(self.exit_bullish_return.value) * 1.02) & (dataframe["stochrsi_k"] > float(self.exit_bullish_stochrsi_rapid.value) * 1.02)
sell_condition = (cond1_bullish & cond2_bullish) | (cond1_bullish & cond3_bullish) | (cond2_bullish & cond3_bullish)
logger.info(f"[{pair}] 🚀 上涨趋势策略:严格出场条件")
elif trend_status == "bearish":
# 下跌趋势:宽松出场条件,快速止盈止损
cond1_bearish = (dataframe["&-price_value_divergence"] > self.sell_threshold * float(self.exit_bearish_divergence_mult.value))
cond2_bearish = (dataframe["rsi"] > float(self.exit_bearish_rsi.value)) & (dataframe["stochrsi_k"] > float(self.exit_bearish_stochrsi.value)) & (dataframe["adx"] > float(self.exit_bearish_adx.value))
cond3_bearish = (dataframe["short_term_return"] > float(self.exit_bearish_return.value)) & (dataframe["stochrsi_k"] > float(self.exit_bearish_stochrsi_rapid.value))
cond1_bearish = (dataframe["&-price_value_divergence"] > self.sell_threshold * float(self.exit_bearish_divergence_mult.value) * 1.02)
cond2_bearish = (dataframe["rsi"] > float(self.exit_bearish_rsi.value) * 1.02) & (dataframe["stochrsi_k"] > float(self.exit_bearish_stochrsi.value) * 1.02) & (dataframe["adx"] > float(self.exit_bearish_adx.value) * 1.02)
cond3_bearish = (dataframe["short_term_return"] > float(self.exit_bearish_return.value) * 1.02) & (dataframe["stochrsi_k"] > float(self.exit_bearish_stochrsi_rapid.value) * 1.02)
sell_condition = cond1_bearish | cond2_bearish | cond3_bearish # 任一条件即可卖出
logger.info(f"[{pair}] 📉 下跌趋势策略:宽松出场条件")