hyperopted
This commit is contained in:
parent
34238eb875
commit
a74000e3ba
@ -87,6 +87,15 @@ class FreqaiPrimer(IStrategy):
|
||||
rsi_overbought = IntParameter(50, 70, default=58, optimize=True, load=True, space='buy')
|
||||
rsi_oversold = IntParameter(30, 50, default=42, optimize=True, load=True, space='buy')
|
||||
|
||||
# 入场条件阈值参数
|
||||
bb_lower_deviation = DecimalParameter(1.01, 1.05, decimals=2, default=1.03, optimize=True, load=True, space='buy')
|
||||
rsi_bull_threshold = IntParameter(45, 55, default=50, optimize=True, load=True, space='buy')
|
||||
stochrsi_bull_threshold = IntParameter(30, 40, default=35, optimize=True, load=True, space='buy')
|
||||
stochrsi_neutral_threshold = IntParameter(20, 30, default=25, optimize=True, load=True, space='buy')
|
||||
volume_multiplier = DecimalParameter(1.2, 2.0, decimals=1, default=1.5, optimize=True, load=True, space='buy')
|
||||
bb_width_threshold = DecimalParameter(0.01, 0.03, decimals=3, default=0.02, optimize=True, load=True, space='buy')
|
||||
min_condition_count = IntParameter(2, 4, default=3, optimize=True, load=True, space='buy')
|
||||
|
||||
# 剧烈拉升检测参数 - 使用Hyperopt可优化参数
|
||||
h1_max_candles = IntParameter(100, 300, default=200, optimize=True, load=True, space='buy')
|
||||
h1_rapid_rise_threshold = DecimalParameter(0.05, 0.15, decimals=3, default=0.11, optimize=True, load=True, space='buy')
|
||||
@ -350,35 +359,35 @@ class FreqaiPrimer(IStrategy):
|
||||
dataframe['prev_market_state'] = 'neutral'
|
||||
|
||||
# 条件1: 价格接近布林带下轨(允许一定偏差)
|
||||
close_to_bb_lower_1h = (dataframe['close'] <= dataframe['bb_lower_1h'] * 1.03) # 放宽到3%偏差
|
||||
close_to_bb_lower_1h = (dataframe['close'] <= dataframe['bb_lower_1h'] * self.bb_lower_deviation.value) # 可优化偏差
|
||||
|
||||
# 条件2: RSI 不高于阈值(根据市场状态动态调整)
|
||||
# 为每一行创建动态阈值
|
||||
rsi_condition_1h = dataframe.apply(lambda row:
|
||||
row['rsi_1h'] < 50 if row['prev_market_state'] in ['strong_bull', 'weak_bull'] else row['rsi_1h'] < self.rsi_oversold.value,
|
||||
row['rsi_1h'] < self.rsi_bull_threshold.value if row['prev_market_state'] in ['strong_bull', 'weak_bull'] else row['rsi_1h'] < self.rsi_oversold.value,
|
||||
axis=1)
|
||||
|
||||
# 条件3: StochRSI 处于超卖区域(根据市场状态动态调整)
|
||||
stochrsi_condition_1h = dataframe.apply(lambda row:
|
||||
(row['stochrsi_k_1h'] < 35 and row['stochrsi_d_1h'] < 35) if row['prev_market_state'] in ['strong_bull', 'weak_bull']
|
||||
else (row['stochrsi_k_1h'] < 25 and row['stochrsi_d_1h'] < 25),
|
||||
(row['stochrsi_k_1h'] < self.stochrsi_bull_threshold.value and row['stochrsi_d_1h'] < self.stochrsi_bull_threshold.value) if row['prev_market_state'] in ['strong_bull', 'weak_bull']
|
||||
else (row['stochrsi_k_1h'] < self.stochrsi_neutral_threshold.value and row['stochrsi_d_1h'] < self.stochrsi_neutral_threshold.value),
|
||||
axis=1)
|
||||
|
||||
# 条件4: MACD 上升趋势
|
||||
macd_condition_1h = dataframe['macd_1h'] > dataframe['macd_signal_1h']
|
||||
|
||||
# 条件5: 成交量显著放大(可选条件)
|
||||
volume_spike = dataframe['volume'] > dataframe['volume_ma'] * 1.5
|
||||
volume_spike = dataframe['volume'] > dataframe['volume_ma'] * self.volume_multiplier.value
|
||||
|
||||
# 条件6: 布林带宽度过滤(避免窄幅震荡)
|
||||
bb_width = (dataframe['bb_upper_1h'] - dataframe['bb_lower_1h']) / dataframe['close']
|
||||
bb_width_condition = bb_width > 0.02 # 布林带宽度大于2%
|
||||
bb_width_condition = bb_width > self.bb_width_threshold.value # 可优化的布林带宽度阈值
|
||||
|
||||
# 辅助条件: 3m 和 15m 趋势确认(允许部分时间框架不一致)
|
||||
trend_confirmation = (dataframe['trend_3m'] == 1) | (dataframe['trend_15m'] == 1)
|
||||
|
||||
# 合并所有条件(减少强制性条件)
|
||||
# 至少满足5个条件中的3个
|
||||
# 至少满足多个条件中的一定数量
|
||||
condition_count = (
|
||||
close_to_bb_lower_1h.astype(int) +
|
||||
rsi_condition_1h.astype(int) +
|
||||
@ -387,7 +396,7 @@ class FreqaiPrimer(IStrategy):
|
||||
(volume_spike | bb_width_condition).astype(int) + # 成交量或布林带宽度满足其一即可
|
||||
trend_confirmation.astype(int)
|
||||
)
|
||||
final_condition = condition_count >= 3
|
||||
final_condition = condition_count >= self.min_condition_count.value
|
||||
|
||||
# 设置入场信号
|
||||
dataframe.loc[final_condition, 'enter_long'] = 1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user