Pine Script策略止盈不符、多单并发问题排查求助
Pine Script策略问题:止盈比例异常波动与多单持仓异常
问题现象
- 策略基于限价单入场,通过
strategy.exit()设置1%比例止盈平仓,但回测中实际止盈比例在0.01%-2.6%区间波动,与预期不符 - 金字塔交易(Pyramiding)参数设为0时,仍出现多单同时持仓的情况
已尝试的排查动作
- 开启“订单成交后重新计算”功能,怀疑平仓操作触发了新的开仓订单
- 将
strategy.exit()的profit参数替换为limit参数,问题依然存在
观察到的细节
K线内的详细成交时间被统一显示为K线起始时间,例如5月8日8:00的K线中,同时出现开仓和平仓两单,对应的止盈比例分别为0.1%和2.35%
相关代码片段
take_profit_percentage = input.float(1) strategy.cancel_all() if (close > open) and buy and strategy.position_size == 0 strategy.entry('Long', strategy.long, qty=ordersize, limit=buyPrice, comment=enterLongComment) if (strategy.position_size > 0) take_profit_limit = strategy.position_avg_price * ((take_profit_percentage/100)+1) //+ stretch * 2 take_profit = strategy.position_avg_price * (take_profit_percentage/100) strategy.exit("Exit Long", from_entry="Long", profit = take_profit, stop = stop_loss, comment=exitLongComment)
内容的提问来源于stack exchange,提问作者dorien
相关产品推荐
相关产品推荐

