Reputation: 1
if you have indicator with buy/sell signals, how would you create alert for it using 1 alert:
For example: the alert will be: if i get a buy signal, i get alert saying “buy” and ticker. And same for sell basically.
Its easy to create 2 alerts (1 for buy and 1 for sell), but how would you do it in 1 alert. Please share example code Thank You
This is what I had but it only gives me alert for buy/sell. it doesnt tell me what ticker it is:
if buy or sell
newalert = (buy ? "BUY" : sell ? "SELL" : na),
alert(newalert)
Upvotes: 0
Views: 2442
Reputation: 1714
This may help:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © adolgov
//@version=4
study("My Script")
buy = bar_index % 2 == 0
sell = bar_index % 2 == 1
if buy
alert("buy " + syminfo.ticker)
if sell
alert("sell " + syminfo.ticker)
Upvotes: 2