报错求助:strategy.opentrades.all字段不存在,需获取全部持仓总数
解决Pine Script报错“Object has no field all”
- 错误原因:
strategy.opentrades对象不存在all字段,你误用了这个不存在的属性来获取持仓总数。 - 正确用法:
- 获取全部持仓总数:使用
strategy.opentrades.size(),该函数默认返回当前所有未平仓订单的数量,无需额外参数。 - 获取全部持仓的总利润:使用
strategy.opentrades.profit(),不带参数时直接返回所有未平仓持仓的总利润。
- 获取全部持仓总数:使用
修正后的代码片段:
closelong = (n1 < n2 and p < n2 and confidence < dt) or (strategy.opentrades.profit() < SL) or (strategy.opentrades.profit() > TP)
如果需要基于持仓数量做判断,比如持仓数大于某个阈值,直接用strategy.opentrades.size()即可,示例:
// 判断持仓总数是否大于2 if (strategy.opentrades.size() > 2) // 执行对应操作
内容的提问来源于stack exchange,提问作者user25598400
相关产品推荐
相关产品推荐

