hyperopted

This commit is contained in:
zhangkun9038@dingtalk.com 2025-09-07 23:19:02 +08:00
parent 7b638c4a13
commit 34238eb875

View File

@ -117,9 +117,9 @@ class FreqaiPrimer(IStrategy):
dataframe['rsi_3m'] = ta.rsi(dataframe['close'], length=rsi_length_value)
# 新增 StochRSI 指标
stochrsi_3m = ta.stochrsi(dataframe['close'], length=14, rsi_length=14)
dataframe['stochrsi_k_3m'] = stochrsi_3m['STOCHRSIk_14_14_3_3']
dataframe['stochrsi_d_3m'] = stochrsi_3m['STOCHRSId_14_14_3_3']
stochrsi_3m = ta.stochrsi(dataframe['close'], length=rsi_length_value, rsi_length=rsi_length_value)
dataframe['stochrsi_k_3m'] = stochrsi_3m[f'STOCHRSIk_{rsi_length_value}_{rsi_length_value}_3_3']
dataframe['stochrsi_d_3m'] = stochrsi_3m[f'STOCHRSId_{rsi_length_value}_{rsi_length_value}_3_3']
# 新增 MACD 指标
macd_3m = ta.macd(dataframe['close'], fast=12, slow=26, signal=9)
@ -139,7 +139,7 @@ class FreqaiPrimer(IStrategy):
# 获取 15m 数据
df_15m = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe='15m')
df_15m['rsi_15m'] = ta.rsi(df_15m['close'], length=self.rsi_length)
df_15m['rsi_15m'] = ta.rsi(df_15m['close'], length=rsi_length_value)
# 计算15m时间框架的EMA50和EMA200
df_15m['ema_50_15m'] = ta.ema(df_15m['close'], length=50)
df_15m['ema_200_15m'] = ta.ema(df_15m['close'], length=200)
@ -330,7 +330,7 @@ class FreqaiPrimer(IStrategy):
macd_downward = dataframe['macd_1h'] < dataframe['macd_signal_1h']
# 条件4: RSI 进入超买区域
rsi_overbought = dataframe['rsi_1h'] > self.rsi_overbought
rsi_overbought = dataframe['rsi_1h'] > self.rsi_overbought.value
# 合并所有条件
final_condition = breakout_condition | volume_spike | macd_downward | rsi_overbought
@ -355,7 +355,7 @@ class FreqaiPrimer(IStrategy):
# 条件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'] < 45,
row['rsi_1h'] < 50 if row['prev_market_state'] in ['strong_bull', 'weak_bull'] else row['rsi_1h'] < self.rsi_oversold.value,
axis=1)
# 条件3: StochRSI 处于超卖区域(根据市场状态动态调整)