止损计算异常求助:1:2风险回报策略执行偏差
策略止损逻辑执行异常问题
策略规则与预期逻辑
- 采用1:2风险回报比
- 多头止损默认设为最近5根K线的低点,空头止损默认设为最近5根K线的高点,同时设置0.075%的最小止损距离
- 空头止损判定逻辑:若最近5根K线的高点低于「入场价+最小止损距离」,则使用最小止损;若近期高点高于该值,则使用近期高点作为止损位
- 多头止损判定逻辑:若最近5根K线的低点高于「入场价-最小止损距离」,则使用最小止损;若近期低点低于该值,则使用近期低点作为止损位
实际异常情况
回溯过往头寸时发现策略未按规则执行:
- 未正确采用最近5根K线的最高/最低点,止损位出现无规律的随机数值
- 在不应触发最小止损的场景下,错误触发了最小止损规则
策略代码
MinStopLong = strategy.position_avg_price * (1 - 0.00075) MinStopShort = strategy.position_avg_price * (1 + 0.00075) StopLossLong = ta.lowest(low,5) StopLossShort = ta.highest(high,5) if MinStopLong < StopLossLong StopLossLong := MinStopLong if MinStopShort > StopLossShort StopLossShort := MinStopShort //Take Profit TakeProfitLong = strategy.position_avg_price + (2 * (strategy.position_avg_price - StopLossLong)) TakeProfitShort = strategy.position_avg_price - (2 *(StopLossShort - strategy.position_avg_price)) //Strategy Exit if strategy.position_size>0 strategy.exit(id='close', stop=StopLossLong, limit=TakeProfitLong) if strategy.position_size<0 strategy.exit(id='close', stop=StopLossShort, limit=TakeProfitShort)
内容的提问来源于stack exchange,提问作者Dev The Hall
相关产品推荐
相关产品推荐

