禁用入场间隔最小限制机制
This commit is contained in:
parent
cd7dc94d45
commit
49270fbe02
@ -1216,12 +1216,13 @@ class FreqaiPrimer(IStrategy):
|
||||
# 仅对多头交易进行检查
|
||||
if side == 'long':
|
||||
# 检查1:入场间隔控制(使用hyperopt参数)
|
||||
if pair in self._last_entry_time:
|
||||
last_entry = self._last_entry_time[pair]
|
||||
time_diff = (current_time - last_entry).total_seconds() * 0.0166666667 # 转换为分钟(使用乘法避免除法)
|
||||
if time_diff < self.entry_interval_minutes.value:
|
||||
self.strategy_log(f"[{pair}] 入场间隔不足: 距离上次入场 {time_diff:.1f}分钟 < {self.entry_interval_minutes.value}分钟,取消本次入场")
|
||||
allow_trade = False
|
||||
# 暂时禁用入场间隔限制以进行验证
|
||||
# if pair in self._last_entry_time:
|
||||
# last_entry = self._last_entry_time[pair]
|
||||
# time_diff = (current_time - last_entry).total_seconds() * 0.0166666667 # 转换为分钟(使用乘法避免除法)
|
||||
# if time_diff < self.entry_interval_minutes.value:
|
||||
# self.strategy_log(f"[{pair}] 入场间隔不足: 距离上次入场 {time_diff:.1f}分钟 < {self.entry_interval_minutes.value}分钟,取消本次入场")
|
||||
# allow_trade = False
|
||||
|
||||
# 检查2:检查是否处于剧烈拉升的不稳固区域
|
||||
if allow_trade:
|
||||
@ -1401,22 +1402,27 @@ class FreqaiPrimer(IStrategy):
|
||||
# 识别入场类型并生成标签
|
||||
df, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
||||
if len(df) > 0:
|
||||
entry_info = self.identify_entry_type(df, -1)
|
||||
|
||||
# 获取全面的市场环境信息
|
||||
market_context = self.get_comprehensive_market_context(df, pair)
|
||||
|
||||
# 生成标签字符串,包含入场类型信息和市场环境信息
|
||||
tag_string = f"type:{entry_info['type']},duration:{entry_info['duration']},risk:{entry_info['risk']},confidence:{entry_info['confidence']},name:{entry_info['name']},market_state:{market_context['market_state']},trend_strength:{market_context['trend_strength']:.2f}"
|
||||
|
||||
self.strategy_log(
|
||||
f"[{pair}] 入场类型识别: {entry_info['name']} (类型{entry_info['type']}), "
|
||||
f"建议持仓: {entry_info['duration']}分钟, 风险等级: {entry_info['risk']}, "
|
||||
f"市场状态: {market_context['market_state']}, 趋势强度: {market_context['trend_strength']:.2f}"
|
||||
)
|
||||
|
||||
# 返回带有标签的字典,Freqtrade会自动处理
|
||||
return {'enter_tag': tag_string}
|
||||
try:
|
||||
entry_info = self.identify_entry_type(df, -1)
|
||||
|
||||
# 获取全面的市场环境信息
|
||||
market_context = self.get_comprehensive_market_context(df, pair)
|
||||
|
||||
# 生成标签字符串,包含入场类型信息和市场环境信息
|
||||
tag_string = f"type:{entry_info['type']},duration:{entry_info['duration']},risk:{entry_info['risk']},confidence:{entry_info['confidence']},name:{entry_info['name']},market_state:{market_context['market_state']},trend_strength:{market_context['trend_strength']:.2f}"
|
||||
|
||||
self.strategy_log(
|
||||
f"[{pair}] 入场类型识别: {entry_info['name']} (类型{entry_info['type']}), "
|
||||
f"建议持仓: {entry_info['duration']}分钟, 风险等级: {entry_info['risk']}, "
|
||||
f"市场状态: {market_context['market_state']}, 趋势强度: {market_context['trend_strength']:.2f}"
|
||||
)
|
||||
|
||||
# 返回带有标签的字典,Freqtrade会自动处理
|
||||
return {'enter_tag': tag_string}
|
||||
except Exception as e:
|
||||
# 如果在生成标签过程中出现异常,仍允许入场,但不带标签
|
||||
self.strategy_log(f"[{pair}] 生成入场标签时出错: {str(e)}, 允许无标签入场")
|
||||
return {} # 允许入场,但不带标签
|
||||
|
||||
return allow_trade
|
||||
|
||||
@ -1884,12 +1890,17 @@ class FreqaiPrimer(IStrategy):
|
||||
)
|
||||
|
||||
# 返回ROI字典,格式为 {时间: ROI阈值}
|
||||
# 这里我们返回一个简单的ROI表,从0时间开始直到计算出的时间,然后维持最终的ROI值
|
||||
# ROI字典应该从最短时间到最长时间,ROI值逐渐降低(或保持)
|
||||
# 为了确保交易能够持续,我们需要设置一个合理的ROI曲线
|
||||
roi_dict = {}
|
||||
roi_dict[0] = adjusted_roi # 立即止盈
|
||||
roi_dict[0] = adjusted_roi # 立即生效的ROI
|
||||
roi_dict[int(adjusted_time)] = adjusted_roi # 在指定时间后保持该ROI水平
|
||||
roi_dict[1440] = 0.01 # 24小时后至少1%的ROI(安全网)
|
||||
|
||||
return roi_dict
|
||||
# 确保字典按照时间升序排列
|
||||
sorted_roi_dict = dict(sorted(roi_dict.items()))
|
||||
|
||||
return sorted_roi_dict
|
||||
|
||||
|
||||
def adjust_trade_position(self, trade: 'Trade', current_time, current_rate: float,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user