0
votes

I am trying to send back a custom variable through the Pinescript alerts.

top        = input(title="Top",                      type=input.float,    defval=10000, minval=1)
bottom     = input(title="Bottom",                   type=input.integer,  defval=5000, minval=0)

failedmessage = " \"processing\":\"NONE\" "
basemessage   = " \"processing\":\"COMPLETED\", \"top\":{{top}}, \"bottom\":{{bottom}} "

alertcondition( top > bottom, title="test",  message=basemessage   )

When the alert condition pops up, the values for "top" and "bottom" are not filled in. I have also tried:

basemessage   = " \"processing\":\"COMPLETED\", \"top\":{{\"Top\"}}, \"bottom\":{{\"Bottom\"}} "

but this did not work either.

What can I do here?

Thanks!

2

2 Answers

0
votes

You can't use dynamic text in alert messages.

If using a different numeric value to distinguish between your conditions in the alert message could meet your needs, see the first link in that answer for an example of the technique you can use to achieve that.

0
votes

Now you can send dynamic alert messages through strategy.entry. Here is a sample code below.

buy_msg = "TYPE:LE "+" :SYMBOL: "+syminfo.ticker +" :PRICE: "+tostring(close)+" :QTY: "+tostring(quant)
sell_msg = "TYPE:Lx "+" :SYMBOL: "+syminfo.ticker +" :PRICE: "+tostring(close)+" :QTY: "+tostring(quant)

strategy.entry("Long", strategy.long, when = buy,comment="Buy",alert_message=buy_msg )
strategy.entry("Short", strategy.short, when = sell,comment="Sell",alert_message=sell_msg)