merged
This commit is contained in:
commit
b154f5f95d
@ -67,7 +67,7 @@
|
||||
"freqaimodel": "CatboostClassifier",
|
||||
"purge_old_models": 2,
|
||||
"train_period_days": 15,
|
||||
"identifier": "test18",
|
||||
"identifier": "test52",
|
||||
"train_period_days": 30,
|
||||
"backtest_period_days": 10,
|
||||
"live_retrain_hours": 0,
|
||||
|
||||
@ -40,14 +40,25 @@ services:
|
||||
# --strategy FreqaiExampleStrategy
|
||||
# --strategy FreqaiExampleHybridStrategy
|
||||
# --strategy-path /freqtrade/templates
|
||||
# command: >
|
||||
# backtesting
|
||||
# --logfile /freqtrade/user_data/logs/freqtrade.log
|
||||
# --freqaimodel XGBoostRegressor
|
||||
# --config /freqtrade/config_examples/config_freqai.okx.json
|
||||
# --strategy-path /freqtrade/templates
|
||||
# --strategy FreqaiExampleStrategy
|
||||
# --timerange 20250310-20250410
|
||||
# --export trades
|
||||
command: >
|
||||
backtesting
|
||||
hyperopt
|
||||
--logfile /freqtrade/user_data/logs/freqtrade.log
|
||||
--freqaimodel XGBoostRegressor
|
||||
--freqaimodel XGBoostClassifier
|
||||
--config /freqtrade/config_examples/config_freqai.okx.json
|
||||
--strategy-path /freqtrade/templates
|
||||
--strategy FreqaiExampleStrategy
|
||||
--timerange 20250320-20250420
|
||||
--export trades
|
||||
--timerange 20250301-20250420
|
||||
--hyperopt-loss SharpeHyperOptLoss
|
||||
--spaces buy sell roi stoploss trailing
|
||||
-e 200
|
||||
|
||||
|
||||
|
||||
@ -5,28 +5,28 @@
|
||||
"max_open_trades": 4
|
||||
},
|
||||
"buy": {
|
||||
"buy_rsi": 37
|
||||
"buy_rsi": 28
|
||||
},
|
||||
"sell": {
|
||||
"sell_rsi": 70
|
||||
"sell_rsi": 89
|
||||
},
|
||||
"protection": {},
|
||||
"roi": {
|
||||
"0": 0.135,
|
||||
"9": 0.015,
|
||||
"30": 0.007,
|
||||
"102": 0
|
||||
"0": 0.08099999999999999,
|
||||
"7": 0.038,
|
||||
"23": 0.013,
|
||||
"63": 0
|
||||
},
|
||||
"stoploss": {
|
||||
"stoploss": -0.239
|
||||
"stoploss": -0.236
|
||||
},
|
||||
"trailing": {
|
||||
"trailing_stop": true,
|
||||
"trailing_stop_positive": 0.243,
|
||||
"trailing_stop_positive_offset": 0.309,
|
||||
"trailing_stop_positive": 0.139,
|
||||
"trailing_stop_positive_offset": 0.14800000000000002,
|
||||
"trailing_only_offset_is_reached": true
|
||||
}
|
||||
},
|
||||
"ft_stratparam_v": 1,
|
||||
"export_time": "2025-04-23 03:44:58.374765+00:00"
|
||||
}
|
||||
"export_time": "2025-04-23 09:36:34.486164+00:00"
|
||||
}
|
||||
|
||||
@ -5,37 +5,26 @@ import talib.abstract as ta
|
||||
from pandas import DataFrame
|
||||
from technical import qtpylib
|
||||
from freqtrade.strategy import IntParameter, IStrategy, DecimalParameter
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class FreqaiExampleStrategy(IStrategy):
|
||||
# ROI 参数:保持 DecimalParameter 对象,不使用 .value
|
||||
|
||||
minimal_roi = {
|
||||
"0": DecimalParameter(low=0.01, high=0.15, default=0.02, space="roi", optimize=True, load=True),
|
||||
"9": DecimalParameter(low=0.005, high=0.05, default=0.015, space="roi", optimize=True, load=True),
|
||||
"30": DecimalParameter(low=0.005, high=0.03, default=0.007, space="roi", optimize=True, load=True),
|
||||
"102": DecimalParameter(low=0.0, high=0.01, default=0.0, space="roi", optimize=True, load=True)
|
||||
"0": DecimalParameter(low=0.01, high=0.05, default=0.02, space="roi", optimize=True, load=True).value,
|
||||
"360": DecimalParameter(low=0.005, high=0.02, default=0.01, space="roi", optimize=True, load=True).value
|
||||
}
|
||||
# 止损参数:保持 DecimalParameter 对象
|
||||
stoploss = DecimalParameter(low=-0.3, high=-0.02, default=-0.07, space="stoploss", optimize=True, load=True)
|
||||
# 最大开仓数
|
||||
max_open_trades = IntParameter(low=1, high=10, default=4, space="misc", optimize=False, load=True)
|
||||
# 追踪止损参数:替换硬编码为 DecimalParameter
|
||||
stoploss = DecimalParameter(low=-0.1, high=-0.02, default=-0.07, space="stoploss", optimize=True, load=True).value
|
||||
trailing_stop = True
|
||||
trailing_stop_positive = DecimalParameter(low=0.005, high=0.3, default=0.01, space="trailing", optimize=True, load=True)
|
||||
trailing_stop_positive_offset = DecimalParameter(low=0.01, high=0.4, default=0.02, space="trailing", optimize=True, load=True)
|
||||
trailing_only_offset_is_reached = False
|
||||
|
||||
# 买卖参数:保持不变,已正确
|
||||
buy_rsi = IntParameter(low=10, high=50, default=30, space="buy", optimize=True, load=True)
|
||||
sell_rsi = IntParameter(low=50, high=90, default=70, space="sell", optimize=True, load=True)
|
||||
|
||||
# 其他设置
|
||||
trailing_stop_positive = 0.01
|
||||
trailing_stop_positive_offset = 0.02
|
||||
process_only_new_candles = True
|
||||
use_exit_signal = True
|
||||
startup_candle_count: int = 40
|
||||
can_short = False
|
||||
|
||||
buy_rsi = IntParameter(low=10, high=50, default=30, space="buy", optimize=True, load=True)
|
||||
sell_rsi = IntParameter(low=50, high=90, default=70, space="sell", optimize=True, load=True)
|
||||
|
||||
plot_config = {
|
||||
"main_plot": {},
|
||||
"subplots": {
|
||||
@ -44,18 +33,6 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
},
|
||||
}
|
||||
|
||||
def __init__(self, config: dict) -> None:
|
||||
super().__init__(config)
|
||||
# 调试输出,确认参数加载
|
||||
print(f"buy_rsi: {self.buy_rsi.value}")
|
||||
print(f"sell_rsi: {self.sell_rsi.value}")
|
||||
print(f"stoploss: {self.stoploss.value}")
|
||||
print(f"max_open_trades: {self.max_open_trades.value}")
|
||||
print(f"minimal_roi: { {k: v.value for k, v in self.minimal_roi.items()} }")
|
||||
print(f"trailing_stop_positive: {self.trailing_stop_positive.value}")
|
||||
print(f"trailing_stop_positive_offset: {self.trailing_stop_positive_offset.value}")
|
||||
|
||||
|
||||
def feature_engineering_expand_all(self, dataframe: DataFrame, period: int, metadata: dict, **kwargs) -> DataFrame:
|
||||
dataframe["%-rsi-period"] = ta.RSI(dataframe, timeperiod=period)
|
||||
dataframe["%-mfi-period"] = ta.MFI(dataframe, timeperiod=period)
|
||||
@ -135,10 +112,10 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
enter_long_conditions = [
|
||||
qtpylib.crossed_above(df["rsi"], self.buy_rsi.value),
|
||||
df["tema"] > df["tema"].shift(1),
|
||||
df["%-relative_volume-period"] > 1.2,
|
||||
df["close"] > df["bb_middleband"],
|
||||
df["volume"] > 0,
|
||||
df["do_predict"] == 1,
|
||||
df["&-up_or_down"] == "up"
|
||||
#df["%-bb_width-period_4h"] > 0.05
|
||||
]
|
||||
if enter_long_conditions:
|
||||
df.loc[
|
||||
@ -172,3 +149,4 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
if rate > (last_candle["close"] * (1 + 0.0025)):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user