fix float to decimal
This commit is contained in:
parent
8fd5165394
commit
ac91270bd6
@ -632,26 +632,26 @@ class FreqaiPrimer(IStrategy):
|
||||
|
||||
# 条件 1:高阈值 &-price_value_divergence
|
||||
cond1 = (
|
||||
(dataframe["&-price_value_divergence"] > self.sell_threshold * self.exit_divergence_multiplier) &
|
||||
(dataframe["adx"] > self.exit_adx_threshold) # 趋势强度过滤
|
||||
(dataframe["&-price_value_divergence"] > self.sell_threshold * float(self.exit_divergence_multiplier.value)) &
|
||||
(dataframe["adx"] > float(self.exit_adx_threshold.value)) # 趋势强度过滤
|
||||
)
|
||||
|
||||
# 条件 2:超买信号
|
||||
cond2 = (
|
||||
(dataframe["rsi"] > self.exit_rsi_threshold) &
|
||||
(dataframe["stochrsi_k"] > self.exit_stochrsi_threshold) & # StochRSI 超买
|
||||
(dataframe["adx"] > self.exit_adx_threshold_overbought) # 趋势强度
|
||||
(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)) # 趋势强度
|
||||
)
|
||||
|
||||
# 条件 3:快速拉升退出
|
||||
# 检测最近 5 根 K 线(约 15 分钟)涨幅超过阈值,且有最低利润要求
|
||||
min_profit = self.exit_min_profit_threshold # 最低利润要求
|
||||
rapid_rise_threshold = self.linear_map(trend_score, 0, 100, self.exit_rapid_rise_bear, self.exit_rapid_rise_bull)
|
||||
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))
|
||||
cond3 = (
|
||||
(dataframe["short_term_return"] > rapid_rise_threshold) & # 短期快速拉升
|
||||
(dataframe["close"] / dataframe["close"].shift(5) - 1 > min_profit) & # 确保最低利润
|
||||
(dataframe["stochrsi_k"] > self.exit_stochrsi_rapid) & # 超买确认
|
||||
(dataframe["volume_z_score"] > self.exit_volume_threshold)
|
||||
(dataframe["stochrsi_k"] > float(self.exit_stochrsi_rapid.value)) & # 超买确认
|
||||
(dataframe["volume_z_score"] > float(self.exit_volume_threshold.value))
|
||||
)
|
||||
|
||||
# 检测趋势状态
|
||||
@ -660,34 +660,34 @@ class FreqaiPrimer(IStrategy):
|
||||
# 根据趋势状态调整出场策略
|
||||
if trend_status == "bullish":
|
||||
# 上涨趋势:严格出场条件,让利润奔跑
|
||||
if trend_score > self.exit_bullish_trend_score_max:
|
||||
if trend_score > float(self.exit_bullish_trend_score_max.value):
|
||||
logger.info(f"[{pair}] 🚀 强劲上涨趋势,拒绝卖出")
|
||||
return dataframe
|
||||
|
||||
# 上涨趋势下需要更强的卖出信号
|
||||
cond1_bullish = (dataframe["&-price_value_divergence"] > self.sell_threshold * self.exit_bullish_divergence_mult)
|
||||
cond2_bullish = (dataframe["rsi"] > self.exit_bullish_rsi) & (dataframe["stochrsi_k"] > self.exit_bullish_stochrsi) & (dataframe["adx"] > self.exit_bullish_adx)
|
||||
cond3_bullish = (dataframe["short_term_return"] > self.exit_bullish_return) & (dataframe["stochrsi_k"] > self.exit_bullish_stochrsi_rapid)
|
||||
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))
|
||||
|
||||
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 * self.exit_bearish_divergence_mult)
|
||||
cond2_bearish = (dataframe["rsi"] > self.exit_bearish_rsi) & (dataframe["stochrsi_k"] > self.exit_bearish_stochrsi) & (dataframe["adx"] > self.exit_bearish_adx)
|
||||
cond3_bearish = (dataframe["short_term_return"] > self.exit_bearish_return) & (dataframe["stochrsi_k"] > self.exit_bearish_stochrsi_rapid)
|
||||
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))
|
||||
|
||||
sell_condition = cond1_bearish | cond2_bearish | cond3_bearish # 任一条件即可卖出
|
||||
logger.info(f"[{pair}] 📉 下跌趋势策略:宽松出场条件")
|
||||
|
||||
else: # ranging
|
||||
# 震荡趋势:使用原策略
|
||||
if trend_score > self.exit_ranging_trend_score_max:
|
||||
if trend_score > float(self.exit_ranging_trend_score_max.value):
|
||||
logger.info(f"[{pair}] ⚖️ 震荡趋势但得分较高,拒绝卖出")
|
||||
return dataframe
|
||||
|
||||
if trend_score > self.exit_ranging_trend_score_threshold:
|
||||
if trend_score > float(self.exit_ranging_trend_score_threshold.value):
|
||||
sell_condition = (cond1 & cond2) | (cond1 & cond3) | (cond2 & cond3) # 中等趋势,至少两个条件满足
|
||||
logger.info(f"[{pair}] ⚖️ 震荡趋势策略:标准出场条件")
|
||||
else:
|
||||
@ -703,8 +703,8 @@ class FreqaiPrimer(IStrategy):
|
||||
adx_value = dataframe["adx"].iloc[-1] if not dataframe["adx"].isna().all() else np.nan
|
||||
short_term_return = dataframe["short_term_return"].iloc[-1] if not dataframe["short_term_return"].isna().all() else np.nan
|
||||
logger.info(f"[{pair}] 卖出条件检查 - "
|
||||
f"&-price_value_divergence={divergence_value:.6f} > {self.sell_threshold * 1.06:.6f}: {cond1.iloc[-1]}, "
|
||||
f"rsi={rsi_value:.2f} > 75 & stochrsi_k={stochrsi_value:.2f} > 80: {cond2.iloc[-1]}, "
|
||||
f"&-price_value_divergence={divergence_value:.6f} > {self.sell_threshold * float(self.exit_divergence_multiplier.value):.6f}: {cond1.iloc[-1]}, "
|
||||
f"rsi={rsi_value:.2f} > {float(self.exit_rsi_threshold.value)} & stochrsi_k={stochrsi_value:.2f} > {float(self.exit_stochrsi_threshold.value)}: {cond2.iloc[-1]}, "
|
||||
f"short_term_return={short_term_return:.2f}% > {rapid_rise_threshold:.2f}% & profit > {min_profit*100:.2f}%: {cond3.iloc[-1]}, "
|
||||
f"adx={adx_value:.2f}, trend_score={trend_score:.2f}")
|
||||
else:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user