Reputation: 31
I have been trying to send the alerts which should contain entry price, profit, loss in a single message(basically a bracket order format). So far i am getting it via 2 different message. One is during the strategy.entry() and another one during strategy.exir()... anyway it can be send together?
Upvotes: 0
Views: 3066
Reputation: 512
You can try something like this. Create two different messages, one for buy and another one for sell & then use the respective message in Tradingview script. The alert message encoded in entry call will then get picked up in alert messages. Since you are looking for bracket order you can add the other parameters like profit and loss in following format.
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)
In the last step, you need to specify Message as {{strategy.order.alert_message}}. See the attached screenshot for reference.
Upvotes: 0
Reputation: 31
LucF,
Achieved requirements using the following code.
'strategy.entry("Enter Short", strategy.short, 1, when = TradingTime, alert_message = 'Profit=' + tostring(high[1]-low[1]) + 'Loss=' + tostring(high[1]-low[1]) )'
place holder {{strategy.order.alert_message}} passing the required values. :)
Thanks for the direction to use alert_message.
Upvotes: 2
Reputation: 8789
Use the alert_message=
in each order, but make the one in strategy.exit()
empty, then configure your alert using the {{strategy.order.alert_message}}
placeholder.
Upvotes: 0