# Industry / Sector ranking

##### Member
VIP
there 197 Industries in the market, each industry performs by how well its overall holdings price action is doing Similar to a single stock, the best price performing industry would be ranked #1 and the worst price action industry would be ranked 197.
Right now, oil and gas Trust, is the top performing industry, with Relative strength rating of 99, there are 15 names in Gas & Oil trust industry.
looking at how IBD calculates, seems too complex for TOS, however im not a coder and below is the definition IBD gives for industry ranking.

a number would be obtained by calculating the least-squares curve fit of summed prices on certain stocks within that industry. Another calculation is then done using all companies in the group

Thank you for taking the time to look, and double thank you, to anyone that might be able to create something

The ToS platform has no ability to discern which "certain stocks" comprise which industries, as sector/industry data is not an available for custom scripting.

The work around that members use is:
1. identify what ETF fund best represent each of your industries.
The assumption is that the ETF fund performance is analogous as long as those funds are comprised of the stocks that you are accessing.

2. Then create an industry ETF symbol list
use this format:
input Oil_Gas_Royalty_Trust = "ABC";
input Medical_LongTermCare = "EFG";
etc.. for all 197 industries

3. provide your math for calculating the least-squares curve fit of summed prices
that would be placed into a script{} subroutine

4. and then just write out the 197 compare statements
Here is what the compare statements look like for the 9 sectors:
# determine integer sequence (ranking)
def c1 = (st1>st2)+(st1>st3)+(st1>st4)+(st1>st5)+(st1>st6)+(st1>st7)+(st1>st8)+(st1>st9)+1;
def c2 = (st2>st1)+(st2>st3)+(st2>st4)+(st2>st5)+(st2>st6)+(st2>st7)+(st2>st8)+(st2>st9)+1;
def c3 = (st3>st1)+(st3>st2)+(st3>st4)+(st3>st5)+(st3>st6)+(st3>st7)+(st3>st8)+(st3>st9)+1;
def c4 = (st4>st1)+(st4>st2)+(st4>st3)+(st4>st5)+(st4>st6)+(st4>st7)+(st4>st8)+(st4>st9)+1;
def c5 = (st5>st1)+(st5>st2)+(st5>st3)+(st5>st4)+(st5>st6)+(st5>st7)+(st5>st8)+(st5>st9)+1;
def c6 = (st6>st1)+(st6>st2)+(st6>st3)+(st6>st4)+(st6>st5)+(st6>st7)+(st6>st8)+(st6>st9)+1;
def c7 = (st7>st1)+(st7>st2)+(st7>st3)+(st7>st4)+(st7>st5)+(st7>st6)+(st7>st8)+(st7>st9)+1;
def c8 = (st8>st1)+(st8>st2)+(st8>st3)+(st8>st4)+(st8>st5)+(st8>st6)+(st8>st7)+(st8>st9)+1;
def c9 = (st9>st1)+(st9>st2)+(st9>st3)+(st9>st4)+(st9>st5)+(st9>st6)+(st9>st7)+(st9>st8)+1;

No, it is not too complex for ToS.
But you will be writing out code for a long time.
You might want to limit it to the top 20 industries to be ranked.

Last edited by a moderator:
The ToS platform has no ability to discern which "certain stocks" comprise which industries, as sector/industry data is not an available for custom scripting.

The work around that members use is:
1. identify what ETF fund best represent each of your industries.
The assumption is that the ETF fund performance is analogous as long as those funds are comprised of the stocks that you are accessing.

2. Then create an industry ETF symbol list
use this format:

etc.. for all 197 industries

3. provide your math for calculating the least-squares curve fit of summed prices
that would be placed into a script{} subroutine

4. and then just write out the 197 compare statements
Here is what the compare statements look like for the 9 sectors:
# determine integer sequence (ranking)

No, it is not too complex for ToS.
But you will be writing out code for a long time.
You might want to limit it to the top 20 industries to be ranked.

Thank you for the above examples, I will work on it.

@Breakout Trader - I worked on similar stuff I didn't see fully done. Feel free to use/update as needed

## SECTOR RANKING ##

Code:
``````# Sector Ranking using ETFs
# bulusufinances
# v0.3

input Cyclicals = "XLY";
input Technology = "XLK";
input Industrials = "XLI";
input Materials = "XLB";
input Energy = "XLE";
input Staples = "XLP";
input HealthCare = "XLV";
input Utilities = "XLU";
input Financials = "XLF";

# Function to calculate the least-squares curve fit
script leastSquaresFit {
input data = close;
def n = 252; # Number of days for the fit
def sumX = Sum(1, n);
def sumY = Sum(data, n);
def sumXY = Sum(data * (1 + n), n);
def sumXX = Sum(Sqr(1 + n), n);
def slope = (n * sumXY - sumX * sumY) / (n * sumXX - Sqr(sumX));
def intercept = (sumY - slope * sumX) / n;
plot fit = slope * (1 + n) + intercept;
}

# Calculate the least-squares curve fit for each ETF
def ls_Cyclicals = leastSquaresFit(close(Cyclicals));
def ls_Technology = leastSquaresFit(close(Technology));
def ls_Industrials = leastSquaresFit(close(Industrials));
def ls_Materials = leastSquaresFit(close(Materials));
def ls_Energy = leastSquaresFit(close(Energy));
def ls_Staples = leastSquaresFit(close(Staples));
def ls_HealthCare = leastSquaresFit(close(HealthCare));
def ls_Utilities = leastSquaresFit(close(Utilities));
def ls_Financials = leastSquaresFit(close(Financials));

# Determine integer sequence (ranking)
def c1 = (ls_Cyclicals > ls_Technology) + (ls_Cyclicals > ls_Industrials) + (ls_Cyclicals > ls_Materials) + (ls_Cyclicals > ls_Energy) + (ls_Cyclicals > ls_Staples) + (ls_Cyclicals > ls_HealthCare) + (ls_Cyclicals > ls_Utilities) + (ls_Cyclicals > ls_Financials) + 1;
def c2 = (ls_Technology > ls_Cyclicals) + (ls_Technology > ls_Industrials) + (ls_Technology > ls_Materials) + (ls_Technology > ls_Energy) + (ls_Technology > ls_Staples) + (ls_Technology > ls_HealthCare) + (ls_Technology > ls_Utilities) + (ls_Technology > ls_Financials) + 1;
def c3 = (ls_Industrials > ls_Cyclicals) + (ls_Industrials > ls_Technology) + (ls_Industrials > ls_Materials) + (ls_Industrials > ls_Energy) + (ls_Industrials > ls_Staples) + (ls_Industrials > ls_HealthCare) + (ls_Industrials > ls_Utilities) + (ls_Industrials > ls_Financials) + 1;
def c4 = (ls_Materials > ls_Cyclicals) + (ls_Materials > ls_Technology) + (ls_Materials > ls_Industrials) + (ls_Materials > ls_Energy) + (ls_Materials > ls_Staples) + (ls_Materials > ls_HealthCare) + (ls_Materials > ls_Utilities) + (ls_Materials > ls_Financials) + 1;
def c5 = (ls_Energy > ls_Cyclicals) + (ls_Energy > ls_Technology) + (ls_Energy > ls_Industrials) + (ls_Energy > ls_Materials) + (ls_Energy > ls_Staples) + (ls_Energy > ls_HealthCare) + (ls_Energy > ls_Utilities) + (ls_Energy > ls_Financials) + 1;
def c6 = (ls_Staples > ls_Cyclicals) + (ls_Staples > ls_Technology) + (ls_Staples > ls_Industrials) + (ls_Staples > ls_Materials) + (ls_Staples > ls_Energy) + (ls_Staples > ls_HealthCare) + (ls_Staples > ls_Utilities) + (ls_Staples > ls_Financials) + 1;
def c7 = (ls_HealthCare > ls_Cyclicals) + (ls_HealthCare > ls_Technology) + (ls_HealthCare > ls_Industrials) + (ls_HealthCare > ls_Materials) + (ls_HealthCare > ls_Energy) + (ls_HealthCare > ls_Staples) + (ls_HealthCare > ls_Utilities) + (ls_HealthCare > ls_Financials) + 1;
def c8 = (ls_Utilities > ls_Cyclicals) + (ls_Utilities > ls_Technology) + (ls_Utilities > ls_Industrials) + (ls_Utilities > ls_Materials) + (ls_Utilities > ls_Energy) + (ls_Utilities > ls_Staples) + (ls_Utilities > ls_HealthCare) + (ls_Utilities > ls_Financials) + 1;
def c9 = (ls_Financials > ls_Cyclicals) + (ls_Financials > ls_Technology) + (ls_Financials > ls_Industrials) + (ls_Financials > ls_Materials) + (ls_Financials > ls_Energy) + (ls_Financials > ls_Staples) + (ls_Financials > ls_HealthCare) + (ls_Financials > ls_Utilities) + 1;

# Display the table-like structure using labels
AddLabel(yes, "Cyclicals (XLY): " + c1, Color.RED);
AddLabel(yes, "Technology (XLK): " + c2, Color.ORANGE);
AddLabel(yes, "Industrials (XLI): " + c3, Color.YELLOW);
AddLabel(yes, "Materials (XLB): " + c4, Color.GREEN);
AddLabel(yes, "Energy (XLE): " + c5, Color.BLUE);
AddLabel(yes, "Staples (XLP): " + c6, Color.CYAN);
AddLabel(yes, "HealthCare (XLV): " + c7, Color.VIOLET);
AddLabel(yes, "Utilities (XLU): " + c8, Color.PINK);
AddLabel(yes, "Financials (XLF): " + c9, Color.GRAY);``````

## Below is the industrial ranking code where I used the Industry List from TOS Public lists and started calculating slopes, but never finished ranking, etc. Maybe you can see it through ##

I did not do many validations for accuracy. I started working last winter break and never got to it.

Code:
``````# TOS Industry Ranking
# Using TOS Public List of S&P 500 Sectors & Industries
# bulusufinances
# v0.1

declare lower;

input Industrial_Conglomerates = "\$SP500#201050";
input Wireless_Telecommunication_Services = "\$SP500#501020";
input Health_Care_REITs = "\$SP500#601050";
input Household_Durables = "\$SP500#252010";
input Tobacco = "\$SP500#302030";
input Telecommunication_Services_TR = "\$SP500#5010TR";
input Utilities_TR = "\$SP500#5510TR";
input Electric_Utilities = "\$SP500#551010";
input Aerospace_Defense = "\$SP500#201010";
input Consumer_Staples_Distribution_Retail_TR = "\$SP500#3010TR";
input Technology_Hardware_Storage_Peripherals = "\$SP500#452020";
input Commercial_Professional_Services_TR = "\$SP500#2020TR";
input Technology_Hardware_Equipment_TR = "\$SP500#4520TR";
input Commercial_Services_Supplies = "\$SP500#202010";
input Insurance_TR = "\$SP500#4030TR";
input Technology_Hardware_Equipment = "\$SP500#4520";
input Consumer_Staples_Distribution_Retail = "\$SP500#3010";
input Consumer_Staples_Distribution_Retail_Industry = "\$SP500#301010";
input Commercial_Professional_Services = "\$SP500#2020";
input Biotechnology = "\$SP500#352010";
input Utilities = "\$SP500#5510";
input Insurance = "\$SP500#4030";
input Insurance_Industry = "\$SP500#403010";
input Consumer_Finance = "\$SP500#402020";
input Building_Products = "\$SP500#201020";
input Financial_Services_TR = "\$SP500#4020TR";
input Banks_TR = "\$SP500#4010TR";
input Telecommunication_Services = "\$SP500#5010";
input Financial_Services = "\$SP500#4020";
input Interactive_Media_Services = "\$SP500#502030";
input Equity_REITs_TR = "\$SP500#6010TR";
input Life_Sciences_Tools_Services = "\$SP500#352030";
input Banks = "\$SP500#4010";
input Banks_Industry = "\$SP500#401010";
input Specialized_REITs = "\$SP500#601080";
input Gas_Utilities = "\$SP500#551020";
input Media_Entertainment = "\$SP500#5020";
input Media_Entertainment_TR = "\$SP500#5020TR";
input Semiconductors_Equipment_TR = "\$SP500#4530TR";
input Multi_Utilities = "\$SP500#551030";
input Construction_Materials = "\$SP500#151020";
input Semiconductors_Equipment = "\$SP500#4530";
input Semiconductor_Equipment = "\$SP500#453010";
input Containers_Packaging = "\$SP500#151030";
input Equity_REITs = "\$SP500#6010";
input Real_Estate_Management_Development = "\$SP500#6020";
input Real_Estate_Management_Development_Industry = "\$SP500#602010";
input Financial_Services_Industry = "\$SP500#402010";
input Capital_Goods_TR = "\$SP500#2010TR";
input Health_Care_Equipment_Services_TR = "\$SP500#3510TR";
input Pharmaceuticals_Biotechnology_Life_Sciences_TR = "\$SP500#3520TR";
input Diversified_Telecommunication_Services = "\$SP500#501010";
input Water_Utilities = "\$SP500#551040";
input Retail_REITs = "\$SP500#601070";
input Capital_Goods = "\$SP500#2010";
input Health_Care_Equipment_Services = "\$SP500#3510";
input Specialty_Retail = "\$SP500#255040";
input Health_Care_Providers_Services = "\$SP500#351020";
input Residential_REITs = "\$SP500#601060";
input Capital_Markets = "\$SP500#402030";
input Professional_Services = "\$SP500#202020";
input Construction_Engineering = "\$SP500#201030";
input Food_Beverage_Tobacco_TR = "\$SP500#3020TR";
input Pharmaceuticals_Biotechnology_Life_Sciences = "\$SP500#3520";
input Materials_TR = "\$SP500#1510TR";
input Household_Products = "\$SP500#303010";
input Chemicals = "\$SP500#151010";
input Office_REITs = "\$SP500#601040";
input Food_Beverage_Tobacco = "\$SP500#3020";
input Beverages = "\$SP500#302010";
input Household_Personal_Products_TR = "\$SP500#3030TR";
input IT_Services = "\$SP500#451020";
input Materials = "\$SP500#1510";
input Industrial_REITs = "\$SP500#601025";
input Household_Personal_Products = "\$SP500#3030";
input Leisure_Products = "\$SP500#252020";
input Consumer_Discretionary_Distribution_Retail_TR = "\$SP500#2550TR";
input Entertainment = "\$SP500#502020";
input Consumer_Discretionary_Distribution_Retail = "\$SP500#2550";
input Automobiles = "\$SP500#251020";
input Automobiles_Components = "\$SP500#2510";
input Automobiles_Components_TR = "\$SP500#2510TR";
input Consumer_Durables_Apparel = "\$SP500#2520";
input Consumer_Durables_Apparel_TR = "\$SP500#2520TR";
input Health_Care_Equipment_Supplies = "\$SP500#351010";
input Pharmaceuticals = "\$SP500#352020";
input Communications_Equipment = "\$SP500#452010";
input Media = "\$SP500#502010";
input Metals_Mining = "\$SP500#151040";
input Machinery = "\$SP500#201060";
input Distributors = "\$SP500#255010";
input Food_Products = "\$SP500#302020";
input Electrical_Equipment = "\$SP500#201040";
input Software = "\$SP500#451030";
input Software_Services_TR = "\$SP500#4510TR";
input Ground_Transportation = "\$SP500#203040";
input Fertilizers_Agricultural_Chemicals = "\$SP500#15101030";
input Software_Services = "\$SP500#4510";
input Independent_Power_Renewable_Electricity_Producers = "\$SP500#551050";
input Energy_TR = "\$SP500#1010TR";
input Oil_Gas_Consumable_Fuels = "\$SP500#101020";
input Air_Freight_Logistics = "\$SP500#203010";
input Energy = "\$SP500#1010";
input Transportation_TR = "\$SP500#2030TR";
input Energy_Equipment_Services = "\$SP500#101010";
input Transportation = "\$SP500#2030";
input Automobile_Components = "\$SP500#251010";
input Personal_Care_Products = "\$SP500#303020";
input Consumer_Services_TR = "\$SP500#2530TR";
input Textiles_Apparel_Luxury_Goods = "\$SP500#252030";
input Consumer_Services = "\$SP500#2530";
input Hotels_Restaurants_Leisure = "\$SP500#253010";
input Passenger_Airlines = "\$SP500#203020";
input Electronic_Equipment_Instruments_Components = "\$SP500#452030";
input Hotel_Resort_REITs = "\$SP500#601030";

# Function to calculate the least-squares curve fit slope
script leastSquaresFit {
input data = close;
def n = 252; # Number of days for the fit
def sumX = Sum(1, n);
def sumY = Sum(data, n);
def sumXY = Sum(data * (1 + n), n);
def sumXX = Sum(Sqr(1 + n), n);
def slope = (n * sumXY - sumX * sumY) / (n * sumXX - Sqr(sumX));
plot slopeValue = slope;
}

# Calculate the least-squares slope for each industry
def slope_Industrial_Conglomerates = leastSquaresFit(close((Industrial_Conglomerates)));
def slope_Wireless_Telecommunication_Services = leastSquaresFit(close((Wireless_Telecommunication_Services)));
def slope_Health_Care_REITs = leastSquaresFit(close((Health_Care_REITs)));
def slope_Household_Durables = leastSquaresFit(close((Household_Durables)));
def slope_Tobacco = leastSquaresFit(close((Tobacco)));
def slope_Telecommunication_Services_TR = leastSquaresFit(close((Telecommunication_Services_TR)));
def slope_Utilities_TR = leastSquaresFit(close((Utilities_TR)));
def slope_Electric_Utilities = leastSquaresFit(close((Electric_Utilities)));
def slope_Aerospace_Defense = leastSquaresFit(close((Aerospace_Defense)));
def slope_Consumer_Staples_Distribution_Retail_TR = leastSquaresFit(close((Consumer_Staples_Distribution_Retail_TR)));
def slope_Technology_Hardware_Storage_Peripherals = leastSquaresFit(close((Technology_Hardware_Storage_Peripherals)));
def slope_Commercial_Professional_Services_TR = leastSquaresFit(close((Commercial_Professional_Services_TR)));
def slope_Technology_Hardware_Equipment_TR = leastSquaresFit(close((Technology_Hardware_Equipment_TR)));
def slope_Commercial_Services_Supplies = leastSquaresFit(close((Commercial_Services_Supplies)));
def slope_Insurance_TR = leastSquaresFit(close((Insurance_TR)));
def slope_Technology_Hardware_Equipment = leastSquaresFit(close((Technology_Hardware_Equipment)));
def slope_Consumer_Staples_Distribution_Retail = leastSquaresFit(close((Consumer_Staples_Distribution_Retail)));
def slope_Consumer_Staples_Distribution_Retail_Industry = leastSquaresFit(close((Consumer_Staples_Distribution_Retail_Industry)));
def slope_Commercial_Professional_Services = leastSquaresFit(close((Commercial_Professional_Services)));
def slope_Biotechnology = leastSquaresFit(close((Biotechnology)));
def slope_Utilities = leastSquaresFit(close((Utilities)));
def slope_Insurance = leastSquaresFit(close((Insurance)));
def slope_Insurance_Industry = leastSquaresFit(close((Insurance_Industry)));
def slope_Consumer_Finance = leastSquaresFit(close((Consumer_Finance)));
def slope_Building_Products = leastSquaresFit(close((Building_Products)));
def slope_Financial_Services_TR = leastSquaresFit(close((Financial_Services_TR)));
def slope_Banks_TR = leastSquaresFit(close((Banks_TR)));
def slope_Telecommunication_Services = leastSquaresFit(close((Telecommunication_Services)));
def slope_Financial_Services = leastSquaresFit(close((Financial_Services)));
def slope_Interactive_Media_Services = leastSquaresFit(close((Interactive_Media_Services)));
def slope_Equity_REITs_TR = leastSquaresFit(close((Equity_REITs_TR)));
def slope_Life_Sciences_Tools_Services = leastSquaresFit(close((Life_Sciences_Tools_Services)));
def slope_Banks = leastSquaresFit(close((Banks)));
def slope_Banks_Industry = leastSquaresFit(close((Banks_Industry)));
def slope_Specialized_REITs = leastSquaresFit(close((Specialized_REITs)));
def slope_Gas_Utilities = leastSquaresFit(close((Gas_Utilities)));
def slope_Media_Entertainment = leastSquaresFit(close((Media_Entertainment)));
def slope_Media_Entertainment_TR = leastSquaresFit(close((Media_Entertainment_TR)));
def slope_Semiconductors_Equipment_TR = leastSquaresFit(close((Semiconductors_Equipment_TR)));
def slope_Multi_Utilities = leastSquaresFit(close((Multi_Utilities)));
def slope_Construction_Materials = leastSquaresFit(close((Construction_Materials)));
def slope_Semiconductors_Equipment = leastSquaresFit(close((Semiconductors_Equipment)));
def slope_Semiconductor_Equipment = leastSquaresFit(close((Semiconductor_Equipment)));
def slope_Containers_Packaging = leastSquaresFit(close((Containers_Packaging)));
def slope_Equity_REITs = leastSquaresFit(close((Equity_REITs)));
def slope_Real_Estate_Management_Development = leastSquaresFit(close((Real_Estate_Management_Development)));
def slope_Real_Estate_Management_Development_Industry = leastSquaresFit(close((Real_Estate_Management_Development_Industry)));
def slope_Financial_Services_Industry = leastSquaresFit(close((Financial_Services_Industry)));
def slope_Capital_Goods_TR = leastSquaresFit(close((Capital_Goods_TR)));
def slope_Health_Care_Equipment_Services_TR = leastSquaresFit(close((Health_Care_Equipment_Services_TR)));
def slope_Pharmaceuticals_Biotechnology_Life_Sciences_TR = leastSquaresFit(close((Pharmaceuticals_Biotechnology_Life_Sciences_TR)));
def slope_Diversified_Telecommunication_Services = leastSquaresFit(close((Diversified_Telecommunication_Services)));
def slope_Water_Utilities = leastSquaresFit(close((Water_Utilities)));
def slope_Retail_REITs = leastSquaresFit(close((Retail_REITs)));
def slope_Capital_Goods = leastSquaresFit(close((Capital_Goods)));
def slope_Health_Care_Equipment_Services = leastSquaresFit(close((Health_Care_Equipment_Services)));
def slope_Specialty_Retail = leastSquaresFit(close((Specialty_Retail)));
def slope_Health_Care_Providers_Services = leastSquaresFit(close((Health_Care_Providers_Services)));
def slope_Residential_REITs = leastSquaresFit(close((Residential_REITs)));
def slope_Capital_Markets = leastSquaresFit(close((Capital_Markets)));
def slope_Professional_Services = leastSquaresFit(close((Professional_Services)));
def slope_Construction_Engineering = leastSquaresFit(close((Construction_Engineering)));
def slope_Food_Beverage_Tobacco_TR = leastSquaresFit(close((Food_Beverage_Tobacco_TR)));
def slope_Pharmaceuticals_Biotechnology_Life_Sciences = leastSquaresFit(close((Pharmaceuticals_Biotechnology_Life_Sciences)));
def slope_Materials_TR = leastSquaresFit(close((Materials_TR)));
def slope_Household_Products = leastSquaresFit(close((Household_Products)));
def slope_Chemicals = leastSquaresFit(close((Chemicals)));
def slope_Office_REITs = leastSquaresFit(close((Office_REITs)));
def slope_Food_Beverage_Tobacco = leastSquaresFit(close((Food_Beverage_Tobacco)));
def slope_Beverages = leastSquaresFit(close((Beverages)));
def slope_Household_Personal_Products_TR = leastSquaresFit(close((Household_Personal_Products_TR)));
def slope_IT_Services = leastSquaresFit(close((IT_Services)));
def slope_Materials = leastSquaresFit(close((Materials)));
def slope_Industrial_REITs = leastSquaresFit(close((Industrial_REITs)));
def slope_Household_Personal_Products = leastSquaresFit(close((Household_Personal_Products)));
def slope_Leisure_Products = leastSquaresFit(close((Leisure_Products)));
def slope_Consumer_Discretionary_Distribution_Retail_TR = leastSquaresFit(close((Consumer_Discretionary_Distribution_Retail_TR)));
def slope_Entertainment = leastSquaresFit(close((Entertainment)));
def slope_Consumer_Discretionary_Distribution_Retail = leastSquaresFit(close((Consumer_Discretionary_Distribution_Retail)));
def slope_Automobiles = leastSquaresFit(close((Automobiles)));
def slope_Automobiles_Components = leastSquaresFit(close((Automobiles_Components)));
def slope_Automobiles_Components_TR = leastSquaresFit(close((Automobiles_Components_TR)));
def slope_Consumer_Durables_Apparel = leastSquaresFit(close((Consumer_Durables_Apparel)));
def slope_Consumer_Durables_Apparel_TR = leastSquaresFit(close((Consumer_Durables_Apparel_TR)));
def slope_Health_Care_Equipment_Supplies = leastSquaresFit(close((Health_Care_Equipment_Supplies)));
def slope_Pharmaceuticals = leastSquaresFit(close((Pharmaceuticals)));
def slope_Communications_Equipment = leastSquaresFit(close((Communications_Equipment)));
def slope_Media = leastSquaresFit(close((Media)));
def slope_Metals_Mining = leastSquaresFit(close((Metals_Mining)));
def slope_Machinery = leastSquaresFit(close((Machinery)));
def slope_Distributors = leastSquaresFit(close((Distributors)));
def slope_Food_Products = leastSquaresFit(close((Food_Products)));
def slope_Electrical_Equipment = leastSquaresFit(close((Electrical_Equipment)));
def slope_Software = leastSquaresFit(close((Software)));
def slope_Software_Services_TR = leastSquaresFit(close((Software_Services_TR)));
def slope_Ground_Transportation = leastSquaresFit(close((Ground_Transportation)));
def slope_Fertilizers_Agricultural_Chemicals = leastSquaresFit(close((Fertilizers_Agricultural_Chemicals)));
def slope_Software_Services = leastSquaresFit(close((Software_Services)));
def slope_Independent_Power_Renewable_Electricity_Producers = leastSquaresFit(close((Independent_Power_Renewable_Electricity_Producers)));
def slope_Energy_TR = leastSquaresFit(close((Energy_TR)));
def slope_Oil_Gas_Consumable_Fuels = leastSquaresFit(close((Oil_Gas_Consumable_Fuels)));
def slope_Air_Freight_Logistics = leastSquaresFit(close((Air_Freight_Logistics)));
def slope_Energy = leastSquaresFit(close((Energy)));
def slope_Transportation_TR = leastSquaresFit(close((Transportation_TR)));
def slope_Energy_Equipment_Services = leastSquaresFit(close((Energy_Equipment_Services)));
def slope_Transportation = leastSquaresFit(close((Transportation)));
def slope_Automobile_Components = leastSquaresFit(close((Automobile_Components)));
def slope_Personal_Care_Products = leastSquaresFit(close((Personal_Care_Products)));
def slope_Consumer_Services_TR = leastSquaresFit(close((Consumer_Services_TR)));
def slope_Textiles_Apparel_Luxury_Goods = leastSquaresFit(close((Textiles_Apparel_Luxury_Goods)));
def slope_Consumer_Services = leastSquaresFit(close((Consumer_Services)));
def slope_Hotels_Restaurants_Leisure = leastSquaresFit(close((Hotels_Restaurants_Leisure)));
def slope_Passenger_Airlines = leastSquaresFit(close((Passenger_Airlines)));
def slope_Electronic_Equipment_Instruments_Components = leastSquaresFit(close((Electronic_Equipment_Instruments_Components)));
def slope_Hotel_Resort_REITs = leastSquaresFit(close((Hotel_Resort_REITs)));

# Display the top 20 slopes
AddLabel(yes, "Top 20 Industry Slopes:", Color.YELLOW);

# Add labels for the top 20 industries based on manually checking their slopes
AddLabel(yes, "Wireless Telecommunication Services: " + slope_Wireless_Telecommunication_Services, Color.GREEN);
AddLabel(yes, "Health Care REITs: " + slope_Health_Care_REITs, Color.GREEN);
AddLabel(yes, "Tobacco: " + slope_Tobacco, Color.GREEN);
AddLabel(yes, "Telecommunication Services TR: " + slope_Telecommunication_Services_TR, Color.GREEN);
AddLabel(yes, "Utilities TR: " + slope_Utilities_TR, Color.GREEN);
AddLabel(yes, "Electric Utilities: " + slope_Electric_Utilities, Color.GREEN);
AddLabel(yes, "Aerospace & Defense: " + slope_Aerospace_Defense, Color.GREEN);
AddLabel(yes, "Technology Hardware, Storage & Peripherals: " + slope_Technology_Hardware_Storage_Peripherals, Color.GREEN);
AddLabel(yes, "Commercial & Professional Services TR: " + slope_Commercial_Professional_Services_TR, Color.GREEN);
AddLabel(yes, "Technology Hardware & Equipment TR: " + slope_Technology_Hardware_Equipment_TR, Color.GREEN);
AddLabel(yes, "Commercial Services & Supplies: " + slope_Commercial_Services_Supplies, Color.GREEN);
AddLabel(yes, "Insurance TR: " + slope_Insurance_TR, Color.GREEN);
AddLabel(yes, "Technology Hardware & Equipment: " + slope_Technology_Hardware_Equipment, Color.GREEN);
AddLabel(yes, "Consumer Staples Distribution & Retail: " + slope_Consumer_Staples_Distribution_Retail, Color.GREEN);
AddLabel(yes, "Biotechnology: " + slope_Biotechnology, Color.GREEN);
AddLabel(yes, "Life Sciences Tools & Services: " + slope_Life_Sciences_Tools_Services, Color.GREEN);
AddLabel(yes, "Banks Industry: " + slope_Banks_Industry, Color.GREEN);
AddLabel(yes, "Specialized REITs: " + slope_Specialized_REITs, Color.GREEN);
AddLabel(yes, "Gas Utilities: " + slope_Gas_Utilities, Color.GREEN);
AddLabel(yes, "Media & Entertainment: " + slope_Media_Entertainment, Color.GREEN);``````

87k+ Posts
312 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?