Weighted Advance/Decline

venkytos

New member
Looking for the same thing. I'm both impressed, and confused, as to how they were able to specify the ADSPD for particular sectors, instead of the broader market. Any tips or clues would be appreciated.
 

Tofu

New member
Looking for the same thing. I'm both impressed, and confused, as to how they were able to specify the ADSPD for particular sectors, instead of the broader market. Any tips or clues would be appreciated.
They use these 11 sectors of S&P with the weight values from this: https://www.spglobal.com/spdji/en/indices/equity/sp-500/#data

SECTOR
INDEX WEIGHT
Information Technology XLK
29.2%

Health Care XLY
13.3%

Consumer Discretionary XLV
12.5%

Financials XLF
10.7%

Communication Services XLC
10.2%

Industrials XLI
7.8%

Consumer Staples XLP
5.9%

Real Estate XLRE
2.8%

Energy XLRE
2.7%

Materials XLB
2.6%

Utilities XLU
2.5%
 

mrkya253

New member
They use these 11 sectors of S&P with the weight values from this: https://www.spglobal.com/spdji/en/indices/equity/sp-500/#data

SECTOR
INDEX WEIGHT
Information Technology XLK
29.2%

Health Care XLY
13.3%

Consumer Discretionary XLV
12.5%

Financials XLF
10.7%

Communication Services XLC
10.2%

Industrials XLI
7.8%

Consumer Staples XLP
5.9%

Real Estate XLRE
2.8%

Energy XLRE
2.7%

Materials XLB
2.6%

Utilities XLU
2.5%
Are there advanced/decline symbols for these ETFs?
 

Joshua

Well-known member
VIP
CBErSqk.png


It could be using the ETFs, or it could be using the Sector Indexes ( XLF versus $SP500#40 ).

It may be using the change from the Open, or the change from the Prior Close.

And, It may be using a different weighting table than me. His info-tech is 27.9, but I used 29.2 from this weighting table, for example.

However, I've more or less deciphered it. I am decently certain that this is nonsense, and that it doesn't even use advance decline at all. It certainly does not use advance decline of individual sectors, that's for sure. Its based on the percentage change in the indexes -- basic average, and by weighting percentage.
 
Last edited:

mrkya253

New member
CBErSqk.png


It could be using the ETFs, or it could be using the Sector Indexes ( XLF versus $SP500#40 ).

It may be using the change from the Open, or the change from the Prior Close.

And, It may be using a different weighting table than me. His info-tech is 27.9, but I used 29.2 from this weighting table, for example.

However, I've more or less deciphered it. I am decently certain that this is nonsense, and that it doesn't even use advance decline at all. It certainly does not use advance decline of individual sectors, that's for sure. Its based on the percentage change in the indexes -- basic average, and by weighting percentage.

Oh, interesting. So something like this?

(pseudo code)

sectors = [XLK, XLV, XY, ...]

getSize(SectorETF) { percentChange * sectorWeight }
  • get the sum of all sizes for each sector
  • get the average i.e., divide the sum by the count of sectors
  • multiply by some scaling quotient
  • plot values as a histogram chart
  • overlay $ADSPD line to expose areas of divergence
 

venkytos

New member
CBErSqk.png


It could be using the ETFs, or it could be using the Sector Indexes ( XLF versus $SP500#40 ).

It may be using the change from the Open, or the change from the Prior Close.

And, It may be using a different weighting table than me. His info-tech is 27.9, but I used 29.2 from this weighting table, for example.

However, I've more or less deciphered it. I am decently certain that this is nonsense, and that it doesn't even use advance decline at all. It certainly does not use advance decline of individual sectors, that's for sure. Its based on the percentage change in the indexes -- basic average, and by weighting percentage.

Could you share your code for the cyan histogram bars? I'd love to see and learn from your version.
 

mrkya253

New member
This is what I have so far. Not a bad start, but there are some issues I need to resolve.

https://tos.mx/id4OV5H

# # Sources:
# https://siblisresearch.com/data/us-sector-weightings/
# https://seekingalpha.com/etfs-and-funds/etf-tables/sectors
# debug
def transpose = .05;
def SectorCount = 11;
def NewDay = secondsFromTime(0930) < secondsFromTime(0930)[1];
def InformationTechnology = 27.63; #XLK
def HealthCare = 13.25; #XLV
def ConsumerDiscretionary = 12.36; #XLY
def Financials = 11.39; #XLF
def Communications = 11.29; #XLC
def Industrials = 8.04; #XLI
def ConsumerStaples = 5.77; #XLP
def Energy = 2.75; #XLE
def RealEstate = 2.58; #XLRE
def Materials = 2.48; #XLB
def Utilities = 2.46; #XLU
def xlkWeight = InformationTechnology;
def xlvWeight = HealthCare;
def xlyWeight = ConsumerDiscretionary;
def xlfWeight = Financials;
def xlcWeight = Communications;
def xliWeight = Industrials;
def xlpWeight = ConsumerStaples;
def xleWeight = Energy;
def xlreWeight = RealEstate;
def xlbWeight = Materials;
def xluWeight = Utilities;
def xlk = close("XLK");
def xlv = close("XLV");
def xly = close("XLY");
def xlf = close("XLF");
def xlc = close("XLC");
def xli = close("XLI");
def xlp = close("XLP");
def xle = close("XLE");
def xlre = close("XLRE");
def xlb = close("XLB");
def xlu = close("XLU");
def xlkChangePercent = (xlk - xlk[1]) / xlk[1];
def xlvChangePercent = (xlv - xlv[1]) / xlv[1];
def xlyChangePercent = (xly - xly[1]) / xly[1];
def xlfChangePercent = (xlf - xlf[1]) / xlf[1];
def xlcChangePercent = (xlc - xlc[1]) / xlc[1];
def xliChangePercent = (xli - xli[1]) / xli[1];
def xlpChangePercent = (xlp - xlp[1]) / xlp[1];
def xleChangePercent = (xle - xle[1]) / xle[1];
def xlreChangePercent = (xlre - xlre[1]) / xlre[1];
def xlbChangePercent = (xlb - xlb[1]) / xlb[1];
def xluChangePercent = (xlu - xlu[1]) / xlu[1];
def xlkSizing = xlkChangePercent * xlkWeight;
def xlvSizing = xlvChangePercent * xlvWeight;
def xlySizing = xlyChangePercent * xlyWeight;
def xlfSizing = xlfChangePercent * xlfWeight;
def xlcSizing = xlcChangePercent * xlcWeight;
def xliSizing = xliChangePercent * xliWeight;
def xlpSizing = xlpChangePercent * xlpWeight;
def xleSizing = xleChangePercent * xleWeight;
def xlreSizing = xlreChangePercent * xlreWeight;
def xlbSizing = xlbChangePercent * xlbWeight;
def xluSizing = xluChangePercent * xluWeight;
def combinedSizing = ((
xlkSizing +
xlvSizing +
xlySizing +
xlfSizing +
xlcSizing +
xliSizing +
xlpSizing +
xleSizing +
xlreSizing +
xlbSizing +
xluSizing
) / SectorCount);
def cumuCombinedSizing = if newday then combinedSizing else cumuCombinedSizing[1] + combinedSizing;
# Display
AddLabel(yes, "InfoTech " + AsPercent(xlkSizing), if xlkSizing > 0 then color.GREEN else color.RED);
plot zeroLine = 0;
zeroLine.AssignValueColor(color.WHITE);
plot cumuSectorWeightAD = cumuCombinedSizing + transpose;
cumuSectorWeightAD.AssignValueColor(if cumuSectorWeightAD > cumuSectorWeightAD[1] then color.MAGENTA else color.YELLOW);
cumuSectorWeightAD.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
 

Tofu

New member
This is what I have so far. Not a bad start, but there are some issues I need to resolve.

https://tos.mx/id4OV5H

# # Sources:
# https://siblisresearch.com/data/us-sector-weightings/
# https://seekingalpha.com/etfs-and-funds/etf-tables/sectors
# debug
def transpose = .05;
def SectorCount = 11;
def NewDay = secondsFromTime(0930) < secondsFromTime(0930)[1];
def InformationTechnology = 27.63; #XLK
def HealthCare = 13.25; #XLV
def ConsumerDiscretionary = 12.36; #XLY
def Financials = 11.39; #XLF
def Communications = 11.29; #XLC
def Industrials = 8.04; #XLI
def ConsumerStaples = 5.77; #XLP
def Energy = 2.75; #XLE
def RealEstate = 2.58; #XLRE
def Materials = 2.48; #XLB
def Utilities = 2.46; #XLU
def xlkWeight = InformationTechnology;
def xlvWeight = HealthCare;
def xlyWeight = ConsumerDiscretionary;
def xlfWeight = Financials;
def xlcWeight = Communications;
def xliWeight = Industrials;
def xlpWeight = ConsumerStaples;
def xleWeight = Energy;
def xlreWeight = RealEstate;
def xlbWeight = Materials;
def xluWeight = Utilities;
def xlk = close("XLK");
def xlv = close("XLV");
def xly = close("XLY");
def xlf = close("XLF");
def xlc = close("XLC");
def xli = close("XLI");
def xlp = close("XLP");
def xle = close("XLE");
def xlre = close("XLRE");
def xlb = close("XLB");
def xlu = close("XLU");
def xlkChangePercent = (xlk - xlk[1]) / xlk[1];
def xlvChangePercent = (xlv - xlv[1]) / xlv[1];
def xlyChangePercent = (xly - xly[1]) / xly[1];
def xlfChangePercent = (xlf - xlf[1]) / xlf[1];
def xlcChangePercent = (xlc - xlc[1]) / xlc[1];
def xliChangePercent = (xli - xli[1]) / xli[1];
def xlpChangePercent = (xlp - xlp[1]) / xlp[1];
def xleChangePercent = (xle - xle[1]) / xle[1];
def xlreChangePercent = (xlre - xlre[1]) / xlre[1];
def xlbChangePercent = (xlb - xlb[1]) / xlb[1];
def xluChangePercent = (xlu - xlu[1]) / xlu[1];
def xlkSizing = xlkChangePercent * xlkWeight;
def xlvSizing = xlvChangePercent * xlvWeight;
def xlySizing = xlyChangePercent * xlyWeight;
def xlfSizing = xlfChangePercent * xlfWeight;
def xlcSizing = xlcChangePercent * xlcWeight;
def xliSizing = xliChangePercent * xliWeight;
def xlpSizing = xlpChangePercent * xlpWeight;
def xleSizing = xleChangePercent * xleWeight;
def xlreSizing = xlreChangePercent * xlreWeight;
def xlbSizing = xlbChangePercent * xlbWeight;
def xluSizing = xluChangePercent * xluWeight;
def combinedSizing = ((
xlkSizing +
xlvSizing +
xlySizing +
xlfSizing +
xlcSizing +
xliSizing +
xlpSizing +
xleSizing +
xlreSizing +
xlbSizing +
xluSizing
) / SectorCount);
def cumuCombinedSizing = if newday then combinedSizing else cumuCombinedSizing[1] + combinedSizing;
# Display
AddLabel(yes, "InfoTech " + AsPercent(xlkSizing), if xlkSizing > 0 then color.GREEN else color.RED);
plot zeroLine = 0;
zeroLine.AssignValueColor(color.WHITE);
plot cumuSectorWeightAD = cumuCombinedSizing + transpose;
cumuSectorWeightAD.AssignValueColor(if cumuSectorWeightAD > cumuSectorWeightAD[1] then color.MAGENTA else color.YELLOW);
cumuSectorWeightAD.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
They use the open to start the calculation. The line is for the 11 unweighted sectors and the histogram is for the weighted sectors.
 

Tofu

New member
CBErSqk.png


It could be using the ETFs, or it could be using the Sector Indexes ( XLF versus $SP500#40 ).

It may be using the change from the Open, or the change from the Prior Close.

And, It may be using a different weighting table than me. His info-tech is 27.9, but I used 29.2 from this weighting table, for example.

However, I've more or less deciphered it. I am decently certain that this is nonsense, and that it doesn't even use advance decline at all. It certainly does not use advance decline of individual sectors, that's for sure. Its based on the percentage change in the indexes -- basic average, and by weighting percentage.
They use the change from the open. Their Info-tech weight is 29.3, pretty much the same as yours. They use the ETFs as I indicated in my first reply.
 
Last edited:

Joshua

Well-known member
VIP

Its the percentage change, from the close of the first bar, of all the sectors, multiplied by weight, added together, and brought to scale. Which is totally pointless, because SPX is already weighted properly to begin with; the percentage change of SPX itself already accomplishes this perfectly. This is just a bad measurement of the percent change in SPX with a bunch of ridiculous extra steps. To cap it off, all the final values are multiplied by five for no reason.

Here it is with SPX's percentage change from the close of its first bar (yellow):

Here is the closing price of the first bar of SPY (blue dash) :

The indicator will just cross the zero line when ever SPX (spy in this image) crosses above or below the close of its first bar...
 
Last edited:

Quantum33

New member
Its the percentage change, from the close of the first bar, of all the sectors, multiplied by weight, added together, and brought to scale. Which is totally pointless, because SPX is already weighted properly to begin with; the percentage change of SPX itself already accomplishes this perfectly. This is just a bad measurement of the percent change in SPX with a bunch of ridiculous extra steps. To cap it off, all the final values are multiplied by five for no reason.

Here it is with SPX's percentage change from the close of its first bar (yellow):


Here is the closing price of the first bar of SPY (blue dash) :


The indicator will just cross the zero line when ever SPX (spy in this image) crosses above or below the close of its first bar...
If its not much to ask for, could it still be possible for you to share this script here or something similar? Thanks in advance
 

mashume

Well-known member
VIP
Lifetime
It could be done (since they have at that site and want $95 for their work).

I don't know what the sector tickers are through ThinkOrSwim, and I stole these from the trading view website, and I don't know the weightings, but it might go something like this:

Code:
declare lower;

def S5CONDD = close(symbol = "S5CONDD");  #  CONSUMER DISCRETIONARY
def S5CONSD = close(symbol = "S5CONSD");  #  CONSUMER STAPLES
def S5HLTHD = close(symbol = "S5HLTHD");  #  HEALTH CARE
def S5INDUD = close(symbol = "S5INDUD");  #  INDUSTRIALS
def S5INFTD = close(symbol = "S5INFTD");  #  INFORMATION TECHNOLOGY
def S5MATRD = close(symbol = "S5MATRD");  #  MATERIALS
def S5REASD = close(symbol = "S5REASD");  #  REAL ESTATE
def S5TELSD = close(symbol = "S5TELSD");  #  COMMUNICATION SERVICES
def S5UTILD = close(symbol = "S5UTILD");  #  UTILITIES
def SPFD    = close(symbol = "SPFD");     #  FINANCIALS
def SPND    = close(symbol = "SPND");     #  ENERGY

def S5CONDD_Weight = 1.0;
def S5CONSD_Weight = 1.0;
def S5HLTHD_Weight = 1.0;
def S5INDUD_Weight = 1.0;
def S5INFTD_Weight = 1.0;
def S5MATRD_Weight = 1.0;
def S5REASD_Weight = 1.0;
def S5TELSD_Weight = 1.0;
def S5UTILD_Weight = 1.0;
def SPFD_Weight = 1.0;
def SPND_Weight = 1.0;


AddLabel(yes, "S5CONDD  " + S5CONDD, color.black);
AddLabel(yes, "S5CONSD  " + S5CONSD, color.black);
AddLabel(yes, "S5HLTHD  " + S5HLTHD, color.black);
AddLabel(yes, "S5INDUD  " + S5INDUD, color.black);
AddLabel(yes, "S5INFTD  " + S5INFTD, color.black);
AddLabel(yes, "S5MATRD  " + S5MATRD, color.black);
AddLabel(yes, "S5REASD  " + S5REASD, color.black);
AddLabel(yes, "S5TELSD  " + S5TELSD, color.black);
AddLabel(yes, "S5UTILD  " + S5UTILD, color.black);
AddLabel(yes, "SPFD  "    + SPFD,    color.black);
AddLabel(yes, "SPND  "    + SPND,    color.black);


plot weighted_total = (S5CONDD * S5CONDD_weight) + (S5CONSD * S5CONSD_weight) + (S5HLTHD * S5HLTHD_weight) + (S5INDUD * S5INDUD_weight) + (S5INFTD * S5INFTD_weight) + (S5MATRD * S5MATRD_weight) + (S5REASD * S5REASD_weight) + (S5TELSD * S5TELSD_weight) + (S5UTILD * S5UTILD_weight) + (SPFD * SPFD_weight) + (SPND * SPND_weight);

plot unweighted_total = (S5CONDD + S5CONSD + S5HLTHD + S5INDUD + S5INFTD + S5MATRD + S5REASD + S5TELSD + S5UTILD + SPFD + SPND) / 11;

-mashume
 
Last edited:

maddy91

New member
It could be done (since they have at that site and want $95 for their work).

I don't know what the sector tickers are through ThinkOrSwim, and I stole these from the trading view website, and I don't know the weightings, but it might go something like this:

Code:
declare lower;

def S5CONDD = close(symbol = "S5CONDD");  #  CONSUMER DISCRETIONARY
def S5CONSD = close(symbol = "S5CONSD");  #  CONSUMER STAPLES
def S5HLTHD = close(symbol = "S5HLTHD");  #  HEALTH CARE
def S5INDUD = close(symbol = "S5INDUD");  #  INDUSTRIALS
def S5INFTD = close(symbol = "S5INFTD");  #  INFORMATION TECHNOLOGY
def S5MATRD = close(symbol = "S5MATRD");  #  MATERIALS
def S5REASD = close(symbol = "S5REASD");  #  REAL ESTATE
def S5TELSD = close(symbol = "S5TELSD");  #  COMMUNICATION SERVICES
def S5UTILD = close(symbol = "S5UTILD");  #  UTILITIES
def SPFD    = close(symbol = "SPFD");     #  FINANCIALS
def SPND    = close(symbol = "SPND");     #  ENERGYdef S5CONDD = close(symbol = "S5CONDD");  #  CONSUMER DISCRETIONARY


def S5CONDD_Weight = 1.0;
def S5CONSD_Weight = 1.0;
def S5HLTHD_Weight = 1.0;
def S5INDUD_Weight = 1.0;
def S5INFTD_Weight = 1.0;
def S5MATRD_Weight = 1.0;
def S5REASD_Weight = 1.0;
def S5TELSD_Weight = 1.0;
def S5UTILD_Weight = 1.0;
def SPFD_Weight = 1.0;
def SPND_Weight = 1.0;


AddLabel(yes, "S5CONDD  " + S5CONDD, color.black);
AddLabel(yes, "S5CONSD  " + S5CONSD, color.black);
AddLabel(yes, "S5HLTHD  " + S5HLTHD, color.black);
AddLabel(yes, "S5INDUD  " + S5INDUD, color.black);
AddLabel(yes, "S5INFTD  " + S5INFTD, color.black);
AddLabel(yes, "S5MATRD  " + S5MATRD, color.black);
AddLabel(yes, "S5REASD  " + S5REASD, color.black);
AddLabel(yes, "S5TELSD  " + S5TELSD, color.black);
AddLabel(yes, "S5UTILD  " + S5UTILD, color.black);
AddLabel(yes, "SPFD  "    + SPFD,    color.black);
AddLabel(yes, "SPND  "    + SPND,    color.black);


plot sumTotal = (S5CONDD * S5CONDD_weight) + (S5CONSD * S5CONSD_weight) + (S5HLTHD * S5HLTHD_weight) + (S5INDUD * S5INDUD_weight) + (S5INFTD * S5INFTD_weight) + (S5MATRD * S5MATRD_weight) + (S5REASD * S5REASD_weight) + (S5TELSD * S5TELSD_weight) + (S5UTILD * S5UTILD_weight) + (SPFD * SPFD_weight) + (SPND * SPND_weight);

-mashume
Is this supposed work ?nothing's showing up
 

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.
Top