You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用strategy.close时添加comment参数报错,该参数是否支持?

Pine Script中strategy.close能否添加comment参数?

不行,strategy.close()函数本身不支持comment参数。从报错信息可知,该函数仅提供一种重载形式:strategy.close(const string, series[bool]) => void,仅接受两个参数:

  • 订单ID字符串(如示例中的"long")
  • 触发平仓的布尔条件(when参数)

若需给平仓操作添加注释,推荐使用strategy.exit()函数替代,它原生支持comment参数,示例代码:

strategy.exit("exit_long", "long", when = shortCond == true and tradeType == "LONG", comment = "CLOSE")

其中"exit_long"是平仓订单的自定义ID,"long"是目标平仓的多单ID,这样就能给平仓操作添加指定注释。

如果一定要使用strategy.close(),可在平仓触发时额外添加文本标签实现类似效果,示例:

if (shortCond == true and tradeType == "LONG")
    strategy.close("long")
    label.new(bar_index, close, "CLOSE", color=color.red)

内容的提问来源于stack exchange,提问作者Jonas Duarte

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 19:45:55