Reputation: 5407
I have a pine script strategy, which does simple buy/sell orders using:
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)
Now I am setting up a Tradingview alert which needs to output specific information.
I can output buy or sell using {{strategy.order.action}}
, but I also need to output the words close or open. Do you know how I can get this value in the alert message box? Does it exist in some sort of standard variable of strategy? Or can I assign it in the script and call it in the alert box?
Update: based on the answer of bjorn-mistiaen, I added a comment. It works fine for .entry and .exit, but not for .close:
strategy.close(id = "Long", when = cond3, comment="test")
returns:
Hoovering the function shows me that comment is a valid argument though. I don't really understand the debug error message.
Upvotes: 2
Views: 2333
Reputation: 6905
You could try to use {{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.
Source: How to use a variable value in alert
That comment
is a parameter in strategy.entry() which you could give the strings open
and close
.
strategy.entry(id, long, qty, limit, stop, oca_name, oca_type, comment, when, alert_message)
Upvotes: 3