允许提升盈利
This commit is contained in:
parent
bcf65f9f9d
commit
9f2684e414
@ -211,19 +211,9 @@ class FreqaiPrimer(IStrategy):
|
||||
if len(prevented_entries) > 0:
|
||||
logger.info(f"[{pair}] 总共阻止了 {len(prevented_entries)} 个潜在的入场信号")
|
||||
|
||||
# 调试:检查每个条件的触发情况
|
||||
print(f"Pair: {metadata['pair']}, Entry condition checks:")
|
||||
print(f" - Close <= bb_lower_3m * 1.03: {close_to_bb_lower.sum()} candles")
|
||||
print(f" - RSI_3m < {self.rsi_oversold}: {(dataframe['rsi_3m'] < self.rsi_oversold).sum()} candles")
|
||||
print(f" - RSI_15m < {self.rsi_oversold}: {(dataframe['rsi_15m'] < self.rsi_oversold).sum()} candles")
|
||||
print(f" - Trend_1h (Close > EMA_50_1h): {trend_1h.sum()} candles")
|
||||
print(f" - Volume > Volume_MA: {volume_condition.sum()} candles")
|
||||
print(f" - Bullish Engulfing or RSI_3m < {self.rsi_oversold - 5}: {special_condition.sum()} candles")
|
||||
# 调试:检查每个条件的触发情况(简化输出)
|
||||
if dataframe['enter_long'].sum() > 0:
|
||||
print(f"Entry signals found at:")
|
||||
print(dataframe[dataframe['enter_long'] == 1][['date', 'close', 'rsi_3m', 'rsi_15m', 'trend_1h', 'bullish_engulfing']])
|
||||
else:
|
||||
print("No entry signals generated.")
|
||||
logger.info(f"[{pair}] 发现入场信号数量: {dataframe['enter_long'].sum()}")
|
||||
|
||||
return dataframe
|
||||
|
||||
@ -280,14 +270,13 @@ class FreqaiPrimer(IStrategy):
|
||||
trend_reversal = merged_data['rsi_15m'] > 75
|
||||
|
||||
# 动态调整退出条件 - 提高ATR倍数以增加单笔盈利潜力
|
||||
# 强劲趋势中:提高到4.5倍ATR才退出,给利润更多增长空间
|
||||
dataframe.loc[strong_trend & ((dataframe['close'] > dataframe['open'] + dataframe['atr'] * 4.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
|
||||
|
||||
# 一般趋势中:提高到3倍ATR退出
|
||||
dataframe.loc[normal_trend & ((dataframe['close'] > dataframe['open'] + dataframe['atr'] * 3) | 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
|
||||
# 非趋势或弱势:保持2倍ATR退出
|
||||
|
||||
# 记录退出决策日志
|
||||
if len(dataframe[dataframe['exit_long'] == 1]) > 0:
|
||||
@ -369,11 +358,20 @@ class FreqaiPrimer(IStrategy):
|
||||
last_candle = dataframe.iloc[-1]
|
||||
atr = last_candle['atr']
|
||||
|
||||
# 渐进式止损策略
|
||||
if current_profit > 0.03: # 利润超过3%时
|
||||
return -1.5 * atr / current_rate # 扩大止损范围,让利润奔跑
|
||||
elif current_profit > 0.015: # 利润超过1.5%时
|
||||
return -1.2 * atr / current_rate # 轻微扩大止损范围
|
||||
# 获取当前市场状态
|
||||
current_state = dataframe['market_state'].iloc[-1] if 'market_state' in dataframe.columns else 'unknown'
|
||||
|
||||
# 更激进的渐进式止损策略
|
||||
if current_profit > 0.04: # 利润超过4%时
|
||||
return -2.0 * atr / current_rate # 大幅扩大止损范围,让利润奔跑
|
||||
elif current_profit > 0.025: # 利润超过2.5%时
|
||||
return -1.7 * atr / current_rate # 中等扩大止损范围
|
||||
elif current_profit > 0.01: # 利润超过1%时
|
||||
return -1.3 * atr / current_rate # 轻微扩大止损范围
|
||||
|
||||
# 在强劲牛市中,即使小亏损也可以容忍更大回调
|
||||
if current_state == 'strong_bull' and current_profit > -0.01:
|
||||
return -1.5 * atr / current_rate
|
||||
|
||||
if atr > 0:
|
||||
return -1.0 * atr / current_rate # 基础1倍ATR止损
|
||||
@ -387,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.02, 0.3), (0.04, 0.5), (0.06, 0.7), (0.08, 0.9)], # 强劲牛市的渐进止盈
|
||||
'weak_bull': [(0.015, 0.3), (0.03, 0.5), (0.05, 0.8)], # 弱牛市的渐进止盈
|
||||
'neutral': [(0.01, 0.4), (0.02, 0.7), (0.03, 0.9)], # 中性市场的渐进止盈
|
||||
'bear': [(0.008, 0.5), (0.015, 0.8), (0.025, 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)] # 熊市的渐进止盈(更保守)
|
||||
}
|
||||
|
||||
# 默认使用中性市场的止盈设置
|
||||
@ -442,7 +440,11 @@ class FreqaiPrimer(IStrategy):
|
||||
|
||||
# 检查价格回调是否达到加仓间隔(0.047)
|
||||
# 价格回调表示价格比初始价格低4.7%或更多
|
||||
if price_diff_pct <= -0.047:
|
||||
# 同时考虑市场状态,只在市场不是弱势时加仓
|
||||
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
||||
current_state = dataframe['market_state'].iloc[-1] if 'market_state' in dataframe.columns else 'neutral'
|
||||
|
||||
if price_diff_pct <= -0.047 and current_state not in ['bear', 'weak_bear']:
|
||||
# 计算初始入场金额
|
||||
initial_stake = trade.orders[0].cost # 第一笔订单的成本
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user