TradingView PineScript策略部分限价多单未成交问题咨询
TradingView多笔限价单仅成交部分问题排查方案
核心原因
你的问题由3个TradingView策略的内置机制限制导致,逐一调整即可解决:
- 重复调用
strategy.entry导致历史未成交挂单被自动取消
你当前的逻辑是每根满足activeorders条件的K线都会重新执行5次strategy.entry调用,而TradingView默认会在重复调用相同ID的strategy.entry指令时,先取消该ID对应的未成交挂单,再重新提交新挂单。这就导致上一根K线提交的未成交挂单,在新K线刷新时被直接取消,自然不可能在后续K线触发成交。
解决方法:新增订单提交状态判断,只有对应订单未提交过、且无未成交挂单时,才调用提交指令,避免重复覆盖:
// 定义各订单的提交状态 var bool long1Submitted = false var bool long2Submitted = false var bool long3Submitted = false var bool long4Submitted = false var bool long5Submitted = false if (activeorders) if(uselong1 and not long1Submitted and window()) strategy.entry("long1", strategy.long, size1contracts, limit=longprice1) long1Submitted := true if(uselong2 and not long2Submitted and window()) strategy.entry("long2", strategy.long, size2contracts, limit=longprice2) long2Submitted := true if(uselong3 and not long3Submitted and window()) strategy.entry("long3", strategy.long, size3contracts, limit=longprice3) long3Submitted := true if(uselong4 and not long4Submitted and window()) strategy.entry("long4", strategy.long, size4contracts, limit=longprice4) long4Submitted := true if(uselong5 and not long5Submitted and window()) strategy.entry("long5", strategy.long, size5contracts, limit=longprice5) long5Submitted := true // 挂单有效期结束后重置所有状态 if not activeorders long1Submitted := false long2Submitted := false long3Submitted := false long4Submitted := false long5Submitted := false
- 策略回测配置限制
检查策略设置中的两项参数:- 确认开启
检查限价/停损单在K线形成过程中的成交,如果关闭该选项,策略只会在K线闭合时校验订单成交状态,会遗漏K线运行过程中的价格触达信号 - 确认
每根K线最大允许提交订单数的设置值≥5,默认值通常为1-2,会直接限制后续订单提交
- 确认开启
- OCA参数隐性冲突
你当前为每个订单设置了独立的oca_name和strategy.oca.cancel参数,虽然无直接冲突,但错误的OCA分组会导致同组内只要有一笔订单成交,其余同组挂单就会被自动取消。你可以先暂时移除所有OCA相关参数,确认基础成交逻辑正常后再按需添加。
内容的提问来源于stack exchange,提问作者Eduard Germis
相关产品推荐
相关产品推荐

