Working with combined/calculated tickers -> coding tool

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', 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, 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', 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' 😃


Comment: You can create large combinations, for example:
(max 10 during testing)
To make it easy to copy such a string, you can make an alert:
if barstate.islast 
    alert(syminfo.ticker, alert.freq_once_per_bar)
Then you can copy the data and put it in a variable:
if barstate.islast and syminfo.ticker == strDEFI_10x_1, high, bar_index + 1, high, extend=extend.both, color=color.white)

This string can sometimes only be used in previous situation
(syminfo.ticker == ...), and not for example in a security call:
strAAPL_GOOG  = 'AAPL*2+BATS:GOOG*3)/BITSTAMP:BTCUSD' // we know this worked previously
hi_AAPL_GOOG =, '', high) 
if barstate.islast, hi_AAPL_GOOG, bar_index + 1, hi_AAPL_GOOG, extend=extend.both,
This gives an error -> symbol resolve error

if we use what is visible at the top left -> no issue
hi_AAPL_GOOG =, '', high) // no error 
if barstate.islast, hi_AAPL_GOOG, bar_index + 1, hi_AAPL_GOOG, extend=extend.both,
    if syminfo.ticker == 'AAPL*2+BATS:GOOG*3)/BITSTAMP:BTCUSD' // '(AAPL*2+GOOG*3)/BTCUSD' -> no label showing, high, text=syminfo.ticker)

Also, we have to consider the different tickers ~ sessions, this can give mixed results

Daily (perfect):
4u chart (not as intended):

Of course you can experiment further:
str_1 = '(AAPL*2+GOOG*3)/BTCUSD'

[vol_1, sma20_1] =, '', [volume, ta.sma(close, 20)])
[vol_2, sma20_2] =, '', [volume, ta.sma(close, 20)])

if barstate.islast, sma20_1, text=str_1), sma20_2, text=str_2)

vol = vol_1 + vol_2 

plot(sma20_1, color=color.yellow)
plot(sma20_2,   )
plot(vol    , style=plot.style_columns, color=vol > vol[1] ? #23CD1180 : #FF000080)

Comment: This idea/script is part of a collection of educational idea's/scripts
If you want to return to the open source INDEX page, click here
-> Education: INDEX

#trusted pine programmers for hire

- We cannot control our emotions,
but we can control our keyboard -

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.