I am wondering if anyone has a similar indicator of this by Shadow Trader? Its a weighted version of the Advance/Decline
https://www.shadowtrader.net/weighted-ad-line-thinkscript/
https://www.shadowtrader.net/weighted-ad-line-thinkscript/
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
It is used to see the difference between the weighted sectors vs. unweightedSomething isn't right here.
- The Advance/Decline ($ADSPD) represents the cumulative difference between the number of advancing and declining stocks within SPX.
Example: NWS (weight 0.000715 in the SPX) have the same "$ADSPD weight" as the 1000 times bigger AAPL (weight 7.074 in the SPX)
- The Weighted Advance/Decline distributes the "weight" based on the sectors XLK 27.6%, XLV 13.5%, XLV 12.7%, etc.)
Watch begining it's a companion to advance/ decline line. It is used to see the difference between the weighted sectors vs. unweightedThe indicator called Weighted_SPX_Sector_AD
There are no references to the advance/decline of individual sectors, or to anything else like $ADD, $ADSPD, or to any other advance/decline data, weighted or otherwise, whatsoever, at any point within the actual code of this indicator.
# # Sources:
# https://siblisresearch.com/data/us-sector-weightings/
# https://seekingalpha.com/etfs-and-funds/etf-tables/sectors
# https://www.spglobal.com/spdji/en/indices/equity/sp-500/#data
# debug
declare lower;
declare once_per_bar;
input open_time = 930;
input ConsumerStaples = 5.88; #XLP
input Utilities = 2.5; #XLU
input Communications = 10.16; #XLC
input Financials = 10.69; #XLF
input Materials = 2.56; #XLB
input Industrials = 7.77; #XLI
input Energy = 2.67; #XLE
input RealEstate = 2.77; #XLRE
input HealthCare = 13.29; #XLV
input InformationTechnology = 29.17; #XLK
input ConsumerDiscretionary = 12.54; #XLY
input sticker = "SPX";
def SectorCount = 11;
def NewDay = SecondsFromTime(open_time) < SecondsFromTime(open_time)[1];
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 xlkprice = open("XLK");
def xlvprice = open("XLV");
def xlyprice = open("XLY");
def xlfprice = open("XLF");
def xlcprice = open("XLC");
def xliprice = open("XLI");
def xlpprice = open("XLP");
def xleprice = open("XLE");
def xlreprice = open("XLRE");
def xlbprice = open("XLB");
def xluprice = open("XLU");
def xlkChangePercent = (xlk - xlkprice) / xlkprice;
def xlvChangePercent = (xlv - xlvprice) / xlvprice;
def xlyChangePercent = (xly - xlyprice) / xlyprice;
def xlfChangePercent = (xlf - xlfprice) / xlfprice;
def xlcChangePercent = (xlc - xlcprice) / xlcprice;
def xliChangePercent = (xli - xliprice) / xliprice;
def xlpChangePercent = (xlp - xlpprice) / xlpprice;
def xleChangePercent = (xle - xleprice) / xleprice;
def xlreChangePercent = (xlre - xlreprice) / xlreprice;
def xlbChangePercent = (xlb - xlbprice) / xlbprice;
def xluChangePercent = (xlu - xluprice) / xluprice;
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 = 6000 * (
xlkSizing +
xlvSizing +
xlySizing +
xlfSizing +
xlcSizing +
xliSizing +
xlpSizing +
xleSizing +
xlreSizing +
xlbSizing +
xluSizing
) / SectorCount;
def cumuCombinedSizing = if NewDay then combinedSizing else cumuCombinedSizing[1] + combinedSizing;
# Display
plot cumuSectorWeightAD = if !IsNaN(combinedSizing) then cumuCombinedSizing else Double.NaN;
cumuSectorWeightAD.AssignValueColor(if cumuSectorWeightAD < cumuSectorWeightAD[1] then Color.YELLOW else Color.MAGENTA);
cumuSectorWeightAD.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plot zeroLine = 0;
zeroLine.AssignValueColor(Color.WHITE);
zeroLine.HideBubble();
zeroLine.HideTitle();
def spx = close("SPX");
def spxprice = open("SPX");
def spxChangePercent = (spx - spxprice) / spxprice;
def spxSizing = spxChangePercent * 100 / SectorCount;
def spxcombinedSizing = spxSizing * 6000;
def cumuSPX = if NewDay then spxcombinedSizing else cumuSPX[1] + spxcombinedSizing;
plot cumuSPXAD = if spxChangePercent != 0 then cumuSPX else Double.NaN ;
cumuSPXAD.AssignValueColor(Color.white);
cumuSPXAD.SetPaintingStrategy(PaintingStrategy.LINE);
This is what im seeing vs. yours. Very close as day progressed Monday and later Friday. But beginning of both days look very differentthis is what I get so far. I am not sure calculations are correct.
Code:# # Sources: # https://siblisresearch.com/data/us-sector-weightings/ # https://seekingalpha.com/etfs-and-funds/etf-tables/sectors # https://www.spglobal.com/spdji/en/indices/equity/sp-500/#data # debug declare lower; declare once_per_bar; input open_time = 930; input ConsumerStaples = 5.88; #XLP input Utilities = 2.5; #XLU input Communications = 10.16; #XLC input Financials = 10.69; #XLF input Materials = 2.56; #XLB input Industrials = 7.77; #XLI input Energy = 2.67; #XLE input RealEstate = 2.77; #XLRE input HealthCare = 13.29; #XLV input InformationTechnology = 29.17; #XLK input ConsumerDiscretionary = 12.54; #XLY input sticker = "SPX"; def SectorCount = 11; def NewDay = SecondsFromTime(open_time) < SecondsFromTime(open_time)[1]; 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 xlkprice = open("XLK"); def xlvprice = open("XLV"); def xlyprice = open("XLY"); def xlfprice = open("XLF"); def xlcprice = open("XLC"); def xliprice = open("XLI"); def xlpprice = open("XLP"); def xleprice = open("XLE"); def xlreprice = open("XLRE"); def xlbprice = open("XLB"); def xluprice = open("XLU"); def xlkChangePercent = (xlk - xlkprice) / xlkprice; def xlvChangePercent = (xlv - xlvprice) / xlvprice; def xlyChangePercent = (xly - xlyprice) / xlyprice; def xlfChangePercent = (xlf - xlfprice) / xlfprice; def xlcChangePercent = (xlc - xlcprice) / xlcprice; def xliChangePercent = (xli - xliprice) / xliprice; def xlpChangePercent = (xlp - xlpprice) / xlpprice; def xleChangePercent = (xle - xleprice) / xleprice; def xlreChangePercent = (xlre - xlreprice) / xlreprice; def xlbChangePercent = (xlb - xlbprice) / xlbprice; def xluChangePercent = (xlu - xluprice) / xluprice; 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 = 6000 * ( xlkSizing + xlvSizing + xlySizing + xlfSizing + xlcSizing + xliSizing + xlpSizing + xleSizing + xlreSizing + xlbSizing + xluSizing ) / SectorCount; def cumuCombinedSizing = if NewDay then combinedSizing else cumuCombinedSizing[1] + combinedSizing; # Display plot cumuSectorWeightAD = if !IsNaN(combinedSizing) then cumuCombinedSizing else Double.NaN; cumuSectorWeightAD.AssignValueColor(if cumuSectorWeightAD < cumuSectorWeightAD[1] then Color.YELLOW else Color.MAGENTA); cumuSectorWeightAD.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); plot zeroLine = 0; zeroLine.AssignValueColor(Color.WHITE); zeroLine.HideBubble(); zeroLine.HideTitle(); def spx = close("SPX"); def spxprice = open("SPX"); def spxChangePercent = (spx - spxprice) / spxprice; def spxSizing = spxChangePercent * 100 / SectorCount; def spxcombinedSizing = spxSizing * 6000; def cumuSPX = if NewDay then spxcombinedSizing else cumuSPX[1] + spxcombinedSizing; plot cumuSPXAD = if spxChangePercent != 0 then cumuSPX else Double.NaN ; cumuSPXAD.AssignValueColor(Color.white); cumuSPXAD.SetPaintingStrategy(PaintingStrategy.LINE);
![]()
Thanks, i think the script is working good except for the start, from what i am seeing on ShadowTraders screen, he is skipping the first bar of the day, if i am looking at 5min chart, i only see 5 bars on his screenshot, but in this script we have 6 bars. How can we skip the first bar on a given day?this is what I get so far. I am not sure calculations are correct.
Code:# # Sources: # https://siblisresearch.com/data/us-sector-weightings/ # https://seekingalpha.com/etfs-and-funds/etf-tables/sectors # https://www.spglobal.com/spdji/en/indices/equity/sp-500/#data # debug declare lower; declare once_per_bar; input open_time = 930; input ConsumerStaples = 5.88; #XLP input Utilities = 2.5; #XLU input Communications = 10.16; #XLC input Financials = 10.69; #XLF input Materials = 2.56; #XLB input Industrials = 7.77; #XLI input Energy = 2.67; #XLE input RealEstate = 2.77; #XLRE input HealthCare = 13.29; #XLV input InformationTechnology = 29.17; #XLK input ConsumerDiscretionary = 12.54; #XLY input sticker = "SPX"; def SectorCount = 11; def NewDay = SecondsFromTime(open_time) < SecondsFromTime(open_time)[1]; 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 xlkprice = open("XLK"); def xlvprice = open("XLV"); def xlyprice = open("XLY"); def xlfprice = open("XLF"); def xlcprice = open("XLC"); def xliprice = open("XLI"); def xlpprice = open("XLP"); def xleprice = open("XLE"); def xlreprice = open("XLRE"); def xlbprice = open("XLB"); def xluprice = open("XLU"); def xlkChangePercent = (xlk - xlkprice) / xlkprice; def xlvChangePercent = (xlv - xlvprice) / xlvprice; def xlyChangePercent = (xly - xlyprice) / xlyprice; def xlfChangePercent = (xlf - xlfprice) / xlfprice; def xlcChangePercent = (xlc - xlcprice) / xlcprice; def xliChangePercent = (xli - xliprice) / xliprice; def xlpChangePercent = (xlp - xlpprice) / xlpprice; def xleChangePercent = (xle - xleprice) / xleprice; def xlreChangePercent = (xlre - xlreprice) / xlreprice; def xlbChangePercent = (xlb - xlbprice) / xlbprice; def xluChangePercent = (xlu - xluprice) / xluprice; 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 = 6000 * ( xlkSizing + xlvSizing + xlySizing + xlfSizing + xlcSizing + xliSizing + xlpSizing + xleSizing + xlreSizing + xlbSizing + xluSizing ) / SectorCount; def cumuCombinedSizing = if NewDay then combinedSizing else cumuCombinedSizing[1] + combinedSizing; # Display plot cumuSectorWeightAD = if !IsNaN(combinedSizing) then cumuCombinedSizing else Double.NaN; cumuSectorWeightAD.AssignValueColor(if cumuSectorWeightAD < cumuSectorWeightAD[1] then Color.YELLOW else Color.MAGENTA); cumuSectorWeightAD.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); plot zeroLine = 0; zeroLine.AssignValueColor(Color.WHITE); zeroLine.HideBubble(); zeroLine.HideTitle(); def spx = close("SPX"); def spxprice = open("SPX"); def spxChangePercent = (spx - spxprice) / spxprice; def spxSizing = spxChangePercent * 100 / SectorCount; def spxcombinedSizing = spxSizing * 6000; def cumuSPX = if NewDay then spxcombinedSizing else cumuSPX[1] + spxcombinedSizing; plot cumuSPXAD = if spxChangePercent != 0 then cumuSPX else Double.NaN ; cumuSPXAD.AssignValueColor(Color.white); cumuSPXAD.SetPaintingStrategy(PaintingStrategy.LINE);
![]()
There are no references to the advance/decline of individual sectors, or to anything else like $ADD, $ADSPD, or to any other advance/decline data, weighted or otherwise, whatsoever, at any point within the actual code of this indicator.
I've been trying to follow along and I'm a little confused.
I agree w/ your comments about how comparing to SPX doesn't make sense.... but I'm not sure that's what their indicator does.
Are you assuming they are using SPX? Or are you looking at their actual script? (I can't tell if you are talking about the ones posted in this thread or their actual version).
And if you are looking at their actual script, are you saying they use SPX as the "unweighted" line instead of $ADSPD (scaled) or a cumulative total of sector % changes - all being treated equally - added together?
FWIW - the difference in bar colors is just to indicate if it moved up or down versus the previous bar (purple up, yellow down) - it does not tell you anything about specific sectors. Just how the weighted sectors are doing versus unweighted (the line). So each bar - no matter the color - represents all the sectors as weighted by SPX. Colors are just to discern direction/ movement.I Change the color to Light Red and Light Green, I agree it really is just a visual of the Sector status above.
it needs a better display to let you know what sector is really driving the move
Oh... I like your thought on different colors for each sectors delta change. Even if it used the main color for the sector that changed the most. That would beI guess we could adjust the colors to change according to which sector has the most delta change but it will look like a rainbow and
hard to follow. Even if you knew what sector was up or down the most, how could this help you decide if your stock choice is the right one for today's or tomorrow's play?
Should be:def O = if isFirstBar then close(Sym) else O[1];
def O = if isFirstBar then Open(Sym) else O[1];
declare lower;
script PC {
input Sym = "SPY";
def isFirstBar = GetTime() == RegularTradingStart(GetYYYYMMDD()) + 1;
def O = if isFirstBar then close(Sym) else O[1];
def C = close(Sym);
plot PC = (C - O) / O;
}
def cXLK = PC("XLK");
def cXLY = PC("XLY");
def cXLV = PC("XLV");
def cXLF = PC("XLF");
def cXLC = PC("XLC");
def cXLI = PC("XLI");
def cXLP = PC("XLP");
def cXLRE = PC("XLRE");
def cXLE = PC("XLE");
def cXLB = PC("XLB");
def cXLU = PC("XLU");
def wXLK = cXLK * 27.9;
def wXLY = cXLY * 11.9;
def wXLV = cXLV * 13.4;
def wXLF = cXLF * 11.2;
def wXLC = cXLC * 11.5;
def wXLI = cXLI * 8.2;
def wXLP = cXLP * 5.8;
def wXLRE = cXLRE * 2.6;
def wXLE = cXLE * 2.4;
def wXLB = cXLB * 2.6;
def wXLU = cXLU * 2.5;
def wTotal =
wXLK + wXLY + wXLV +
wXLF + wXLC + wXLI +
wXLP + wXLRE + wXLE +
wXLB + wXLU
;
def uTotal =
cXLK + cXLY + cXLV +
cXLF + cXLC + cXLI +
cXLP + cXLRE + cXLE +
cXLB + cXLU
;
plot Histo = wtotal / 11;
plot Line = utotal ;
Line.setDefaultColor(color.gray);
Line.setlineWeight(1);
Histo.setpaintingStrategy(paintingStrategy.HISTOGRAM);
Histo.assignvalueColor(if Histo > Histo[1] then color.plum else color.yellow);
Histo.setlineWeight(1);
plot z = 0;
thanks. I'll give it a try.I've been busy, calm down. I also was experimenting with alternatives using the actual Equal Weight Sector Indexes and the Standard Indexes, so you wouldn't need the weighting tables. The code was a bit ripped up and I had to put it back. I've also cleaned it up for your guys and also changed it to use Script{} in case you want to experiment farther. It takes some time to put all this together.
Anyway, in order for it to “match”, the weighting tables need to be the same as what you're comparing it to. We basically have samples from the video, and the screen shot that strange posted. I set the weights back to what they were in the video for the best match.
Forgive the MSPAINT distortions from lining up the images in the thin gray line
Luckily, strange's post doesn't include any updates to the weighting tables either, so we can still use that as well. He also has the real code I believe, so go ahead and ask him if you have any doubts about my code.
However, its not actually supposed match anymore. Price is a factor in market capitalization, sector weighting is dynamic. You're going to need to go to this page and update them, or else you're dealing with weights that are months out of date. Check it fairly frequently, it changes every day. It actually changes moment to moment in live markets, but this snap shot from yesterday is the closest thing.
![]()
(XLP in the script is 5.8)
This part is important; Its also apparently using the close of the first bar to establish the zero line for each day. This is why the first bar always appears to be skipped. This is wrong and it really should be changed to measure from the actual open, but I left it as close because that's the match.
This line:
Should be:
Code:declare lower; script PC { input Sym = "SPY"; def isFirstBar = GetTime() == RegularTradingStart(GetYYYYMMDD()) + 1; def O = if isFirstBar then close(Sym) else O[1]; def C = close(Sym); plot PC = (C - O) / O; } def cXLK = PC("XLK"); def cXLY = PC("XLY"); def cXLV = PC("XLV"); def cXLF = PC("XLF"); def cXLC = PC("XLC"); def cXLI = PC("XLI"); def cXLP = PC("XLP"); def cXLRE = PC("XLRE"); def cXLE = PC("XLE"); def cXLB = PC("XLB"); def cXLU = PC("XLU"); def wXLK = cXLK * 27.9; def wXLY = cXLY * 11.9; def wXLV = cXLV * 13.4; def wXLF = cXLF * 11.2; def wXLC = cXLC * 11.5; def wXLI = cXLI * 8.2; def wXLP = cXLP * 5.8; def wXLRE = cXLRE * 2.6; def wXLE = cXLE * 2.4; def wXLB = cXLB * 2.6; def wXLU = cXLU * 2.5; def wTotal = wXLK + wXLY + wXLV + wXLF + wXLC + wXLI + wXLP + wXLRE + wXLE + wXLB + wXLU ; def uTotal = cXLK + cXLY + cXLV + cXLF + cXLC + cXLI + cXLP + cXLRE + cXLE + cXLB + cXLU ; plot Histo = wtotal / 11; plot Line = utotal ; Line.setDefaultColor(color.gray); Line.setlineWeight(1); Histo.setpaintingStrategy(paintingStrategy.HISTOGRAM); Histo.assignvalueColor(if Histo > Histo[1] then color.plum else color.yellow); Histo.setlineWeight(1); plot z = 0;
Here are the Equal Weights if you want to experiment with those too:
![]()
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
T | Volume Weighted RSI For ThinkOrSwim | Questions | 2 | |
P | Stochastic Weighted Moving Averages for ThinkorSwim | Custom | 0 | |
S | Scan for Weighted Alpha | Questions | 1 | |
J | GWAP - Gamma Weighted Average Price | Questions | 5 | |
J | Formulas for a Fibonacci Weighted Moving Average | Questions | 11 |
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.
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.