stable1 6
This commit is contained in:
parent
6c634f9137
commit
36a7563923
@ -299,8 +299,14 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
# 改进卖出信号条件
|
||||
exit_long_conditions = [
|
||||
(dataframe["rsi"] > dataframe["sell_rsi_pred"]), # RSI 高于卖出阈值
|
||||
(dataframe["volume"] > dataframe["volume"].rolling(window=10).mean()), # 成交量高于近期均值
|
||||
(dataframe["close"] < dataframe["bb_middleband"]) # 价格低于布林带中轨
|
||||
(
|
||||
(dataframe["volume"] > dataframe["volume"].rolling(window=10).mean()) | # 成交量高于近期均值
|
||||
(dataframe["volume"] < dataframe["volume"].shift(1) * 0.9) # 当前成交量低于上一周期的10%
|
||||
),
|
||||
(
|
||||
(dataframe["close"] < dataframe["bb_middleband"]) | # 价格低于布林带中轨
|
||||
(dataframe["close"] < dataframe["bb_lowerband"].shift(1)) # 当前价格低于上一周期的布林带下轨
|
||||
)
|
||||
]
|
||||
if exit_long_conditions:
|
||||
dataframe.loc[
|
||||
@ -311,22 +317,28 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
def populate_entry_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
|
||||
# 改进买入信号条件
|
||||
# 检查 MACD 列是否存在
|
||||
if "macd" not in df.columns or "macdsignal" not in df.columns:
|
||||
if "macd" not in dataframe.columns or "macdsignal" not in dataframe.columns:
|
||||
logger.error("MACD 或 MACD 信号列缺失,无法生成买入信号。尝试重新计算 MACD 列。")
|
||||
|
||||
try:
|
||||
macd = ta.MACD(df, fastperiod=12, slowperiod=26, signalperiod=9)
|
||||
df["macd"] = macd["macd"]
|
||||
df["macdsignal"] = macd["macdsignal"]
|
||||
macd = ta.MACD(dataframe, fastperiod=12, slowperiod=26, signalperiod=9)
|
||||
dataframe["macd"] = macd["macd"]
|
||||
dataframe["macdsignal"] = macd["macdsignal"]
|
||||
logger.info("MACD 列已成功重新计算。")
|
||||
except Exception as e:
|
||||
logger.error(f"重新计算 MACD 列时出错:{str(e)}")
|
||||
raise ValueError("DataFrame 缺少必要的 MACD 列且无法重新计算。")
|
||||
|
||||
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"]) # 价格高于布林带中轨
|
||||
(dataframe["rsi"] < dataframe["buy_rsi_pred"]), # RSI 低于买入阈值
|
||||
(
|
||||
(dataframe["volume"] > dataframe["volume"].rolling(window=10).mean() * 1.2) | # 成交量高于近期均值20%
|
||||
(dataframe["volume"] > dataframe["volume"].shift(1) * 1.1) # 当前成交量高于上一周期的10%
|
||||
),
|
||||
(
|
||||
(dataframe["close"] > dataframe["bb_middleband"]) | # 价格高于布林带中轨
|
||||
(dataframe["close"] > dataframe["bb_upperband"].shift(1)) # 当前价格高于上一周期的布林带上轨
|
||||
)
|
||||
]
|
||||
|
||||
# 如果 MACD 列存在,则添加 MACD 金叉条件
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user