Scan for a particular sector or industry in ThinkorSwim

Sonima

New member
I'm wondering if there would be any indicator/script that one can plot industry and/or sector as an indicator in TOS?

For example, for each ticker we have on the cart, get the industry/sector and plot as what we see on TC2000 or finviz https://www.finviz.com/groups.ashx?g=sector&v=410&o=name

This would be very useful indicator.

Code:
# S&P 500 Sector Performance (Percentage)
# Paris
# 4.12.2018

# After reviewing chubbyboy's S&P sector study, I thought it might
# be a good idea to display labels of relative S&P sector performance
# in percentages. At one glance this will enable us to determine
# which sectors are happening and which are not. Decided to use a
# script() to retrieve the data. Also, I changed the formula slightly.
# The percentage displayed is the current price as a percentage over
# yesterday's closing rather than the open today as was used in chubbyboy's
# study.

script Sector {
    input symb = "SPX";
    def c = close(symbol = symb, period = AggregationPeriod.DAY);
    def PctChg = (c / c[1]) - 1;
    plot pct = PctChg;
}

def SPX       = Sector("SPX");
def Energy    = Sector("$SP500#10");
def ConDisr   = Sector("$SP500#25");
def Finance   = Sector("$SP500#40");
def Utilities = Sector("$SP500#55");
def Materials = Sector("$SP500#15");
def ConStaple = Sector("$SP500#30");
def InfoTech  = Sector("$SP500#45");
def RealEste  = Sector("$SP500#60");
def Industrl  = Sector("$SP500#20");
def Health    = Sector("$SP500#35");
def Telecoms  = Sector("$SP500#50");

AddLabel(1, "S&P Sector Performance", Color.ORANGE);
AddLabel(1, "SPX: " + AsPercent(SPX), if Energy > 0 then Color.GREEN else if SPX < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Energy: " + AsPercent(Energy), if Energy > 0 then Color.GREEN else if Energy < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Consumer Discretionary: " + AsPercent(ConDisr), if ConDisr > 0 then Color.GREEN else if ConDisr < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Financials: " + AsPercent(Finance), if Finance > 0 then Color.GREEN else if Finance < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Utilities: " + AsPercent(Utilities), if Utilities > 0 then Color.GREEN else if Utilities < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Materials: " + AsPercent(Materials), if Materials > 0 then Color.GREEN else if Materials < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Consumer Staples: " + AsPercent(ConStaple), if ConStaple > 0 then Color.GREEN else if ConStaple < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Info Tech: " + AsPercent(InfoTech), if InfoTech > 0 then Color.GREEN else if InfoTech < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Real Estate: " + AsPercent(RealEste), if RealEste > 0 then Color.GREEN else if RealEste < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Industrials: " + AsPercent(Industrl), if Industrl > 0 then Color.GREEN else if Industrl < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Health Care: " + AsPercent(Health), if Health > 0 then Color.GREEN else if Health < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Telecoms: " + AsPercent(Telecoms), if Telecoms > 0 then Color.GREEN else if Telecoms < 0 then Color.RED else Color.LIGHT_GRAY);

# End Study
 
Hi @Sonima is all you want is a label? TOS is not like Finviz or TC2000. It would look just like all of the other labels and try to build off of there. Please see the link below.

Labels are not on this list but it might help you just the same: https://tlc.thinkorswim.com/center/howToTos/thinkManual/Miscellaneous/Industry-Classification.html

Code:
#
#    Daily Sector Performance
#    Johnny Quotron
#    The goal of the study is to assist in visualization of
#    Sector Performance on a daily basis.  The aggregation period
#    of the study can of course be altered but it was created for
#    intraday use.
#
#    The consolidated study containing all ten sectors can be used but the author
#    prefers to segregate the sectors using Thomas J. Lee's designations ( JPMorgan Year Ahead 2013)
#
#    Versioning
#    2018-03-29  drafted base code using mobius CompQuanTicks as a visual guide
#    2018-03-30  added bubbles with symbol and performance..still need to account for offset
#    2018-03-31  added notification if all sectors rise or fall in the same aggregation period
#    2018-04-04  changed calculation of gain
#    2018-04-04  included takecolorvalue code
#    Desired Improvements and Unmet Goals
#    make colors user definable and carry them from plot of lines to bubbles
#    investigate making colors automatically vary in intensity with performance
#    need to solve performance loss issue if offset is increased from zero
#    consider use of an alternative to "input" for sectors




declare lower;
def price = close;
def opentime = 930;
input showFloatingLabels = yes;
input lineWeight = 3;
input index1 = "SPY";
input XLPss = "XLP";
input XLVss = "XLV";
input XLREss = "XLRE";
input XLUss = "XLU";
input labelOffset = 0;



def Index1Percentchg = (close(index1) - First(open(index1))) / First(open(index1)) * 100;
def XLPpercentchg = (close(XLPss) - First(open(XLPss))) / First(open(XLPss)) * 100;
def XLVpercentchg = (close(XLVss) - First(open(XLVss))) / First(open(XLVss)) * 100;
def XLREpercentchg = (close(XLREss) - First(open(XLREss))) / First(open(XLREss)) * 100;
def XLUpercentchg = (close(XLUss) - First(open(XLUss))) / First(open(XLUss)) * 100;



plot XLPdelta = XLPpercentchg - index1Percentchg;
XLPdelta.setdefaultColor(color.light_GRAY);
XLPdelta.setLineWeight(lineWeight);
XLPdelta.hideBubble();
plot XLVdelta = XLVpercentchg - index1Percentchg;
XLVdelta.setdefaultColor(color.light_OrANGE);
XLVdelta.setLineWeight(lineWeight);
XLVdelta.hideBubble();
plot XLREdelta = XLREpercentchg - index1Percentchg;
XLREdelta.setdefaultColor(color.gray);
XLREdelta.setLineWeight(lineWeight);
XLREdelta.hideBubble();
plot XLUdelta = XLUpercentchg - index1Percentchg;
XLUdelta.setdefaultColor(color.light_RED);
XLUdelta.setLineWeight(lineWeight);
XLUdelta.hideBubble();

AddChartBubble(IsNaN(close[labelOffset - 1]) and !IsNaN(close[labelOffset]) and showFloatingLabels, XLPdelta[labelOffset], XLPss +" " + aspercent(XLPdelta/100), XLPdelta.takeValueColor(), yes);

AddChartBubble(IsNaN(close[labelOffset - 1]) and !IsNaN(close[labelOffset]) and showFloatingLabels, XLVdelta[labelOffset], XLVss + " " + aspercent(XLVdelta/100), XLVdelta.takeValueColor(), yes);
AddChartBubble(IsNaN(close[labelOffset - 1]) and !IsNaN(close[labelOffset]) and showFloatingLabels, XLREdelta[labelOffset], XLREss + " " + aspercent(XLREdelta/100), XLREdelta.takeValueColor(), yes);
AddChartBubble(IsNaN(close[labelOffset - 1]) and !IsNaN(close[labelOffset]) and showFloatingLabels, XLUdelta[labelOffset], XLUss + " " + aspercent(XLUdelta/100), XLUdelta.takeValueColor(), yes);

plot allUp = if XLPdelta > XLPdelta[1] and
                XLVdelta > XLVdelta[1] and
                XLREdelta > XLREdelta[1] and
                XLUdelta > XLUdelta[1]
             then 0
             else Double.NaN;
allUp.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
allUp.SetDefaultColor(Color.green);
allUp.setLineWeight(5);
allup.HideBubble();

plot allDown = if XLPdelta < XLPdelta[1] and
                XLVdelta < XLVdelta[1] and
                XLREdelta < XLREdelta[1] and
                XLUdelta < XLUdelta[1]
               then 0
               else Double.NaN;
allDown.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
allDown.SetDefaultColor(Color.red);
allDown.SetLineWeight(5);
allDown.HideBubble();

plot zero = if isNaN(close) then double.nan else 0;
zero.SetDefaultColor(Color.WHITE);
zero.HideBubble();
zero.HideTitle();

AddChartBubble(IsNaN(close[labelOffset - 1]) and !IsNaN(close[labelOffset]) and showFloatingLabels,Zero[labelOffset], index1 + " " + aspercent(Index1Percentchg/100), zero.takeValueColor(), yes);

AddVerticalLine(SecondsTillTime(openTime) == 0 or (GetDay() != GetDay()[1] and (SecondsTillTime(0000) > 0)), "", Color.GRAY, 1);
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

I know that one of the tabs on the right-hand edge of the ToS platform is “Phase Scores” and that I can use it to show a stock's Sector and Market Cap underneath the chart. My question is: Can I show the Sector and Market Cap using labels?
 
@Diamondlil

eNaEPmR.png
 
I'm wondering if there would be any indicator/script that one can plot industry and/or sector as an indicator in TOS?

For example, for each ticker we have on the cart, get the industry/sector and plot as what we see on TC2000 or finviz https://www.finviz.com/groups.ashx?g=sector&v=410&o=name

This would be very useful indicator.

Code:
# S&P 500 Sector Performance (Percentage)
# Paris
# 4.12.2018

# After reviewing chubbyboy's S&P sector study, I thought it might
# be a good idea to display labels of relative S&P sector performance
# in percentages. At one glance this will enable us to determine
# which sectors are happening and which are not. Decided to use a
# script() to retrieve the data. Also, I changed the formula slightly.
# The percentage displayed is the current price as a percentage over
# yesterday's closing rather than the open today as was used in chubbyboy's
# study.

script Sector {
    input symb = "SPX";
    def c = close(symbol = symb, period = AggregationPeriod.DAY);
    def PctChg = (c / c[1]) - 1;
    plot pct = PctChg;
}

def SPX       = Sector("SPX");
def Energy    = Sector("$SP500#10");
def ConDisr   = Sector("$SP500#25");
def Finance   = Sector("$SP500#40");
def Utilities = Sector("$SP500#55");
def Materials = Sector("$SP500#15");
def ConStaple = Sector("$SP500#30");
def InfoTech  = Sector("$SP500#45");
def RealEste  = Sector("$SP500#60");
def Industrl  = Sector("$SP500#20");
def Health    = Sector("$SP500#35");
def Telecoms  = Sector("$SP500#50");

AddLabel(1, "S&P Sector Performance", Color.ORANGE);
AddLabel(1, "SPX: " + AsPercent(SPX), if Energy > 0 then Color.GREEN else if SPX < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Energy: " + AsPercent(Energy), if Energy > 0 then Color.GREEN else if Energy < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Consumer Discretionary: " + AsPercent(ConDisr), if ConDisr > 0 then Color.GREEN else if ConDisr < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Financials: " + AsPercent(Finance), if Finance > 0 then Color.GREEN else if Finance < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Utilities: " + AsPercent(Utilities), if Utilities > 0 then Color.GREEN else if Utilities < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Materials: " + AsPercent(Materials), if Materials > 0 then Color.GREEN else if Materials < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Consumer Staples: " + AsPercent(ConStaple), if ConStaple > 0 then Color.GREEN else if ConStaple < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Info Tech: " + AsPercent(InfoTech), if InfoTech > 0 then Color.GREEN else if InfoTech < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Real Estate: " + AsPercent(RealEste), if RealEste > 0 then Color.GREEN else if RealEste < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Industrials: " + AsPercent(Industrl), if Industrl > 0 then Color.GREEN else if Industrl < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Health Care: " + AsPercent(Health), if Health > 0 then Color.GREEN else if Health < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Telecoms: " + AsPercent(Telecoms), if Telecoms > 0 then Color.GREEN else if Telecoms < 0 then Color.RED else Color.LIGHT_GRAY);

# End Study
Amazing work BTW. If I may request a variation to this for example. $NIO its SECTOR is consumer discretionary, its INDUSTRY is automobiles and the SUB-INDUSTRY is automobile manufactures.

Can you plot it on the chart based on the ticker you are looking at?

The script below displays S&P sector performance, very nice script BTW. I was wondering if it can plot the SECTOR, INDUSTRY, and SUB-INDUSTRY per the ticker you are viewing instead of all the sectors.




# S&P 500 Sector Performance (Percentage)
# Paris
# 4.12.2018

# After reviewing chubbyboy's S&P sector study, I thought it might
# be a good idea to display labels of relative S&P sector performance
# in percentages. At one glance this will enable us to determine
# which sectors are happening and which are not. Decided to use a
# script() to retrieve the data. Also, I changed the formula slightly.
# The percentage displayed is the current price as a percentage over
# yesterday's closing rather than the open today as was used in chubbyboy's
# study.

script Sector {
input symb = "SPX";
def c = close(symbol = symb, period = AggregationPeriod.DAY);
def PctChg = (c / c[1]) - 1;
plot pct = PctChg;
}

def SPX = Sector("SPX");
def Energy = Sector("$SP500#10");
def ConDisr = Sector("$SP500#25");
def Finance = Sector("$SP500#40");
def Utilities = Sector("$SP500#55");
def Materials = Sector("$SP500#15");
def ConStaple = Sector("$SP500#30");
def InfoTech = Sector("$SP500#45");
def RealEste = Sector("$SP500#60");
def Industrl = Sector("$SP500#20");
def Health = Sector("$SP500#35");
def Telecoms = Sector("$SP500#50");

AddLabel(1, "S&P Sector Performance", Color.ORANGE);
AddLabel(1, "SPX: " + AsPercent(SPX), if Energy > 0 then Color.GREEN else if SPX < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Energy: " + AsPercent(Energy), if Energy > 0 then Color.GREEN else if Energy < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Consumer Discretionary: " + AsPercent(ConDisr), if ConDisr > 0 then Color.GREEN else if ConDisr < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Financials: " + AsPercent(Finance), if Finance > 0 then Color.GREEN else if Finance < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Utilities: " + AsPercent(Utilities), if Utilities > 0 then Color.GREEN else if Utilities < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Materials: " + AsPercent(Materials), if Materials > 0 then Color.GREEN else if Materials < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Consumer Staples: " + AsPercent(ConStaple), if ConStaple > 0 then Color.GREEN else if ConStaple < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Info Tech: " + AsPercent(InfoTech), if InfoTech > 0 then Color.GREEN else if InfoTech < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Real Estate: " + AsPercent(RealEste), if RealEste > 0 then Color.GREEN else if RealEste < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Industrials: " + AsPercent(Industrl), if Industrl > 0 then Color.GREEN else if Industrl < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Health Care: " + AsPercent(Health), if Health > 0 then Color.GREEN else if Health < 0 then Color.RED else Color.LIGHT_GRAY);
AddLabel(1, "Telecoms: " + AsPercent(Telecoms), if Telecoms > 0 then Color.GREEN else if Telecoms < 0 then Color.RED else Color.LIGHT_GRAY);
 
Amazing work BTW. If I may request a variation to this for example. $NIO its SECTOR is consumer discretionary, its INDUSTRY is automobiles and the SUB-INDUSTRY is automobile manufactures.

Can you plot it on the chart based on the ticker you are looking at?
The ToS platform does not provide the stock's sector in its feeds.
So there would not be a way to automatically plot a sector ETF on a chart based on the ticker, you are looking at.
Could you manually chart a sector ETF ? Sure, why not?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
324 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top