stockrsi 85分以上阻止开多

This commit is contained in:
Ubuntu 2025-07-05 23:50:07 +08:00
parent c89de22a7a
commit bf60379be7

View File

@ -193,7 +193,10 @@ class FreqaiPrimer(IStrategy):
dataframe["volume_mean_20"] = dataframe["volume"].rolling(20).mean()
dataframe["volume_std_20"] = dataframe["volume"].rolling(20).std()
dataframe["volume_z_score"] = (dataframe["volume"] - dataframe["volume_mean_20"]) / dataframe["volume_std_20"]
# 计算 STOCHRSI
dataframe['stochrsi_k'], dataframe['stochrsi_d'] = stochrsi(dataframe['close'], length=14, k=3, d=3, fillna=True)
# 计算 MASTCHRIS3 (假设为 STOCHRSI K 的 3 周期 SMA)
dataframe['mastchris3'] = sma(dataframe['stochrsi_k'], length=3)
# 数据清理
for col in ["ema200", "bb_upperband", "bb_middleband", "bb_lowerband", "rsi", "volume_z_score", "&-price_value_divergence", "price_value_divergence"]:
dataframe[col] = dataframe[col].replace([np.inf, -np.inf], 0).ffill().fillna(0)
@ -564,7 +567,14 @@ class FreqaiPrimer(IStrategy):
# 调试日志:记录输入参数
logger.debug(f"[{pair}] confirm_trade_entry called with rate={rate}, type(rate)={type(rate)}, "
f"amount={amount}, order_type={order_type}, time_in_force={time_in_force}")
# 获取当前数据
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
last_candle = dataframe.iloc[-1]
# 检查 STOCHRSI K 和 MASTCHRIS3 是否均 > 85
if last_candle['stochrsi_k'] > 85 and last_candle['mastchris3'] > 85:
return False # 阻止开多
# 检查 rate 是否有效
if not isinstance(rate, (float, int)) or rate is None:
logger.error(f"[{pair}] Invalid rate value: {rate} (type: {type(rate)}). Skipping trade entry.")