有交易了,陪的不多
Some checks are pending
Update Docker Hub Description / dockerHubDescription (push) Waiting to run
Some checks are pending
Update Docker Hub Description / dockerHubDescription (push) Waiting to run
This commit is contained in:
parent
8f4c374e6b
commit
c0d0e0290f
@ -85,6 +85,21 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
dataframe["macd"] = np.nan
|
||||
dataframe["macdsignal"] = np.nan
|
||||
|
||||
# 检查并填充 NaN 值
|
||||
if "macd" in dataframe.columns and "macdsignal" in dataframe.columns:
|
||||
dataframe["macd"] = dataframe["macd"].fillna(method='ffill').fillna(0)
|
||||
dataframe["macdsignal"] = dataframe["macdsignal"].fillna(method='ffill').fillna(0)
|
||||
else:
|
||||
logger.error("MACD 或 MACD 信号列缺失,无法生成买入信号。尝试重新计算 MACD 列。")
|
||||
try:
|
||||
macd = ta.MACD(dataframe, fastperiod=12, slowperiod=26, signalperiod=9)
|
||||
dataframe["macd"] = macd["macd"].fillna(method='ffill').fillna(0)
|
||||
dataframe["macdsignal"] = macd["macdsignal"].fillna(method='ffill').fillna(0)
|
||||
logger.info("MACD 列已成功重新计算。")
|
||||
except Exception as e:
|
||||
logger.error(f"重新计算 MACD 列时出错:{str(e)}")
|
||||
raise ValueError("DataFrame 缺少必要的 MACD 列且无法重新计算。")
|
||||
|
||||
# 检查 MACD 列是否存在
|
||||
if "macd" not in dataframe.columns or "macdsignal" not in dataframe.columns:
|
||||
logger.error("MACD 或 MACD 信号列缺失,无法生成买入信号")
|
||||
@ -283,7 +298,9 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
exit_long_conditions = [
|
||||
(df["rsi"] > df["sell_rsi_pred"]), # RSI 高于卖出阈值
|
||||
(df["volume"] > df["volume"].rolling(window=10).mean()), # 成交量高于近期均值
|
||||
(df["close"] < df["bb_middleband"]) # 价格低于布林带中轨
|
||||
(df["close"] < df["bb_middleband"]), # 价格低于布林带中轨
|
||||
(df["close"] < df["bb_lowerband"].shift(1)), # 当前价格低于上一周期的布林带下轨
|
||||
(df["volume"] < df["volume"].shift(1) * 0.9) # 当前成交量低于上一周期的10%
|
||||
]
|
||||
if exit_long_conditions:
|
||||
df.loc[
|
||||
@ -309,12 +326,15 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
enter_long_conditions = [
|
||||
(df["rsi"] < df["buy_rsi_pred"]), # RSI 低于买入阈值
|
||||
(df["volume"] > df["volume"].rolling(window=10).mean() * 1.2), # 成交量高于近期均值20%
|
||||
(df["close"] > df["bb_middleband"]) # 价格高于布林带中轨
|
||||
(df["close"] > df["bb_middleband"]), # 价格高于布林带中轨
|
||||
(df["close"] > df["bb_upperband"].shift(1)), # 当前价格高于上一周期的布林带上轨
|
||||
(df["volume"] > df["volume"].shift(1) * 1.1) # 当前成交量高于上一周期的10%
|
||||
]
|
||||
|
||||
# 如果 MACD 列存在,则添加 MACD 金叉条件
|
||||
if "macd" in df.columns and "macdsignal" in df.columns:
|
||||
enter_long_conditions.append((df["macd"] > df["macdsignal"]))
|
||||
enter_long_conditions.append((df["macd"] > df["macd"].shift(1))) # MACD 上升趋势
|
||||
|
||||
# 确保模型预测为买入
|
||||
enter_long_conditions.append((df["do_predict"] == 1))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user