降低入场门槛+1
This commit is contained in:
parent
91eff14872
commit
8765d12e61
@ -361,53 +361,31 @@ class FreqaiPrimer(IStrategy):
|
||||
if 'market_state' not in dataframe.columns:
|
||||
dataframe['market_state'] = 'neutral'
|
||||
|
||||
# ======================== 出场条件多维度评分 ========================
|
||||
# 条件1: 价格突破布林带上轨(使用可优化的偏差参数)
|
||||
breakout_condition = dataframe['close'] >= dataframe['bb_upper_1h'] * self.exit_bb_upper_deviation.value
|
||||
|
||||
# 条件2: 成交量显著放大(使用可优化的成交量乘数)
|
||||
volume_spike = dataframe['volume'] > dataframe['volume_ma'] * self.exit_volume_multiplier.value
|
||||
|
||||
# 条件3: MACD 下降趋势
|
||||
macd_downward = dataframe['macd_1h'] < dataframe['macd_signal_1h']
|
||||
|
||||
# 条件4: RSI 进入超买区域(市场自适应)
|
||||
# 根据市场状态调整RSI阈值
|
||||
def get_exit_rsi_threshold(row):
|
||||
market_state = row.get('market_state', 'neutral')
|
||||
if market_state == 'strong_bull':
|
||||
return self.exit_rsi_threshold.value + 5 # 强牛市提高阈值,让利润奔跑
|
||||
elif market_state == 'weak_bull':
|
||||
return self.exit_rsi_threshold.value
|
||||
else:
|
||||
return self.exit_rsi_threshold.value - 5 # 弱市降低阈值,及时止盈
|
||||
# ======================== 巨不下器的出场逻辑 ========================
|
||||
# 极其区慢,给利润奔跑的机会
|
||||
|
||||
rsi_thresholds = dataframe.apply(get_exit_rsi_threshold, axis=1)
|
||||
rsi_overbought = dataframe['rsi_1h'] > rsi_thresholds
|
||||
|
||||
# 评分计算
|
||||
condition_score = (
|
||||
breakout_condition.astype(int) +
|
||||
volume_spike.astype(int) +
|
||||
macd_downward.astype(int) +
|
||||
rsi_overbought.astype(int)
|
||||
# 条件1: RSI极度超买(大于75才考虑出场)
|
||||
rsi_extreme_overbought = dataframe['rsi_1h'] > 75
|
||||
|
||||
# 条件2: 趋势大幅反转(超卖)
|
||||
trend_extreme_reversal = dataframe['rsi_1h'] < 20
|
||||
|
||||
# 条件3: MACD死亡交叉(严格的反转信号)
|
||||
macd_death_cross = (
|
||||
(dataframe['macd_1h'] < dataframe['macd_signal_1h']) &
|
||||
(dataframe['macd_1h'].shift(1) >= dataframe['macd_signal_1h'].shift(1))
|
||||
)
|
||||
|
||||
# 触发条件:至少1个条件满足(从≥2降低到≥1,极致放宽)
|
||||
final_condition = condition_score >= 1
|
||||
# 综合成出条件(需要需要偏保守,不然遍地开花)
|
||||
final_condition = (
|
||||
rsi_extreme_overbought |
|
||||
trend_extreme_reversal |
|
||||
macd_death_cross
|
||||
)
|
||||
|
||||
# 设置出场信号
|
||||
dataframe.loc[final_condition, 'exit_long'] = 1
|
||||
|
||||
# 增强调试信息
|
||||
#logger.info(f"[{metadata['pair']}] 出场条件检查:")
|
||||
#logger.info(f" - 价格突破布林带上轨: {breakout_condition.sum()} 次")
|
||||
#logger.info(f" - 成交量显著放大: {volume_spike.sum()} 次")
|
||||
#logger.info(f" - MACD 下降趋势: {macd_downward.sum()} 次")
|
||||
#logger.info(f" - RSI 超买: {rsi_overbought.sum()} 次")
|
||||
#logger.info(f" - 最终条件: {final_condition.sum()} 次")
|
||||
#logger.info(f" - 使用参数: exit_bb_upper_deviation={self.exit_bb_upper_deviation.value}, exit_volume_multiplier={self.exit_volume_multiplier.value}, rsi_overbought={self.rsi_overbought.value}")
|
||||
|
||||
return dataframe
|
||||
|
||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
@ -415,59 +393,45 @@ class FreqaiPrimer(IStrategy):
|
||||
if 'prev_market_state' not in dataframe.columns:
|
||||
dataframe['prev_market_state'] = 'neutral'
|
||||
|
||||
# ======================== 优化版入场逻辑 - 增加信号频率 ========================
|
||||
# ======================== 极致激进版入场逻辑 ========================
|
||||
# 只需满足以下3个核心条件中的至少2个
|
||||
|
||||
# 条件1: RSI 超卖(核心条件,市场状态自适应)
|
||||
# 牛市中降低敏感性,熊市中提高敏感性
|
||||
# 条件1: RSI 超卖(市场自适应)
|
||||
rsi_oversold = 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'] < 55 if row['prev_market_state'] in ['strong_bull', 'weak_bull'] # 牛市放宽到55
|
||||
else row['rsi_1h'] < self.rsi_oversold.value, # 熊市使用优化值
|
||||
axis=1)
|
||||
|
||||
# 条件2: 价格下跌(轻度条件,放宽于严格的布林带检查)
|
||||
price_pullback = dataframe.apply(lambda row:
|
||||
row['close'] < dataframe['close'].shift(3).mean() * 1.02 if len(dataframe) > 3
|
||||
else False,
|
||||
axis=1)
|
||||
# 条件2: 价格低于1小时前的价格(简单下跌判断)
|
||||
price_lower = dataframe['close'] < dataframe['close'].shift(5).mean() # 比5根K线前更低
|
||||
|
||||
# 条件3: MACD 上升或即将上升(动态判断)
|
||||
# 条件3: MACD 看涨(最宽松的MACD判断)
|
||||
macd_bullish = (
|
||||
(dataframe['macd_1h'] > dataframe['macd_signal_1h']) | # MACD 已上穿
|
||||
((dataframe['macd_1h'] > dataframe['macd_signal_1h'].shift(1)) & # MACD 本根刚好上穿
|
||||
(dataframe['macd_1h'].shift(1) <= dataframe['macd_signal_1h'].shift(1)))
|
||||
(dataframe['macd_1h'] > dataframe['macd_signal_1h']) | # MACD已上穿
|
||||
(dataframe['macd_1h'] > 0) # 或MACD本身为正
|
||||
)
|
||||
|
||||
# 条件4: 趋势确认(更宽松,3个时间框架中至少1个上涨即可)
|
||||
trend_bullish = (
|
||||
(dataframe['trend_3m'] == 1) |
|
||||
(dataframe['trend_15m'] == 1) |
|
||||
(dataframe['trend_1h_ema'] == 1)
|
||||
# 条件4: 避免极度高位(可选保护)
|
||||
not_extreme_high = dataframe['close'] < dataframe['bb_upper_1h'] * 1.10 # 放宽到BB上轨上方10%
|
||||
|
||||
# 计算有多少个条件满足
|
||||
condition_count = (
|
||||
rsi_oversold.astype(int) +
|
||||
price_lower.astype(int) +
|
||||
macd_bullish.astype(int) +
|
||||
not_extreme_high.astype(int)
|
||||
)
|
||||
|
||||
# 条件5: 成交量放大(可选条件)
|
||||
volume_spike = dataframe['volume'] > dataframe['volume_ma'] * 1.0 # 放宽到1倍
|
||||
|
||||
# 条件6: 避免高位(价格低于1小时BB上轨)
|
||||
not_overbought = dataframe['close'] < dataframe['bb_upper_1h'] * 1.05
|
||||
|
||||
# 综合入场条件(极大降低难度)
|
||||
# 只需满足以下逻辑即可:
|
||||
# 1. RSI 超卖 OR 价格下跌
|
||||
# 2. AND MACD 看涨
|
||||
# 3. AND 趋势向上
|
||||
final_condition = (
|
||||
(rsi_oversold | price_pullback) &
|
||||
macd_bullish &
|
||||
trend_bullish &
|
||||
not_overbought
|
||||
)
|
||||
# 只需满足至少2个条件即可入场(极其宽松)
|
||||
final_condition = condition_count >= 2
|
||||
|
||||
# 设置入场信号
|
||||
dataframe.loc[final_condition, 'enter_long'] = 1
|
||||
|
||||
# 日志记录
|
||||
if dataframe['enter_long'].sum() > 0:
|
||||
logger.info(f"[{metadata['pair']}] ✅ 发现入场信号数量: {dataframe['enter_long'].sum()} 根K线")
|
||||
# 日志
|
||||
signal_count = dataframe['enter_long'].sum()
|
||||
if signal_count > 0:
|
||||
logger.info(f"[{metadata['pair']}] 🎯 发现 {signal_count} 个入场信号")
|
||||
|
||||
return dataframe
|
||||
|
||||
@ -540,22 +504,11 @@ class FreqaiPrimer(IStrategy):
|
||||
**kwargs,
|
||||
) -> bool:
|
||||
"""
|
||||
交易买入前的确认函数,用于最终决定是否执行交易
|
||||
此处实现剧烈拉升检查逻辑
|
||||
交易买入前的确认函数
|
||||
⚠️ 禁用剧烈拉升检测以增加交易频率
|
||||
"""
|
||||
# 默认允许交易
|
||||
allow_trade = True
|
||||
|
||||
# 仅对多头交易进行检查
|
||||
if side == 'long':
|
||||
# 检查是否处于剧烈拉升的不稳固区域
|
||||
is_unstable_region = self.detect_h1_rapid_rise(pair)
|
||||
if is_unstable_region:
|
||||
#logger.info(f"[{pair}] 由于检测到剧烈拉升,取消入场交易")
|
||||
allow_trade = False
|
||||
|
||||
# 如果没有阻止因素,允许交易
|
||||
return allow_trade
|
||||
# 允许所有符合条件的交易
|
||||
return True
|
||||
|
||||
def _check_add_position_conditions(self, pair: str, current_rate: float, current_profit: float,
|
||||
entry_count: int, initial_price: float, dataframe) -> dict:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user