输出 'open' 或 'close' 的策略警报

Strategy alert to output 'open' or 'close'

我有一个 pine 脚本策略,它执行简单的 buy/sell 命令使用:

strategy.entry("Long", strategy.long, when = cond1)
strategy.entry("Short", strategy.short, when = cond2)
strategy.close("Long", when = cond3)
strategy.exit(id="TrailStop", stop=shortStopPrice)

现在我正在设置一个需要输出特定信息的Tradingview警报。

我可以使用{{strategy.order.action}}输出买或卖,但我还需要输出closeopen。您知道我如何在警报消息框中获取此值吗?它是否存在于某种标准的策略变量中?或者我可以在脚本中分配它并在警告框中调用它吗?

更新:根据bjorn-mistiaen的回答,我添加了评论。它适用于 .entry 和 .exit,但不适用于 .close:

strategy.close(id = "Long", when = cond3, comment="test")

returns:

对函数进行吸尘表明 comment 是一个有效的参数。我不太明白调试错误信息。

您可以尝试使用 {{strategy.order.comment}}

This returns the comment of the executed order (the string used in the comment parameter in one of the function calls generating orders: strategy.entry, strategy.exit or strategy.order). If no comment is specified, then the value of strategy.order.id will be used.

来源:How to use a variable value in alert

commentstrategy.entry() 中的一个参数,您可以将字符串 openclose.

strategy.entry(id, long, qty, limit, stop, oca_name, oca_type, comment, when, alert_message)