Does anyone know if it's possible to request string data using request.security() to get information on multiple symbols at the same time? The script I have compiles with no errors, but the problem is some of the data coming through in the alert message is for the main symbol and not for the security symbols. Example: If I set an alert and the symbol that happens to be on the chart at the time I created the alert, say AAPL, then every time the alert is triggered for any one of the symbols in the list (the "security symbols") it will show the exchange (syminfo.prefix) for AAPL every time and not for the symbols in the list, such as COINBASE:BTCUSD = NASDAQ.
I've tried everything I can think of, but cannot get the correct info to come through. Or I will get an error. This error comes up the most: "Type series__string cannot be used as tuple element in request.security 'expression' argument" and after reading the documentation I think I understand why I can't reqest string in tuple. So, is it even possible to request information like syminfo.prefix on multiple symbols?
Most of the script is from a TradingView blog post: https://www.tradingview.com/blog/en/our-new-alerts-allow-for-dynamic-messages-22588/
My Script:
//@version=5
indicator('trigger RSI alert for multiple symbols')
// Just testing to see if something like this would work
my_func(_ticker) =>
dTicker = str.tostring(syminfo.ticker) + ' : '
dTitle = str.tostring(syminfo.prefix)
returnString = ' test ' + dTicker + dTitle
returnString
// Most of the following is from the TradingView blog post
f_triggerRsi(_ticker) =>
_r = ta.rsi(close, 14)
_x = ta.crossover(_r, 60)
_y = ta.crossunder(_r, 40)
_p = close
_c = syminfo.prefix
_rt = barstate.isrealtime
_tn = timenow
// Trying few things:
//_s = syminfo.prefix (can't use string in tuple error message)
//_ts = timenow (doesn't work)
//_j = str.split(syminfo.ticker, ":")
[_rsi, _co, _cu, _px, _rt_bar] = request.security(_ticker, timeframe.period, [_r, _x, _y, _p, _rt])
_msg = _ticker + ', ' + timeframe.period + ': ' + 'Test: ' + my_func(_ticker)
if _co and _rt_bar
_msg += 'RSI (' + str.tostring(_rsi) + ') crossing up 60 level ' + 'Price: ' + str.tostring(_px, "#.##") + 'Test1: ' + syminfo.prefix
alert(_msg, alert.freq_once_per_bar)
else if _cu and _rt_bar
_msg += 'RSI (' + str.tostring(_rsi) + ') crossing down 40 level ' + 'Price: ' + str.tostring(_px, "#.##") + 'Test2: ' + syminfo.prefix
alert(_msg, alert.freq_once_per_bar)
// This script currently returns:
// GOOD: ticker correctly with _ticker
// GOOD: RSI value correctly with _rsi
// GOOD: timeframe correctly (but it's inherantly correct)
// BAD: exchange incorrectly, returns the exchange of the main symbol and not the value of the security symbols
// BAD: timestamp is always the time of the main symbol not the security symbols
// Data I need in the alert message
// a) tickerid that triggered the alert (NASDAQ:AAPL, COINBASE:BTCUSD, etc.)
// b) timeframe that the ticker is on (Daily, 30 Minute, etc.)
// c) the exchange separately without the ticker (syminfo.prefix)
// d) the symbol without the exchange (syminfo.ticker)
// d) timestamp - the time the alert for the security tickerid was triggered at the exchange time
// Security Symbols
f_triggerRsi(syminfo.tickerid)
f_triggerRsi('NASDAQ:MSFT')
f_triggerRsi('NYSE:PLTR')
f_triggerRsi('NASDAQ:AAPL')
f_triggerRsi('NASDAQ:DWAC')
f_triggerRsi('NASDAQ:PHUN')
f_triggerRsi('NASDAQ:SBEA')
f_triggerRsi('NASDAQ:SEAC')
f_triggerRsi('NASDAQ:CFVI')
f_triggerRsi('NASDAQ:MSFT')
f_triggerRsi('NASDAQ:NVDA')
f_triggerRsi('NASDAQ:FB')
f_triggerRsi('NASDAQ:AMD')
f_triggerRsi('NASDAQ:TSLA')
f_triggerRsi("COINBASE:BTCUSD")
f_triggerRsi("COINBASE:ETHUSD")
f_triggerRsi("COINBASE:LTCUSD")
f_triggerRsi("BINANCE:SOLUSDT")
f_triggerRsi("FTX:RAYUSD")
f_triggerRsi("BINANCE:ICPUSDT")