A while ago Tradingview made it possible to combine multiple tickers, and even do calculations with them.
By doing so you can create a whole new ticker!
For example:
-> Add symbol (+)
-> search bar -> type -> AAPL/GOOG or ((AAPL*2) + (GOOG*3)) / BTCUSD or ...
-> press Enter
-> the chart will appear and is added to your watchlist
Sometimes you want a script to do something ONLY when the chart is on a particular ticker
For example, you want a draw line at the latest high, only when 'AAPL' is selected for your chart:
(if I would use following logic, I would code this differently, this is just for making a simple example)
if barstate.islast
if syminfo.ticker == 'AAPL'
line.new(bar_index, high, bar_index + 1, high, extend=extend.both)
If you replace 'AAPL' with 'AAPL/GOOG' and go to the chart of 'AAPL/GOOG' you would see nothing...
You'll need to get the exact ticker name, which is apparently not 'AAPL/GOOG'
To fetch the correct syminfo.ticker, add the following to your code to your script:
if barstate.islast
label.new(bar_index, high, text=syminfo.ticker, textcolor=color.white)
Then you'll see this:
When you enter this at the correct place:
if barstate.islast
if syminfo.ticker == 'AAPL/BATS:GOOG'
line.new(bar_index, high, bar_index + 1, high, extend=extend.both)
->
The same with '((AAPL*2) + (GOOG*3)) / BTCUSD'
The syminfo.ticker is actually 'AAPL*2+BATS:GOOG*3)/BITSTAMP:BTCUSD' 😃
->
Cheers!