Alert for multiple tickers on multiple time frames
Posted: Thu Apr 06, 2023 3:36 pm
So I am trying to do a multiple ticker on multiple time frames for crossover/under of EMA's.
I am getting an Undeclared identifier 'alertMsg' but it is identified. I have other variations of this and do not get the error. Can anyone see why I am getting an error? Error line is alertMsg += "5 min Buy Long opportunity for \n" + syminfo.tickerid
Thank you
//@version=5
indicator('trigger for multiple symbols on multiple time frames')
checkForAlert() =>
alertMsg = ""
// Get indicator data
time_5min_close_6 = request.security(syminfo.tickerid, "5" , ta.ema(close,6))
time_5min_high_32 = request.security(syminfo.tickerid, "5" , ta.ema(high,32))
time_5min_low_32 = request.security(syminfo.tickerid, "5" , ta.ema(low,32))
time_15min_close_6 = request.security(syminfo.tickerid, "15" , ta.ema(close,6))
time_15min_high_32 = request.security(syminfo.tickerid, "15" , ta.ema(high,32))
time_15min_low_32 = request.security(syminfo.tickerid, "15" , ta.ema(low,32))
time_60min_close_6 = request.security(syminfo.tickerid, "60" , ta.ema(close,6))
time_60min_high_32 = request.security(syminfo.tickerid, "60" , ta.ema(high,32))
time_60min_low_32 = request.security(syminfo.tickerid, "60" , ta.ema(low,32))
time_240min_close_6 = request.security(syminfo.tickerid, "240" , ta.ema(close,6))
time_240min_high_32 = request.security(syminfo.tickerid, "240" , ta.ema(high,32))
time_240min_low_32 = request.security(syminfo.tickerid, "240" , ta.ema(low,32))
// Detect buy or sell
buy_5min = ta.crossover(time_5min_close_6, time_5min_high_32)
sell_5min = ta.crossunder(time_5min_close_6, time_5min_low_32)
buy_15min = ta.crossover(time_15min_close_6, time_15min_high_32)
sell_15min = ta.crossunder(time_15min_close_6, time_15min_low_32)
buy_60min = ta.crossover(time_60min_close_6, time_60min_high_32)
sell_60min = ta.crossunder(time_60min_close_6, time_60min_low_32)
buy_240min = ta.crossover(time_240min_close_6, time_240min_high_32)
sell_240min = ta.crossunder(time_240min_close_6, time_240min_low_32)
//
if buy_5min
alertMsg += "5 min Buy Long opportunity for \n" + syminfo.tickerid
if sell_5min
alertMsg += "5 min Buy Short opportunity for \n" + syminfo.tickerid
if buy_15min
alertMsg += "15 min Buy Long opportunity for \n" + syminfo.tickerid
if sell_15min
alertMsg += "15 min Buy Short opportunity for \n" + syminfo.tickerid
if buy_60min
alertMsg += "60 min Buy Long opportunity for \n" + syminfo.tickerid
if sell_60min
alertMsg += "60 min Buy Short opportunity for \n" + syminfo.tickerid
if buy_240min
alertMsg += "240 min Buy Long opportunity for \n" + syminfo.tickerid
if sell_240min
alertMsg += "240 min Buy Short opportunity for \n" + syminfo.tickerid
alertMsg
fireAlert(ticker, freq = alert.freq_once_per_bar)=>
Msg = request.security(ticker, timeframe.period, checkForAlert())
if str.length(Msg) > 0
alert(Msg, freq)
fireAlert("USDCAD")
fireAlert("EURUSD")
fireAlert("USDJPY")
fireAlert("GBPUSD")
fireAlert("AUDUSD")
fireAlert("NZDUSD")
fireAlert("USDCHF")
fireAlert("EURJPY")
fireAlert("GBPJPY")
I am getting an Undeclared identifier 'alertMsg' but it is identified. I have other variations of this and do not get the error. Can anyone see why I am getting an error? Error line is alertMsg += "5 min Buy Long opportunity for \n" + syminfo.tickerid
Thank you
//@version=5
indicator('trigger for multiple symbols on multiple time frames')
checkForAlert() =>
alertMsg = ""
// Get indicator data
time_5min_close_6 = request.security(syminfo.tickerid, "5" , ta.ema(close,6))
time_5min_high_32 = request.security(syminfo.tickerid, "5" , ta.ema(high,32))
time_5min_low_32 = request.security(syminfo.tickerid, "5" , ta.ema(low,32))
time_15min_close_6 = request.security(syminfo.tickerid, "15" , ta.ema(close,6))
time_15min_high_32 = request.security(syminfo.tickerid, "15" , ta.ema(high,32))
time_15min_low_32 = request.security(syminfo.tickerid, "15" , ta.ema(low,32))
time_60min_close_6 = request.security(syminfo.tickerid, "60" , ta.ema(close,6))
time_60min_high_32 = request.security(syminfo.tickerid, "60" , ta.ema(high,32))
time_60min_low_32 = request.security(syminfo.tickerid, "60" , ta.ema(low,32))
time_240min_close_6 = request.security(syminfo.tickerid, "240" , ta.ema(close,6))
time_240min_high_32 = request.security(syminfo.tickerid, "240" , ta.ema(high,32))
time_240min_low_32 = request.security(syminfo.tickerid, "240" , ta.ema(low,32))
// Detect buy or sell
buy_5min = ta.crossover(time_5min_close_6, time_5min_high_32)
sell_5min = ta.crossunder(time_5min_close_6, time_5min_low_32)
buy_15min = ta.crossover(time_15min_close_6, time_15min_high_32)
sell_15min = ta.crossunder(time_15min_close_6, time_15min_low_32)
buy_60min = ta.crossover(time_60min_close_6, time_60min_high_32)
sell_60min = ta.crossunder(time_60min_close_6, time_60min_low_32)
buy_240min = ta.crossover(time_240min_close_6, time_240min_high_32)
sell_240min = ta.crossunder(time_240min_close_6, time_240min_low_32)
//
if buy_5min
alertMsg += "5 min Buy Long opportunity for \n" + syminfo.tickerid
if sell_5min
alertMsg += "5 min Buy Short opportunity for \n" + syminfo.tickerid
if buy_15min
alertMsg += "15 min Buy Long opportunity for \n" + syminfo.tickerid
if sell_15min
alertMsg += "15 min Buy Short opportunity for \n" + syminfo.tickerid
if buy_60min
alertMsg += "60 min Buy Long opportunity for \n" + syminfo.tickerid
if sell_60min
alertMsg += "60 min Buy Short opportunity for \n" + syminfo.tickerid
if buy_240min
alertMsg += "240 min Buy Long opportunity for \n" + syminfo.tickerid
if sell_240min
alertMsg += "240 min Buy Short opportunity for \n" + syminfo.tickerid
alertMsg
fireAlert(ticker, freq = alert.freq_once_per_bar)=>
Msg = request.security(ticker, timeframe.period, checkForAlert())
if str.length(Msg) > 0
alert(Msg, freq)
fireAlert("USDCAD")
fireAlert("EURUSD")
fireAlert("USDJPY")
fireAlert("GBPUSD")
fireAlert("AUDUSD")
fireAlert("NZDUSD")
fireAlert("USDCHF")
fireAlert("EURJPY")
fireAlert("GBPJPY")