This commit is contained in:
zhangkun9038@dingtalk.com 2025-08-30 14:37:45 +08:00
parent 9c0d86fc11
commit 3109e1064d

View File

@ -12,12 +12,12 @@ import datetime
logger = logging.getLogger(__name__)
class FreqaiPrimer(IStrategy):
# 策略参数 - 设置基于市场状态的动态ROI
# 策略参数 - 调整以提高单笔盈利潜力
minimal_roi = {
"0": 0.08, # 8% ROI (10 分钟内)
"60": 0.05, # 5% ROI (1 小时)
"180": 0.02, # 2% ROI (3 小时)
"360": 0.01 # 1% ROI (6 小时)
"0": 0.05, # 5% ROI (10 分钟内)
"60": 0.03, # 3% ROI (1 小时)
"180": 0.01, # 1% ROI (3 小时)
"360": 0.005 # 0.5% ROI (6 小时)
}
stoploss = -0.15 # 固定止损 -15% (大幅放宽止损以承受更大波动)
@ -57,8 +57,8 @@ class FreqaiPrimer(IStrategy):
bb_length = 20
bb_std = 2.0
rsi_length = 14
rsi_overbought = 62 # 提高超买阈值,减少过早卖出
rsi_oversold = 38 # 进一步放宽超卖阈值,增加优质入场信号
rsi_overbought = 58 # 超买阈值
rsi_oversold = 42 # 放宽超卖阈值,增加入场信号
# 剧烈拉升检测参数
H1_MAX_CANDLES = 200 # 检查最近200根1h K线
@ -270,14 +270,13 @@ class FreqaiPrimer(IStrategy):
trend_reversal = merged_data['rsi_15m'] > 75
# 动态调整退出条件 - 提高ATR倍数以增加单笔盈利潜力
# 强劲趋势中:更激进地持有提高ATR倍数到6.5倍
dataframe.loc[strong_trend & ((dataframe['close'] > dataframe['open'] + dataframe['atr'] * 6.5) | (basic_exit & trend_reversal)), 'exit_long'] = 1
# 强劲趋势中:大幅提高ATR倍数到5.5倍,充分利用趋势利润
dataframe.loc[strong_trend & ((dataframe['close'] > dataframe['open'] + dataframe['atr'] * 5.5) | (basic_exit & trend_reversal)), 'exit_long'] = 1
# 一般趋势中提高到4.5倍ATR退出
dataframe.loc[normal_trend & ((dataframe['close'] > dataframe['open'] + dataframe['atr'] * 4.5) | basic_exit), 'exit_long'] = 1
# 一般趋势中提高到4倍ATR退出
dataframe.loc[normal_trend & ((dataframe['close'] > dataframe['open'] + dataframe['atr'] * 4) | basic_exit), 'exit_long'] = 1
# 非趋势或弱势保持2倍ATR退出
dataframe.loc[~strong_trend & ~normal_trend & (basic_exit | (dataframe['close'] > dataframe['open'] + dataframe['atr'] * 2)), 'exit_long'] = 1
# 记录退出决策日志
if len(dataframe[dataframe['exit_long'] == 1]) > 0:
@ -386,13 +385,13 @@ class FreqaiPrimer(IStrategy):
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
current_state = dataframe['market_state'].iloc[-1] if 'market_state' in dataframe.columns else 'unknown'
# 定义高收益潜力的渐进式止盈水平
# 定义更激进的渐进式止盈水平,提高收益上限
profit_levels = {
# 状态: [(止盈触发利润, 止盈比例)]
'strong_bull': [(0.04, 0.15), (0.08, 0.3), (0.12, 0.45), (0.16, 0.6), (0.20, 0.75), (0.25, 0.9)], # 强劲牛市更激进的渐进止盈
'weak_bull': [(0.03, 0.2), (0.06, 0.4), (0.09, 0.6), (0.13, 0.8), (0.16, 0.95)], # 弱牛市提高止盈目标
'neutral': [(0.02, 0.3), (0.04, 0.55), (0.07, 0.8), (0.10, 0.95)], # 中性市场适度提高目标
'bear': [(0.01, 0.5), (0.025, 0.85), (0.04, 1.0)] # 熊市的渐进止盈(更保守)
'strong_bull': [(0.03, 0.2), (0.06, 0.35), (0.09, 0.5), (0.12, 0.65), (0.15, 0.8)], # 强劲牛市的渐进止盈,提高目标
'weak_bull': [(0.02, 0.25), (0.04, 0.45), (0.07, 0.7), (0.10, 0.9)], # 弱牛市的渐进止盈
'neutral': [(0.015, 0.35), (0.03, 0.6), (0.05, 0.85)], # 中性市场的渐进止盈
'bear': [(0.01, 0.6), (0.02, 0.9), (0.03, 1.0)] # 熊市的渐进止盈(更保守)
}
# 默认使用中性市场的止盈设置
@ -416,20 +415,13 @@ class FreqaiPrimer(IStrategy):
def adjust_trade_position(self, trade: 'Trade', current_time, current_rate: float,
current_profit: float, min_stake: float, max_stake: float, **kwargs) -> float:
"""
高级加仓逻辑在强劲趋势中增加加仓次数和额度
根据用户要求实现加仓逻辑
- 加仓间隔设置为0.0474.7%回调
- 加仓额度为: (stake_amount / 2) ^ (加仓次数)
- 根据市场状态动态调整加仓参数
- 加仓额度为: (stake_amount / 2) ^ (加仓次数 - 1)
"""
# 检查是否已启用加仓
if not hasattr(self, 'max_entry_adjustments'):
# 在强劲牛市中增加最大加仓次数
dataframe, _ = self.dp.get_analyzed_dataframe(trade.pair, self.timeframe)
current_state = dataframe['market_state'].iloc[-1] if 'market_state' in dataframe.columns else 'neutral'
if current_state == 'strong_bull':
self.max_entry_adjustments = 4 # 强劲牛市中增加到4次加仓
else:
self.max_entry_adjustments = 3 # 其他市场状态保持3次
self.max_entry_adjustments = 3 # 设置最大加仓次数
# 获取当前交易对
pair = trade.pair