From 9490a8e12ef8b85e1ad51ba2aab1c5c1a3c9a991 Mon Sep 17 00:00:00 2001 From: "zhangkun9038@dingtalk.com" Date: Tue, 29 Apr 2025 13:57:33 +0800 Subject: [PATCH] with v3 --- freqtrade/templates/FreqaiExampleStrategy.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/freqtrade/templates/FreqaiExampleStrategy.py b/freqtrade/templates/FreqaiExampleStrategy.py index f0ec9e2..7aebfb8 100644 --- a/freqtrade/templates/FreqaiExampleStrategy.py +++ b/freqtrade/templates/FreqaiExampleStrategy.py @@ -263,18 +263,29 @@ class FreqaiExampleStrategy(IStrategy): "buy_rsi_pred": 30, # Default RSI buy threshold "sell_rsi_pred": 70, # Default RSI sell threshold "stoploss_pred": -0.1, # Default stoploss - "roi_0_pred": 0.038 # Default ROI + "roi_0_pred": 0.038, # Default ROI + "do_predict": 0 # Default prediction flag } + # Initialize columns before any calculations for col, default_value in pred_columns.items(): if col not in dataframe.columns: logger.warning(f"Column {col} missing, initializing with default value {default_value}") dataframe[col] = default_value + else: + # Ensure column exists and has proper type + if dataframe[col].dtype not in [np.float64, np.int64]: + logger.warning(f"Column {col} has incorrect dtype {dataframe[col].dtype}, converting to float") + dataframe[col] = dataframe[col].astype(float) # Ensure no NaN values if dataframe[col].isna().any(): logger.warning(f"Column {col} contains NaN values, filling with default value {default_value}") dataframe[col] = dataframe[col].fillna(default_value) + + # Now perform calculations that depend on these columns + dataframe["sell_rsi_pred"] = dataframe["buy_rsi_pred"] + 20 + dataframe["sell_rsi_pred"] = dataframe["sell_rsi_pred"].fillna(dataframe["sell_rsi_pred"].median()) # 检查并处理 NaN 值 for col in pred_columns + ["&-sell_rsi", "&-stoploss", "&-roi_0"]: