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
 

markos

Well-known member
VIP
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:

wchillman

New member
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?
 

BenTen

Administrative
Staff member
Staff
VIP
@Diamondlil

eNaEPmR.png
 

lowtrade

Member
VIP
Is it possible to run the scan for multiple sectors like Information Technology and Energy only? I was able to select one sector like the above example.
 

Similar threads

Top