Reputation: 1
I have created 2 customized indexes-indicators one for big 4 techs and other for 4 big banks. I would like to be able to tell trandingview which one to use depending on the working-ticker displayed. this is indicator-index.1, named "Tech_idx" (big tech):
tindicator(title = "Big.tech", shorttitle = "BigTech", overlay = false)
sec_1_t = request.security("NASDAQ:AAPL", timeframe.period, close)
sec_2_t = request.security("NASDAQ:MSFT", timeframe.period, close)
sec_3_t = request.security("NASDAQ:GOOGL", timeframe.period, close)
sec_4_t = request.security("NASDAQ:AMZN", timeframe.period, close)
Tech_idx = sec_1_t*0.25+sec_2_t*0.25+sec_3_t*0.25+sec_4_t*0.25
plot(Tech_idx, title="Tech_i", color=color.blue)
And similary indicator-index.2, named "Bank_idx", (big four banks):
tyindicator(title = "Big.Banks", shorttitle = "BigBanks", overlay = false)
sec_1_b = request.security("NYSE:JPM", timeframe.period, close)
sec_2_b = request.security("NYSE:BAC", timeframe.period, close)
sec_3_b = request.security("NYSE:WFC", timeframe.period, close)
sec_4_b = request.security("NYSE:GS", timeframe.period, close)
Bank_idx = sec_1_b*0.25+sec_2_b*0.25+sec_3_b*0.25+sec_4_b*0.25
plot(Bank_idx, title="Bank_i", color=color.blue)
Now i would like to be able to tell tradingview that if "JPM" (JPMorgan) is the working-ticker, then bring "Bank_idx" as the indicator to display, but if "AAPL" (APPLE) is the working-ticker, then bring "Tech_idx" as the indicator to display , otherwise Null.
in a similar fashion, I know how to call SECURITIES, but it does not work for calling INDICATORS and I do not find other way:
ticker = syminfo.ticker
var string b =
ticker == "JPM" ? "XLF" :
ticker == "AAPL" ? "XLK" :
NULL
secB = request.security(b, timeframe.period, close)
plot(secB, title="b", color=color.blue)
I would appreciate help, kind regards
Upvotes: 0
Views: 66
Reputation: 2618
You can do that in an ugly way only. You can attach both indicators to the same chart, make some conditionals in both and based on that one of them should display values and the other would not display anything (or both would not do anything).
Put both logic into a single indicator and make a decision at the display level.
Upvotes: 0