Weighted Advance/Decline For ThinkOrSwim

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

From shadowtrader:
Before we get into the examples, a little refresher. The S&P 500 is made up of 500 stocks which are organized into 11 different sectors. As the index is capitalization weighted, the stocks in those sectors give each sector a certain weight in the S&P. (think: Apple moves the market more than Coca Cola) The differences in these sector weights are quite large with technology (XLK) making up almost 30% of the S&P, while sectors like Energy, Utilities, and Real Estate are each less than 3% of the S&P. A regular advance decline line would be unweighted because every stock that is green adds one to the total and every stock that is red subtracts one from it. But if Apple and Coca-Cola are both down by the same amount, Apple is going to drag the S&P down a lot more than Coca-Cola will.

Thus, it would be extremely beneficial if we could figure out what the heavier weighted stocks are doing during the course of a day. As it would be unwieldy and hard to calculate that many stocks on the fly, we do it with the 11 sectors instead. Our script measures the advances and declines from the open of all the sectors and then gives you the choice of plotting them against each other any way you’d like. In our examples, we are using a white line for the unweighted sectors and the purple and yellow histogram for the weighted ones.
 
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

MAwQcvE.png


If you take SPY, and chop it up into sectors like XLF, XLK, and so on... and then you measure the percentage change of each sector, and apply the proper weighting to those changes relative to each sector's weighting in SPY, and then combine those weighted changes back together... you just end up right back where you started, with the percentage change of SPY itself, but in a more error-prone manner. Its like tearing up a piece of paper, and taping it back together, and only then trying to read what is written on it. Its a complete waste of time.

Its literally just the percentage change of SPY/SPX, that's it... I am not joking. These guys are selling a SPX percent change histogram.
 
Last edited:
- 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.)
 
- 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.)

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.
 
The 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.
Watch begining it's a companion to advance/ decline line. It is used to see the difference between the weighted sectors vs. unweighted
 
Last edited by a moderator:
This is the version of the upper study.




# begin script

# track the SP500 ETF sectors in RTH since open print
# script seems to work only if "extended hours" option is turned off in the chart

# the labels display the percentage move of the sector since the opening print

# color code is conventional - GREEN if positive, RED if negative and gray if unchanged



declare upper;

input XLY = "XLY";
input XLK = "XLK";
input XLI = "XLI";
input XLB = "XLB";
input XLE = "XLE";
input XLP = "XLP";
input XLV = "XLV";
input XLU = "XLU";
input XLF = "XLF";
input XLC = "XLC";
input XLRE = "XLRE";

def aggregationPeriod = AggregationPeriod.DAY; #

def XLKprice = open(XLK, period = aggregationPeriod);
def XLKdiff = close (XLK) - open(XLK, period = aggregationPeriod);
def XLK_d_pct = 100 * XLKdiff / XLKprice;
AddLabel(yes, "InfoTech 27.9%: " + XLK_d_pct, (if XLKdiff > 0 then
Color.GREEN else if XLKdiff<0 then color.red else Color.gray ));

def XLVprice = open(XLV, period = aggregationPeriod);
def XLVdiff = close (XLV) - open(XLV, period = aggregationPeriod);
def XLV_d_pct = 100 * XLVdiff / XLVprice;
AddLabel(yes, "Healthcare 13.4%: " + XLV_d_pct, (if XLVdiff > 0 then
Color.GREEN else if XLVdiff<0 then color.red else Color.gray ));

def XLYprice = open(XLY, period = aggregationPeriod);
def XLYdiff = close (XLY) - open(XLY, period = aggregationPeriod);
def XLY_d_pct = 100 * XLYdiff / XLYprice;
AddLabel(yes, "ConsDisc 11.9%: " + XLY_d_pct, (if XLYdiff > 0 then
Color.GREEN else if XLYdiff<0 then color.red else Color.gray ));

def XLCprice = open(XLC, period = aggregationPeriod);
def XLCdiff = close (XLC) - open(XLC, period = aggregationPeriod);
def XLC_d_pct = 100 * XLCdiff / XLCprice;
AddLabel(yes, "Comms 11.5%: " + XLC_d_pct, (if XLCdiff > 0 then
Color.GREEN else if XLCdiff<0 then color.red else Color.gray ));
 
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);

Screen-Shot-2022-02-07-at-3-53-03-PM.png
 
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);

Screen-Shot-2022-02-07-at-3-53-03-PM.png
This is what im seeing vs. yours. Very close as day progressed Monday and later Friday. But beginning of both days look very different
Screenshot-20220208-082126.png
 
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);

Screen-Shot-2022-02-07-at-3-53-03-PM.png
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?
 
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?
 
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?

I am not looking at their actual script, but I was able to easily duplicate the results of their script exactly. It is entirely based on the combined percentage changes of the sector ETF prices and nothing else. In one case, the change is weighted by the sectors' overall weight within the index, and in the other case it is equally treated.
 
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
 
Last edited by a moderator:
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
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.
 
Last edited:
I 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?
 
I 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?
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 be 🔥

The indicator is helpful to know if the S&P 's current trend is strong or weak....

So for example - if the weighted sectors are leading - there's a good chance the S&P is weak & will start trending down (since stocks like MSFT / AAPL are holding it up). So that's when I might buy a Spy Put (taking in other factors as well though not just solely based on the indicator).

I'm not so sure it's a good indicator to pick specific stocks - although knowing the S&P is strong when you buy an equity that's in the S&P would be a good confirmation of a good time to buy...

IMHO - this is more for daytrading or Futures.. but that's also the lens I look through. So there could be other ways to use it that I don't easily see.
 
Last edited:
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.

O3jEQUF.png

(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:
def O = if isFirstBar then close(Sym) else O[1];​
Should be:
def O = if isFirstBar then Open(Sym) else O[1];​

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:
S9NgpIF.png
 
Last edited by a moderator:
I don't have the code .....or I wouldn't be wasting my time with this thread. I post the screen shots to HELP. The weights are correct in my most recent post. I see the 6.2 in the top of pic. I can't code so I'm trying to "help" with visual of real thing. Yes the creator of the script says it needs to be updated as the weights change (I think monthly or qrtly). I see the value to this script. It's hard to get behind something that you view in a negative light. thanks for FINALLY posting it. Let's see if with everyone on the same page now we can tweak and come up with a close facsimile. 👍
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
404 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