DrBuffet
Pine Script Rookie
Pine Script Rookie
Posts: 2
Joined: January 15th, 2022
Contact: TradingView Profile

Array of stings (ticker codes) - converting "string series" to "simple string"

Hi - I have a challenge I hope one of you can help me with ... :zen:

in an indicator script, I would like to build a (predefined) list of ticker-symbols/strings (eg "NASDAQ:AAPL" as part of a NASDAQ ticket list) and use these in the script values as inputs to the request.security() function - eg ala

var symbol_array = array.new_string(25, "" )

if barstate.isfirst
<indent> array.set(symbol_array, 0, "NASDAQ:AAPL")

float symbol_close = request.security(array.get(symbol_array, 0), timeframe='D', expression=close)"
// to be equivalent to "request.security("NASDAQ:AAPL", timeframe='D', expression=close)"

the problem is that array.get() returns a "string series" and the request.security() expects a "simple string" as parameter

so how do I "convert" the "string series value" to a "simple string" ??

or is there another way to define such a list of symbols not using arrays?

or??

Thanks in advance
Claus from Denmark

Deep-Wave
Pine Script Master
Pine Script Master
Posts: 44
Joined: September 4th, 2020
Contact: TradingView Profile

Re: Array of stings (ticker codes) - converting "string series" to "simple string"

Hi Claus,
if there isn't a specific reason for using arrays, you could simply define the list as "var string" variables and use these as the inputs to your request security function.
It might be easier.
https://www.tradingview.com/pine-script ... ht=var#var
Good luck with your coding and best regards, :cool:

Mark

Return to “Pine Script Q&A”