Sector Histogram

woulf1004

Active member
VIP
Hi All,

I have made slight changes to add markets of interest for quick over view. Now that we have the SPX, NDX, DJI, COMP and RUT. Can someone create a lower single indicator that plots a histogram for these markets that has a zero line? Plot bullish in color green if is above zero or red when bearish when it's below zero. This zero line should also change colors based on bullish or bearish sentiment.

Code:
# S&P 500 Sector Performance (Percentage)
# Paris
# 4.12.2018
# After reviewing chubbyboy's S&P sector study, I thought it might
# be a good idea to display labels of relative S&P sector performance
# in percentages. At one glance this will enable us to determine
# which sectors are happening and which are not. Decided to use a
# script() to retrieve the data. Also, I changed the formula slightly.
# The percentage displayed is the current price as a percentage over
# yesterday's closing rather than the open today as was used in chubbyboy's
# study.
#====== Further Modified by Killing Hours ======#
# 5/4/2020 #
# Added Color Mapping #
# to distinguish more suddle movements #
#===============================================#
#Modified slightly by Headhunter20.


######################################################################################
script Sector {
input symb = "SPX";
def c = close(symbol = symb, period = AggregationPeriod.day);
def PctChg = (c / c[1]) - 1;
plot pct = PctChg;
}

#Define the color map. Change as you see fit
DefineGlobalColor("VeryGood", CreateColor(4, 216, 22));
DefineGlobalColor("Good", CreateColor(46, 216, 4));
DefineGlobalColor("ModGood", CreateColor(121, 216, 4));
DefineGlobalColor("SlightlyGood", CreateColor(167, 216, 4));
DefineGlobalColor("SluggishGood", CreateColor(210,252,126));
DefineGlobalColor("Neutral", CreateColor(252, 231, 126));
DefineGlobalColor("SluggishBad", CreateColor(252,168,126));
DefineGlobalColor("SlightlyBad", CreateColor(216, 163, 4));
DefineGlobalColor("ModBad", CreateColor(216, 117, 4));
DefineGlobalColor("Bad", CreateColor(216, 43, 4));
DefineGlobalColor("VeryBad", CreateColor(216, 4, 4));

# SPX Overall
def SPX = Sector("SPX");
def spxPer = round(SPX,4) * 100;
def CurrSP = +close("SPX", period = AggregationPeriod.DAY);
def ChangeSP = CurrSP - CurrSP[1];

addLabel(1, "S&P500: "+ CurrSP + " Chg: " + ChangeSP + "  (" + spxPer + "%" + ")   ", if ChangeSP > 0 then color.cyan else if ChangeSP < 0 then color.gray else if spxPer > 0 then COLOR.CYAN else color.gray);

# Energy Sector
def Energy = Sector("$SP500#10");
def engPer = round(Energy,4) * 100;
AddLabel(
1,
"Energy: "+engPer+"% XLE #10",
if engPer > 1.50 then GlobalColor("VeryGood") else
if engPer > 1 && engPer <= 1.50 then GlobalColor("Good") else
if engPer > .5 && engPer <= 1 then GlobalColor("ModGood") else
if engPer > .25 && engPer <= .5 then GlobalColor("SlightlyGood") else
if engPer > 0 && engPer <= .25 then GlobalColor("SluggishGood") else
if engPer == 0 then GlobalColor("Neutral") else
if engPer < 0 && engPer >= -.25 then GlobalColor("SluggishBad") else
if engPer < -.25 && engPer >= -.5 then GlobalColor("SlightlyBad") else
if engPer < -.5 && engPer >= -1 then GlobalColor("ModBad") else
if engPer < -1 && engPer >= -1.50 then GlobalColor("Bad") else
if engPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Consumer Discretionary Spending Sector
def ConDisr = Sector("$SP500#25");
def conDPer = round(ConDisr,4);
AddLabel(
1,
"Con. Discretionary: "+conDPer+"% XLY #25",
if conDPer > 1.50 then GlobalColor("VeryGood") else
if conDPer > 1 && conDPer <= 1.50 then GlobalColor("Good") else
if conDPer > .5 && conDPer <= 1 then GlobalColor("ModGood") else
if conDPer > .25 && conDPer <= .5 then GlobalColor("SlightlyGood") else
if conDPer > 0 && conDPer <= .25 then GlobalColor("SluggishGood") else
if conDPer == 0 then GlobalColor("Neutral") else
if conDPer < 0 && conDPer >= -.25 then GlobalColor("SluggishBad") else
if conDPer < -.25 && conDPer >= -.5 then GlobalColor("SlightlyBad") else
if conDPer < -.5 && conDPer >= -1 then GlobalColor("ModBad") else
if conDPer < -1 && conDPer >= -1.50 then GlobalColor("Bad") else
if conDPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Financial Sector
def Finance = Sector("$SP500#40");
def finPer = round(Finance,4) * 100;
AddLabel(
1,
"Financials: "+finPer+"% XLF #40",
if finPer > 1.50 then GlobalColor("VeryGood") else
if finPer > 1 && finPer <= 1.50 then GlobalColor("Good") else
if finPer > .5 && finPer <= 1 then GlobalColor("ModGood") else
if finPer > .25 && finPer <= .5 then GlobalColor("SlightlyGood") else
if finPer > 0 && finPer <= .25 then GlobalColor("SluggishGood") else
if finPer == 0 then GlobalColor("Neutral") else
if finPer < 0 && finPer >= -.25 then GlobalColor("SluggishBad") else
if finPer < -.25 && finPer >= -.5 then GlobalColor("SlightlyBad") else
if finPer < -.5 && finPer >= -1 then GlobalColor("ModBad") else
if finPer < -1 && finPer >= -1.50 then GlobalColor("Bad") else
if finPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Utilities Sector
def Utilities = Sector("$SP500#55");
def utiPer = round(Utilities,4) * 100;
AddLabel(
1,
"Utilities: "+utiPer+"% XLU #55",
if utiPer > 1.50 then GlobalColor("VeryGood") else
if utiPer > 1 && utiPer <= 1.50 then GlobalColor("Good") else
if utiPer > .5 && utiPer <= 1 then GlobalColor("ModGood") else
if utiPer > .25 && utiPer <= .5 then GlobalColor("SlightlyGood") else
if utiPer > 0 && utiPer <= .25 then GlobalColor("SluggishGood") else
if utiPer == 0 then GlobalColor("Neutral") else
if utiPer < 0 && utiPer >= -.25 then GlobalColor("SluggishBad") else
if utiPer < -.25 && utiPer >= -.5 then GlobalColor("SlightlyBad") else
if utiPer < -.5 && utiPer >= -1 then GlobalColor("ModBad") else
if utiPer < -1 && utiPer >= -1.50 then GlobalColor("Bad") else
if utiPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Materials Sector
def Materials = Sector("$SP500#15");
def matPer = round(Materials,4) * 100;
AddLabel(
1,
"Materials: "+matPer+"% XLB #15",
if matPer > 1.50 then GlobalColor("VeryGood") else
if matPer > 1 && matPer <= 1.50 then GlobalColor("Good") else
if matPer > .5 && matPer <= 1 then GlobalColor("ModGood") else
if matPer > .25 && matPer <= .5 then GlobalColor("SlightlyGood") else
if matPer > 0 && matPer <= .25 then GlobalColor("SluggishGood") else
if matPer == 0 then GlobalColor("Neutral") else
if matPer < 0 && matPer >= -.25 then GlobalColor("SluggishBad") else
if matPer < -.25 && matPer >= -.5 then GlobalColor("SlightlyBad") else
if matPer < -.5 && matPer >= -1 then GlobalColor("ModBad") else
if matPer < -1 && matPer >= -1.50 then GlobalColor("Bad") else
if matPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Consumer Staples Sector
def ConStaple = Sector("$SP500#30");
def conSPer = round(ConStaple,4) * 100;
AddLabel(
1,
"Consumer Staples: "+conSPer+"% XLP #30",
if conSPer > 1.50 then GlobalColor("VeryGood") else
if conSPer > 1 && conSPer <= 1.50 then GlobalColor("Good") else
if conSPer > .5 && conSPer <= 1 then GlobalColor("ModGood") else
if conSPer > .25 && conSPer <= .5 then GlobalColor("SlightlyGood") else
if conSPer > 0 && conSPer <= .25 then GlobalColor("SluggishGood") else
if conSPer == 0 then GlobalColor("Neutral") else
if conSPer < 0 && conSPer >= -.25 then GlobalColor("SluggishBad") else
if conSPer < -.25 && conSPer >= -.5 then GlobalColor("SlightlyBad") else
if conSPer < -.5 && conSPer >= -1 then GlobalColor("ModBad") else
if conSPer < -1 && conSPer >= -1.50 then GlobalColor("Bad") else
if conSPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Information Technology Sector
def InfoTech = Sector("$SP500#45");
def infPer = round(InfoTech,4) * 100;
AddLabel(
1,
"Info Tech: " +infPer+"% XLK #45",
if infPer > 1.50 then GlobalColor("VeryGood") else
if infPer > 1 && infPer <= 1.50 then GlobalColor("Good") else
if infPer > .5 && infPer <= 1 then GlobalColor("ModGood") else
if infPer > .25 && infPer <= .5 then GlobalColor("SlightlyGood") else
if infPer > 0 && infPer <= .25 then GlobalColor("SluggishGood") else
if infPer == 0 then GlobalColor("Neutral") else
if infPer < 0 && infPer >= -.25 then GlobalColor("SluggishBad") else
if infPer < -.25 && infPer >= -.5 then GlobalColor("SlightlyBad") else
if infPer < -.5 && infPer >= -1 then GlobalColor("ModBad") else
if infPer < -1 && infPer >= -1.50 then GlobalColor("Bad") else
if infPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Real Estate Sector
def RealEste = Sector("$SP500#60");
def reaPer = round(RealEste,4) * 100;
AddLabel(
1,
"Real Estate: " +reaPer+"% XLRE #60",
if reaPer > 1.50 then GlobalColor("VeryGood") else
if reaPer > 1 && reaPer <= 1.50 then GlobalColor("Good") else
if reaPer > .5 && reaPer <= 1 then GlobalColor("ModGood") else
if reaPer > .25 && reaPer <= .5 then GlobalColor("SlightlyGood") else
if reaPer > 0 && reaPer <= .25 then GlobalColor("SluggishGood") else
if reaPer == 0 then GlobalColor("Neutral") else
if reaPer < 0 && reaPer >= -.25 then GlobalColor("SluggishBad") else
if reaPer < -.25 && reaPer >= -.5 then GlobalColor("SlightlyBad") else
if reaPer < -.5 && reaPer >= -1 then GlobalColor("ModBad") else
if reaPer < -1 && reaPer >= -1.50 then GlobalColor("Bad") else
if reaPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);


# Industrial Sector
def Industrl = Sector("$SP500#20");
def indPer = round(Industrl,4) * 100;
AddLabel(
1,
"Industrials: " +indPer+"% XLI #20",
if indPer > 1.50 then GlobalColor("VeryGood") else
if indPer > 1 && indPer <= 1.50 then GlobalColor("Good") else
if indPer > .5 && indPer <= 1 then GlobalColor("ModGood") else
if indPer > .25 && indPer <= .5 then GlobalColor("SlightlyGood") else
if indPer > 0 && indPer <= .25 then GlobalColor("SluggishGood") else
if indPer == 0 then GlobalColor("Neutral") else
if indPer < 0 && indPer >= -.25 then GlobalColor("SluggishBad") else
if indPer < -.25 && indPer >= -.5 then GlobalColor("SlightlyBad") else
if indPer < -.5 && indPer >= -1 then GlobalColor("ModBad") else
if indPer < -1 && indPer >= -1.50 then GlobalColor("Bad") else
if indPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Healthcare Sector
def Health = Sector("$SP500#35");
def heaPer = round(Health,4) * 100;
AddLabel(
1,
"Health Care: " +heaPer+"% XLV #35",
if heaPer > 1.50 then GlobalColor("VeryGood") else
if heaPer > 1 && heaPer <= 1.50 then GlobalColor("Good") else
if heaPer > .5 && heaPer <= 1 then GlobalColor("ModGood") else
if heaPer > .25 && heaPer <= .5 then GlobalColor("SlightlyGood") else
if heaPer > 0 && heaPer <= .25 then GlobalColor("SluggishGood") else
if heaPer == 0 then GlobalColor("Neutral") else
if heaPer < 0 && heaPer >= -.25 then GlobalColor("SluggishBad") else
if heaPer < -.25 && heaPer >= -.5 then GlobalColor("SlightlyBad") else
if heaPer < -.5 && heaPer >= -1 then GlobalColor("ModBad") else
if heaPer < -1 && heaPer >= -1.50 then GlobalColor("Bad") else
if heaPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Telecommunication Sector
def Telecoms = Sector("$SP500#50");
def telPef = round(Telecoms,4) * 100;
AddLabel(
1,
"Telecoms: " +telPef+"% XLC #50",
if telPef > 1.50 then GlobalColor("VeryGood") else
if telPef > 1 && telPef <= 1.50 then GlobalColor("Good") else
if telPef > .5 && telPef <= 1 then GlobalColor("ModGood") else
if telPef > .25 && telPef <= .5 then GlobalColor("SlightlyGood") else
if telPef > 0 && telPef <= .25 then GlobalColor("SluggishGood") else
if telPef == 0 then GlobalColor("Neutral") else
if telPef < 0 && telPef >= -.25 then GlobalColor("SluggishBad") else
if telPef < -.25 && telPef >= -.5 then GlobalColor("SlightlyBad") else
if telPef < -.5 && telPef >= -1 then GlobalColor("ModBad") else
if telPef < -1 && telPef >= -1.50 then GlobalColor("Bad") else
if telPef < -1.50 then GlobalColor("VeryBad") else
Color.black
);

def NDX = Sector("NDX");
def ndxPer = Round(NDX, 4) * 100;
def CurrND = +close("NDX", period = AggregationPeriod.DAY);
def ChangeNDX = CurrND - CurrND[1];

addLabel(1, "NASD: "+CurrND +" Chg :" + ChangeNDX + "  (" + ndxPer + "%" + ")  ", if ChangeNDX > 0 then color.cyan else if ChangeNDX < 0 then color.light_gray else if ndxPer > 0 then COLOR.CYAN else color.light_gray);

def DJI = Sector("$DJI");
def djiPer = Round(DJI, 4) * 100;
def CurrDJ = +close("$DJI", period = AggregationPeriod.DAY);
def ChangeDJ = CurrDJ - CurrDJ[1];

addLabel(yes, (Concat("DJI: ", Round (CurrDJ, 1))) + " Chg: " + Round(ChangeDJ) + " (" + djiPer + "%" + ")  ", if ChangeDJ > 0 then color.cyan else if ChangeDJ < 0 then color.LIGHT_GRAY else if djiPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

def COMP = Sector("COMP:GIDS");
def compPer = Round(COMP, 4) * 100;
def CurrC = +close("COMP:GIDS", period = AggregationPeriod.DAY);
def ChangeC = CurrC - CurrC[1];

addLabel(yes, (Concat("COMP: ", Round (CurrC, 1))) + " Chg: " + Round(ChangeC) + " (" + compPer + "%" + ")  ", if ChangeC > 0 then color.cyan else if ChangeC < 0 then color.LIGHT_GRAY else if compPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

def RUT = Sector("RUT");
def rutPer = Round(RUT, 4) * 100;
def CurrRU = +close("RUT", period = AggregationPeriod.DAY);
def ChangeRU = CurrRU - CurrRU[1];

addLabel(yes, (Concat("RUT: ", Round (CurrRU, 1))) + " Chg: " + Round(ChangeRU) + " (" + rutPer + "%" + ")  ", if ChangeRU > 0 then color.cyan else if ChangeRU < 0 then color.LIGHT_GRAY else if rutPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

# End Study
 
Last edited by a moderator:
Hi All,

I have made slight changes to add markets of interest for quick over view. Now that we have the SPX, NDX, DJI, COMP and RUT. Can someone create a lower single indicator that plots a histogram for these markets that has a zero line? Plot bullish in color green if is above zero or red when bearish when it's below zero. This zero line should also change colors based on bullish or bearish sentiment.

Code:
# S&P 500 Sector Performance (Percentage)
# Paris
# 4.12.2018
# After reviewing chubbyboy's S&P sector study, I thought it might
# be a good idea to display labels of relative S&P sector performance
# in percentages. At one glance this will enable us to determine
# which sectors are happening and which are not. Decided to use a
# script() to retrieve the data. Also, I changed the formula slightly.
# The percentage displayed is the current price as a percentage over
# yesterday's closing rather than the open today as was used in chubbyboy's
# study.
#====== Further Modified by Killing Hours ======#
# 5/4/2020 #
# Added Color Mapping #
# to distinguish more suddle movements #
#===============================================#
#Modified slightly by Headhunter20.


######################################################################################
script Sector {
input symb = "SPX";
def c = close(symbol = symb, period = AggregationPeriod.day);
def PctChg = (c / c[1]) - 1;
plot pct = PctChg;
}

#Define the color map. Change as you see fit
DefineGlobalColor("VeryGood", CreateColor(4, 216, 22));
DefineGlobalColor("Good", CreateColor(46, 216, 4));
DefineGlobalColor("ModGood", CreateColor(121, 216, 4));
DefineGlobalColor("SlightlyGood", CreateColor(167, 216, 4));
DefineGlobalColor("SluggishGood", CreateColor(210,252,126));
DefineGlobalColor("Neutral", CreateColor(252, 231, 126));
DefineGlobalColor("SluggishBad", CreateColor(252,168,126));
DefineGlobalColor("SlightlyBad", CreateColor(216, 163, 4));
DefineGlobalColor("ModBad", CreateColor(216, 117, 4));
DefineGlobalColor("Bad", CreateColor(216, 43, 4));
DefineGlobalColor("VeryBad", CreateColor(216, 4, 4));

# SPX Overall
def SPX = Sector("SPX");
def spxPer = round(SPX,4) * 100;
def CurrSP = +close("SPX", period = AggregationPeriod.DAY);
def ChangeSP = CurrSP - CurrSP[1];

addLabel(1, "S&P500: "+ CurrSP + " Chg: " + ChangeSP + "  (" + spxPer + "%" + ")   ", if ChangeSP > 0 then color.cyan else if ChangeSP < 0 then color.gray else if spxPer > 0 then COLOR.CYAN else color.gray);

# Energy Sector
def Energy = Sector("$SP500#10");
def engPer = round(Energy,4) * 100;
AddLabel(
1,
"Energy: "+engPer+"% XLE #10",
if engPer > 1.50 then GlobalColor("VeryGood") else
if engPer > 1 && engPer <= 1.50 then GlobalColor("Good") else
if engPer > .5 && engPer <= 1 then GlobalColor("ModGood") else
if engPer > .25 && engPer <= .5 then GlobalColor("SlightlyGood") else
if engPer > 0 && engPer <= .25 then GlobalColor("SluggishGood") else
if engPer == 0 then GlobalColor("Neutral") else
if engPer < 0 && engPer >= -.25 then GlobalColor("SluggishBad") else
if engPer < -.25 && engPer >= -.5 then GlobalColor("SlightlyBad") else
if engPer < -.5 && engPer >= -1 then GlobalColor("ModBad") else
if engPer < -1 && engPer >= -1.50 then GlobalColor("Bad") else
if engPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Consumer Discretionary Spending Sector
def ConDisr = Sector("$SP500#25");
def conDPer = round(ConDisr,4);
AddLabel(
1,
"Con. Discretionary: "+conDPer+"% XLY #25",
if conDPer > 1.50 then GlobalColor("VeryGood") else
if conDPer > 1 && conDPer <= 1.50 then GlobalColor("Good") else
if conDPer > .5 && conDPer <= 1 then GlobalColor("ModGood") else
if conDPer > .25 && conDPer <= .5 then GlobalColor("SlightlyGood") else
if conDPer > 0 && conDPer <= .25 then GlobalColor("SluggishGood") else
if conDPer == 0 then GlobalColor("Neutral") else
if conDPer < 0 && conDPer >= -.25 then GlobalColor("SluggishBad") else
if conDPer < -.25 && conDPer >= -.5 then GlobalColor("SlightlyBad") else
if conDPer < -.5 && conDPer >= -1 then GlobalColor("ModBad") else
if conDPer < -1 && conDPer >= -1.50 then GlobalColor("Bad") else
if conDPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Financial Sector
def Finance = Sector("$SP500#40");
def finPer = round(Finance,4) * 100;
AddLabel(
1,
"Financials: "+finPer+"% XLF #40",
if finPer > 1.50 then GlobalColor("VeryGood") else
if finPer > 1 && finPer <= 1.50 then GlobalColor("Good") else
if finPer > .5 && finPer <= 1 then GlobalColor("ModGood") else
if finPer > .25 && finPer <= .5 then GlobalColor("SlightlyGood") else
if finPer > 0 && finPer <= .25 then GlobalColor("SluggishGood") else
if finPer == 0 then GlobalColor("Neutral") else
if finPer < 0 && finPer >= -.25 then GlobalColor("SluggishBad") else
if finPer < -.25 && finPer >= -.5 then GlobalColor("SlightlyBad") else
if finPer < -.5 && finPer >= -1 then GlobalColor("ModBad") else
if finPer < -1 && finPer >= -1.50 then GlobalColor("Bad") else
if finPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Utilities Sector
def Utilities = Sector("$SP500#55");
def utiPer = round(Utilities,4) * 100;
AddLabel(
1,
"Utilities: "+utiPer+"% XLU #55",
if utiPer > 1.50 then GlobalColor("VeryGood") else
if utiPer > 1 && utiPer <= 1.50 then GlobalColor("Good") else
if utiPer > .5 && utiPer <= 1 then GlobalColor("ModGood") else
if utiPer > .25 && utiPer <= .5 then GlobalColor("SlightlyGood") else
if utiPer > 0 && utiPer <= .25 then GlobalColor("SluggishGood") else
if utiPer == 0 then GlobalColor("Neutral") else
if utiPer < 0 && utiPer >= -.25 then GlobalColor("SluggishBad") else
if utiPer < -.25 && utiPer >= -.5 then GlobalColor("SlightlyBad") else
if utiPer < -.5 && utiPer >= -1 then GlobalColor("ModBad") else
if utiPer < -1 && utiPer >= -1.50 then GlobalColor("Bad") else
if utiPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Materials Sector
def Materials = Sector("$SP500#15");
def matPer = round(Materials,4) * 100;
AddLabel(
1,
"Materials: "+matPer+"% XLB #15",
if matPer > 1.50 then GlobalColor("VeryGood") else
if matPer > 1 && matPer <= 1.50 then GlobalColor("Good") else
if matPer > .5 && matPer <= 1 then GlobalColor("ModGood") else
if matPer > .25 && matPer <= .5 then GlobalColor("SlightlyGood") else
if matPer > 0 && matPer <= .25 then GlobalColor("SluggishGood") else
if matPer == 0 then GlobalColor("Neutral") else
if matPer < 0 && matPer >= -.25 then GlobalColor("SluggishBad") else
if matPer < -.25 && matPer >= -.5 then GlobalColor("SlightlyBad") else
if matPer < -.5 && matPer >= -1 then GlobalColor("ModBad") else
if matPer < -1 && matPer >= -1.50 then GlobalColor("Bad") else
if matPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Consumer Staples Sector
def ConStaple = Sector("$SP500#30");
def conSPer = round(ConStaple,4) * 100;
AddLabel(
1,
"Consumer Staples: "+conSPer+"% XLP #30",
if conSPer > 1.50 then GlobalColor("VeryGood") else
if conSPer > 1 && conSPer <= 1.50 then GlobalColor("Good") else
if conSPer > .5 && conSPer <= 1 then GlobalColor("ModGood") else
if conSPer > .25 && conSPer <= .5 then GlobalColor("SlightlyGood") else
if conSPer > 0 && conSPer <= .25 then GlobalColor("SluggishGood") else
if conSPer == 0 then GlobalColor("Neutral") else
if conSPer < 0 && conSPer >= -.25 then GlobalColor("SluggishBad") else
if conSPer < -.25 && conSPer >= -.5 then GlobalColor("SlightlyBad") else
if conSPer < -.5 && conSPer >= -1 then GlobalColor("ModBad") else
if conSPer < -1 && conSPer >= -1.50 then GlobalColor("Bad") else
if conSPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Information Technology Sector
def InfoTech = Sector("$SP500#45");
def infPer = round(InfoTech,4) * 100;
AddLabel(
1,
"Info Tech: " +infPer+"% XLK #45",
if infPer > 1.50 then GlobalColor("VeryGood") else
if infPer > 1 && infPer <= 1.50 then GlobalColor("Good") else
if infPer > .5 && infPer <= 1 then GlobalColor("ModGood") else
if infPer > .25 && infPer <= .5 then GlobalColor("SlightlyGood") else
if infPer > 0 && infPer <= .25 then GlobalColor("SluggishGood") else
if infPer == 0 then GlobalColor("Neutral") else
if infPer < 0 && infPer >= -.25 then GlobalColor("SluggishBad") else
if infPer < -.25 && infPer >= -.5 then GlobalColor("SlightlyBad") else
if infPer < -.5 && infPer >= -1 then GlobalColor("ModBad") else
if infPer < -1 && infPer >= -1.50 then GlobalColor("Bad") else
if infPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Real Estate Sector
def RealEste = Sector("$SP500#60");
def reaPer = round(RealEste,4) * 100;
AddLabel(
1,
"Real Estate: " +reaPer+"% XLRE #60",
if reaPer > 1.50 then GlobalColor("VeryGood") else
if reaPer > 1 && reaPer <= 1.50 then GlobalColor("Good") else
if reaPer > .5 && reaPer <= 1 then GlobalColor("ModGood") else
if reaPer > .25 && reaPer <= .5 then GlobalColor("SlightlyGood") else
if reaPer > 0 && reaPer <= .25 then GlobalColor("SluggishGood") else
if reaPer == 0 then GlobalColor("Neutral") else
if reaPer < 0 && reaPer >= -.25 then GlobalColor("SluggishBad") else
if reaPer < -.25 && reaPer >= -.5 then GlobalColor("SlightlyBad") else
if reaPer < -.5 && reaPer >= -1 then GlobalColor("ModBad") else
if reaPer < -1 && reaPer >= -1.50 then GlobalColor("Bad") else
if reaPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);


# Industrial Sector
def Industrl = Sector("$SP500#20");
def indPer = round(Industrl,4) * 100;
AddLabel(
1,
"Industrials: " +indPer+"% XLI #20",
if indPer > 1.50 then GlobalColor("VeryGood") else
if indPer > 1 && indPer <= 1.50 then GlobalColor("Good") else
if indPer > .5 && indPer <= 1 then GlobalColor("ModGood") else
if indPer > .25 && indPer <= .5 then GlobalColor("SlightlyGood") else
if indPer > 0 && indPer <= .25 then GlobalColor("SluggishGood") else
if indPer == 0 then GlobalColor("Neutral") else
if indPer < 0 && indPer >= -.25 then GlobalColor("SluggishBad") else
if indPer < -.25 && indPer >= -.5 then GlobalColor("SlightlyBad") else
if indPer < -.5 && indPer >= -1 then GlobalColor("ModBad") else
if indPer < -1 && indPer >= -1.50 then GlobalColor("Bad") else
if indPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Healthcare Sector
def Health = Sector("$SP500#35");
def heaPer = round(Health,4) * 100;
AddLabel(
1,
"Health Care: " +heaPer+"% XLV #35",
if heaPer > 1.50 then GlobalColor("VeryGood") else
if heaPer > 1 && heaPer <= 1.50 then GlobalColor("Good") else
if heaPer > .5 && heaPer <= 1 then GlobalColor("ModGood") else
if heaPer > .25 && heaPer <= .5 then GlobalColor("SlightlyGood") else
if heaPer > 0 && heaPer <= .25 then GlobalColor("SluggishGood") else
if heaPer == 0 then GlobalColor("Neutral") else
if heaPer < 0 && heaPer >= -.25 then GlobalColor("SluggishBad") else
if heaPer < -.25 && heaPer >= -.5 then GlobalColor("SlightlyBad") else
if heaPer < -.5 && heaPer >= -1 then GlobalColor("ModBad") else
if heaPer < -1 && heaPer >= -1.50 then GlobalColor("Bad") else
if heaPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Telecommunication Sector
def Telecoms = Sector("$SP500#50");
def telPef = round(Telecoms,4) * 100;
AddLabel(
1,
"Telecoms: " +telPef+"% XLC #50",
if telPef > 1.50 then GlobalColor("VeryGood") else
if telPef > 1 && telPef <= 1.50 then GlobalColor("Good") else
if telPef > .5 && telPef <= 1 then GlobalColor("ModGood") else
if telPef > .25 && telPef <= .5 then GlobalColor("SlightlyGood") else
if telPef > 0 && telPef <= .25 then GlobalColor("SluggishGood") else
if telPef == 0 then GlobalColor("Neutral") else
if telPef < 0 && telPef >= -.25 then GlobalColor("SluggishBad") else
if telPef < -.25 && telPef >= -.5 then GlobalColor("SlightlyBad") else
if telPef < -.5 && telPef >= -1 then GlobalColor("ModBad") else
if telPef < -1 && telPef >= -1.50 then GlobalColor("Bad") else
if telPef < -1.50 then GlobalColor("VeryBad") else
Color.black
);

def NDX = Sector("NDX");
def ndxPer = Round(NDX, 4) * 100;
def CurrND = +close("NDX", period = AggregationPeriod.DAY);
def ChangeNDX = CurrND - CurrND[1];

addLabel(1, "NASD: "+CurrND +" Chg :" + ChangeNDX + "  (" + ndxPer + "%" + ")  ", if ChangeNDX > 0 then color.cyan else if ChangeNDX < 0 then color.light_gray else if ndxPer > 0 then COLOR.CYAN else color.light_gray);

def DJI = Sector("$DJI");
def djiPer = Round(DJI, 4) * 100;
def CurrDJ = +close("$DJI", period = AggregationPeriod.DAY);
def ChangeDJ = CurrDJ - CurrDJ[1];

addLabel(yes, (Concat("DJI: ", Round (CurrDJ, 1))) + " Chg: " + Round(ChangeDJ) + " (" + djiPer + "%" + ")  ", if ChangeDJ > 0 then color.cyan else if ChangeDJ < 0 then color.LIGHT_GRAY else if djiPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

def COMP = Sector("COMP:GIDS");
def compPer = Round(COMP, 4) * 100;
def CurrC = +close("COMP:GIDS", period = AggregationPeriod.DAY);
def ChangeC = CurrC - CurrC[1];

addLabel(yes, (Concat("COMP: ", Round (CurrC, 1))) + " Chg: " + Round(ChangeC) + " (" + compPer + "%" + ")  ", if ChangeC > 0 then color.cyan else if ChangeC < 0 then color.LIGHT_GRAY else if compPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

def RUT = Sector("RUT");
def rutPer = Round(RUT, 4) * 100;
def CurrRU = +close("RUT", period = AggregationPeriod.DAY);
def ChangeRU = CurrRU - CurrRU[1];

addLabel(yes, (Concat("RUT: ", Round (CurrRU, 1))) + " Chg: " + Round(ChangeRU) + " (" + rutPer + "%" + ")  ", if ChangeRU > 0 then color.cyan else if ChangeRU < 0 then color.LIGHT_GRAY else if rutPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

# End Study

not quite sure what you want to see....
your study has 11 symbols.
how do you want to see 11 histograms in 1 space ?

'plots a histogram for these markets that has a zero line'
all histograms have a zero line.

do you want all 11 histograms on top of each other, some covering up others, starting from the same 0 line ? probably won't see much except the bars from the biggest one.

do you want 11 separate histograms , stacked vertically? so they don't overlap?
they would be pretty short, wouldn't see much detail.

do you want to pick 1 of them and show just 1 histogram ?
 

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

Hi All,

I have made slight changes to add markets of interest for quick over view. Now that we have the SPX, NDX, DJI, COMP and RUT. Can someone create a lower single indicator that plots a histogram for these markets that has a zero line? Plot bullish in color green if is above zero or red when bearish when it's below zero. This zero line should also change colors based on bullish or bearish sentiment.

Code:
# S&P 500 Sector Performance (Percentage)
# Paris
# 4.12.2018
# After reviewing chubbyboy's S&P sector study, I thought it might
# be a good idea to display labels of relative S&P sector performance
# in percentages. At one glance this will enable us to determine
# which sectors are happening and which are not. Decided to use a
# script() to retrieve the data. Also, I changed the formula slightly.
# The percentage displayed is the current price as a percentage over
# yesterday's closing rather than the open today as was used in chubbyboy's
# study.
#====== Further Modified by Killing Hours ======#
# 5/4/2020 #
# Added Color Mapping #
# to distinguish more suddle movements #
#===============================================#
#Modified slightly by Headhunter20.


######################################################################################
script Sector {
input symb = "SPX";
def c = close(symbol = symb, period = AggregationPeriod.day);
def PctChg = (c / c[1]) - 1;
plot pct = PctChg;
}

#Define the color map. Change as you see fit
DefineGlobalColor("VeryGood", CreateColor(4, 216, 22));
DefineGlobalColor("Good", CreateColor(46, 216, 4));
DefineGlobalColor("ModGood", CreateColor(121, 216, 4));
DefineGlobalColor("SlightlyGood", CreateColor(167, 216, 4));
DefineGlobalColor("SluggishGood", CreateColor(210,252,126));
DefineGlobalColor("Neutral", CreateColor(252, 231, 126));
DefineGlobalColor("SluggishBad", CreateColor(252,168,126));
DefineGlobalColor("SlightlyBad", CreateColor(216, 163, 4));
DefineGlobalColor("ModBad", CreateColor(216, 117, 4));
DefineGlobalColor("Bad", CreateColor(216, 43, 4));
DefineGlobalColor("VeryBad", CreateColor(216, 4, 4));

# SPX Overall
def SPX = Sector("SPX");
def spxPer = round(SPX,4) * 100;
def CurrSP = +close("SPX", period = AggregationPeriod.DAY);
def ChangeSP = CurrSP - CurrSP[1];

addLabel(1, "S&P500: "+ CurrSP + " Chg: " + ChangeSP + "  (" + spxPer + "%" + ")   ", if ChangeSP > 0 then color.cyan else if ChangeSP < 0 then color.gray else if spxPer > 0 then COLOR.CYAN else color.gray);

# Energy Sector
def Energy = Sector("$SP500#10");
def engPer = round(Energy,4) * 100;
AddLabel(
1,
"Energy: "+engPer+"% XLE #10",
if engPer > 1.50 then GlobalColor("VeryGood") else
if engPer > 1 && engPer <= 1.50 then GlobalColor("Good") else
if engPer > .5 && engPer <= 1 then GlobalColor("ModGood") else
if engPer > .25 && engPer <= .5 then GlobalColor("SlightlyGood") else
if engPer > 0 && engPer <= .25 then GlobalColor("SluggishGood") else
if engPer == 0 then GlobalColor("Neutral") else
if engPer < 0 && engPer >= -.25 then GlobalColor("SluggishBad") else
if engPer < -.25 && engPer >= -.5 then GlobalColor("SlightlyBad") else
if engPer < -.5 && engPer >= -1 then GlobalColor("ModBad") else
if engPer < -1 && engPer >= -1.50 then GlobalColor("Bad") else
if engPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Consumer Discretionary Spending Sector
def ConDisr = Sector("$SP500#25");
def conDPer = round(ConDisr,4);
AddLabel(
1,
"Con. Discretionary: "+conDPer+"% XLY #25",
if conDPer > 1.50 then GlobalColor("VeryGood") else
if conDPer > 1 && conDPer <= 1.50 then GlobalColor("Good") else
if conDPer > .5 && conDPer <= 1 then GlobalColor("ModGood") else
if conDPer > .25 && conDPer <= .5 then GlobalColor("SlightlyGood") else
if conDPer > 0 && conDPer <= .25 then GlobalColor("SluggishGood") else
if conDPer == 0 then GlobalColor("Neutral") else
if conDPer < 0 && conDPer >= -.25 then GlobalColor("SluggishBad") else
if conDPer < -.25 && conDPer >= -.5 then GlobalColor("SlightlyBad") else
if conDPer < -.5 && conDPer >= -1 then GlobalColor("ModBad") else
if conDPer < -1 && conDPer >= -1.50 then GlobalColor("Bad") else
if conDPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Financial Sector
def Finance = Sector("$SP500#40");
def finPer = round(Finance,4) * 100;
AddLabel(
1,
"Financials: "+finPer+"% XLF #40",
if finPer > 1.50 then GlobalColor("VeryGood") else
if finPer > 1 && finPer <= 1.50 then GlobalColor("Good") else
if finPer > .5 && finPer <= 1 then GlobalColor("ModGood") else
if finPer > .25 && finPer <= .5 then GlobalColor("SlightlyGood") else
if finPer > 0 && finPer <= .25 then GlobalColor("SluggishGood") else
if finPer == 0 then GlobalColor("Neutral") else
if finPer < 0 && finPer >= -.25 then GlobalColor("SluggishBad") else
if finPer < -.25 && finPer >= -.5 then GlobalColor("SlightlyBad") else
if finPer < -.5 && finPer >= -1 then GlobalColor("ModBad") else
if finPer < -1 && finPer >= -1.50 then GlobalColor("Bad") else
if finPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Utilities Sector
def Utilities = Sector("$SP500#55");
def utiPer = round(Utilities,4) * 100;
AddLabel(
1,
"Utilities: "+utiPer+"% XLU #55",
if utiPer > 1.50 then GlobalColor("VeryGood") else
if utiPer > 1 && utiPer <= 1.50 then GlobalColor("Good") else
if utiPer > .5 && utiPer <= 1 then GlobalColor("ModGood") else
if utiPer > .25 && utiPer <= .5 then GlobalColor("SlightlyGood") else
if utiPer > 0 && utiPer <= .25 then GlobalColor("SluggishGood") else
if utiPer == 0 then GlobalColor("Neutral") else
if utiPer < 0 && utiPer >= -.25 then GlobalColor("SluggishBad") else
if utiPer < -.25 && utiPer >= -.5 then GlobalColor("SlightlyBad") else
if utiPer < -.5 && utiPer >= -1 then GlobalColor("ModBad") else
if utiPer < -1 && utiPer >= -1.50 then GlobalColor("Bad") else
if utiPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Materials Sector
def Materials = Sector("$SP500#15");
def matPer = round(Materials,4) * 100;
AddLabel(
1,
"Materials: "+matPer+"% XLB #15",
if matPer > 1.50 then GlobalColor("VeryGood") else
if matPer > 1 && matPer <= 1.50 then GlobalColor("Good") else
if matPer > .5 && matPer <= 1 then GlobalColor("ModGood") else
if matPer > .25 && matPer <= .5 then GlobalColor("SlightlyGood") else
if matPer > 0 && matPer <= .25 then GlobalColor("SluggishGood") else
if matPer == 0 then GlobalColor("Neutral") else
if matPer < 0 && matPer >= -.25 then GlobalColor("SluggishBad") else
if matPer < -.25 && matPer >= -.5 then GlobalColor("SlightlyBad") else
if matPer < -.5 && matPer >= -1 then GlobalColor("ModBad") else
if matPer < -1 && matPer >= -1.50 then GlobalColor("Bad") else
if matPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Consumer Staples Sector
def ConStaple = Sector("$SP500#30");
def conSPer = round(ConStaple,4) * 100;
AddLabel(
1,
"Consumer Staples: "+conSPer+"% XLP #30",
if conSPer > 1.50 then GlobalColor("VeryGood") else
if conSPer > 1 && conSPer <= 1.50 then GlobalColor("Good") else
if conSPer > .5 && conSPer <= 1 then GlobalColor("ModGood") else
if conSPer > .25 && conSPer <= .5 then GlobalColor("SlightlyGood") else
if conSPer > 0 && conSPer <= .25 then GlobalColor("SluggishGood") else
if conSPer == 0 then GlobalColor("Neutral") else
if conSPer < 0 && conSPer >= -.25 then GlobalColor("SluggishBad") else
if conSPer < -.25 && conSPer >= -.5 then GlobalColor("SlightlyBad") else
if conSPer < -.5 && conSPer >= -1 then GlobalColor("ModBad") else
if conSPer < -1 && conSPer >= -1.50 then GlobalColor("Bad") else
if conSPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Information Technology Sector
def InfoTech = Sector("$SP500#45");
def infPer = round(InfoTech,4) * 100;
AddLabel(
1,
"Info Tech: " +infPer+"% XLK #45",
if infPer > 1.50 then GlobalColor("VeryGood") else
if infPer > 1 && infPer <= 1.50 then GlobalColor("Good") else
if infPer > .5 && infPer <= 1 then GlobalColor("ModGood") else
if infPer > .25 && infPer <= .5 then GlobalColor("SlightlyGood") else
if infPer > 0 && infPer <= .25 then GlobalColor("SluggishGood") else
if infPer == 0 then GlobalColor("Neutral") else
if infPer < 0 && infPer >= -.25 then GlobalColor("SluggishBad") else
if infPer < -.25 && infPer >= -.5 then GlobalColor("SlightlyBad") else
if infPer < -.5 && infPer >= -1 then GlobalColor("ModBad") else
if infPer < -1 && infPer >= -1.50 then GlobalColor("Bad") else
if infPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Real Estate Sector
def RealEste = Sector("$SP500#60");
def reaPer = round(RealEste,4) * 100;
AddLabel(
1,
"Real Estate: " +reaPer+"% XLRE #60",
if reaPer > 1.50 then GlobalColor("VeryGood") else
if reaPer > 1 && reaPer <= 1.50 then GlobalColor("Good") else
if reaPer > .5 && reaPer <= 1 then GlobalColor("ModGood") else
if reaPer > .25 && reaPer <= .5 then GlobalColor("SlightlyGood") else
if reaPer > 0 && reaPer <= .25 then GlobalColor("SluggishGood") else
if reaPer == 0 then GlobalColor("Neutral") else
if reaPer < 0 && reaPer >= -.25 then GlobalColor("SluggishBad") else
if reaPer < -.25 && reaPer >= -.5 then GlobalColor("SlightlyBad") else
if reaPer < -.5 && reaPer >= -1 then GlobalColor("ModBad") else
if reaPer < -1 && reaPer >= -1.50 then GlobalColor("Bad") else
if reaPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);


# Industrial Sector
def Industrl = Sector("$SP500#20");
def indPer = round(Industrl,4) * 100;
AddLabel(
1,
"Industrials: " +indPer+"% XLI #20",
if indPer > 1.50 then GlobalColor("VeryGood") else
if indPer > 1 && indPer <= 1.50 then GlobalColor("Good") else
if indPer > .5 && indPer <= 1 then GlobalColor("ModGood") else
if indPer > .25 && indPer <= .5 then GlobalColor("SlightlyGood") else
if indPer > 0 && indPer <= .25 then GlobalColor("SluggishGood") else
if indPer == 0 then GlobalColor("Neutral") else
if indPer < 0 && indPer >= -.25 then GlobalColor("SluggishBad") else
if indPer < -.25 && indPer >= -.5 then GlobalColor("SlightlyBad") else
if indPer < -.5 && indPer >= -1 then GlobalColor("ModBad") else
if indPer < -1 && indPer >= -1.50 then GlobalColor("Bad") else
if indPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Healthcare Sector
def Health = Sector("$SP500#35");
def heaPer = round(Health,4) * 100;
AddLabel(
1,
"Health Care: " +heaPer+"% XLV #35",
if heaPer > 1.50 then GlobalColor("VeryGood") else
if heaPer > 1 && heaPer <= 1.50 then GlobalColor("Good") else
if heaPer > .5 && heaPer <= 1 then GlobalColor("ModGood") else
if heaPer > .25 && heaPer <= .5 then GlobalColor("SlightlyGood") else
if heaPer > 0 && heaPer <= .25 then GlobalColor("SluggishGood") else
if heaPer == 0 then GlobalColor("Neutral") else
if heaPer < 0 && heaPer >= -.25 then GlobalColor("SluggishBad") else
if heaPer < -.25 && heaPer >= -.5 then GlobalColor("SlightlyBad") else
if heaPer < -.5 && heaPer >= -1 then GlobalColor("ModBad") else
if heaPer < -1 && heaPer >= -1.50 then GlobalColor("Bad") else
if heaPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Telecommunication Sector
def Telecoms = Sector("$SP500#50");
def telPef = round(Telecoms,4) * 100;
AddLabel(
1,
"Telecoms: " +telPef+"% XLC #50",
if telPef > 1.50 then GlobalColor("VeryGood") else
if telPef > 1 && telPef <= 1.50 then GlobalColor("Good") else
if telPef > .5 && telPef <= 1 then GlobalColor("ModGood") else
if telPef > .25 && telPef <= .5 then GlobalColor("SlightlyGood") else
if telPef > 0 && telPef <= .25 then GlobalColor("SluggishGood") else
if telPef == 0 then GlobalColor("Neutral") else
if telPef < 0 && telPef >= -.25 then GlobalColor("SluggishBad") else
if telPef < -.25 && telPef >= -.5 then GlobalColor("SlightlyBad") else
if telPef < -.5 && telPef >= -1 then GlobalColor("ModBad") else
if telPef < -1 && telPef >= -1.50 then GlobalColor("Bad") else
if telPef < -1.50 then GlobalColor("VeryBad") else
Color.black
);

def NDX = Sector("NDX");
def ndxPer = Round(NDX, 4) * 100;
def CurrND = +close("NDX", period = AggregationPeriod.DAY);
def ChangeNDX = CurrND - CurrND[1];

addLabel(1, "NASD: "+CurrND +" Chg :" + ChangeNDX + "  (" + ndxPer + "%" + ")  ", if ChangeNDX > 0 then color.cyan else if ChangeNDX < 0 then color.light_gray else if ndxPer > 0 then COLOR.CYAN else color.light_gray);

def DJI = Sector("$DJI");
def djiPer = Round(DJI, 4) * 100;
def CurrDJ = +close("$DJI", period = AggregationPeriod.DAY);
def ChangeDJ = CurrDJ - CurrDJ[1];

addLabel(yes, (Concat("DJI: ", Round (CurrDJ, 1))) + " Chg: " + Round(ChangeDJ) + " (" + djiPer + "%" + ")  ", if ChangeDJ > 0 then color.cyan else if ChangeDJ < 0 then color.LIGHT_GRAY else if djiPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

def COMP = Sector("COMP:GIDS");
def compPer = Round(COMP, 4) * 100;
def CurrC = +close("COMP:GIDS", period = AggregationPeriod.DAY);
def ChangeC = CurrC - CurrC[1];

addLabel(yes, (Concat("COMP: ", Round (CurrC, 1))) + " Chg: " + Round(ChangeC) + " (" + compPer + "%" + ")  ", if ChangeC > 0 then color.cyan else if ChangeC < 0 then color.LIGHT_GRAY else if compPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

def RUT = Sector("RUT");
def rutPer = Round(RUT, 4) * 100;
def CurrRU = +close("RUT", period = AggregationPeriod.DAY);
def ChangeRU = CurrRU - CurrRU[1];

addLabel(yes, (Concat("RUT: ", Round (CurrRU, 1))) + " Chg: " + Round(ChangeRU) + " (" + rutPer + "%" + ")  ", if ChangeRU > 0 then color.cyan else if ChangeRU < 0 then color.LIGHT_GRAY else if rutPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

# End Study


here is 1 interpretation of your request.


draw 11 histograms, of 11 symbols, all on top of each other.

i copied each symbol code, down below and used the % variable for histogrtam data
i had thoughts of reusing the label colors, so i kept copies of them... but i just used green and red.


Code:
# sector_histos_00

#https://usethinkscript.com/threads/advanced-sector-indicators.15603/
#Advanced Sector Indicators
#woulf1004  5/26

#I have made slight changes to add markets of interest for quick over view. Now that we have the SPX, NDX, DJI, COMP and RUT. Can someone create a lower single indicator that plots a histogram for these markets that has a zero line? Plot bullish in color green if is above zero or red when bearish when it's below zero. This zero line should also change colors based on bullish or bearish sentiment.


# S&P 500 Sector Performance (Percentage)
# Paris
# 4.12.2018
# After reviewing chubbyboy's S&P sector study, I thought it might
# be a good idea to display labels of relative S&P sector performance
# in percentages. At one glance this will enable us to determine
# which sectors are happening and which are not. Decided to use a
# script() to retrieve the data. Also, I changed the formula slightly.
# The percentage displayed is the current price as a percentage over
# yesterday's closing rather than the open today as was used in chubbyboy's
# study.
#====== Further Modified by Killing Hours ======#
# 5/4/2020 #
# Added Color Mapping #
# to distinguish more suddle movements #
#===============================================#
#Modified slightly by Headhunter20.


declare lower;


######################################################################################
script Sector {
input symb = "SPX";
def c = close(symbol = symb, period = AggregationPeriod.day);
def PctChg = (c / c[1]) - 1;
plot pct = PctChg;
}

#Define the color map. Change as you see fit
DefineGlobalColor("VeryGood", CreateColor(4, 216, 22));
DefineGlobalColor("Good", CreateColor(46, 216, 4));
DefineGlobalColor("ModGood", CreateColor(121, 216, 4));
DefineGlobalColor("SlightlyGood", CreateColor(167, 216, 4));
DefineGlobalColor("SluggishGood", CreateColor(210,252,126));
DefineGlobalColor("Neutral", CreateColor(252, 231, 126));
DefineGlobalColor("SluggishBad", CreateColor(252,168,126));
DefineGlobalColor("SlightlyBad", CreateColor(216, 163, 4));
DefineGlobalColor("ModBad", CreateColor(216, 117, 4));
DefineGlobalColor("Bad", CreateColor(216, 43, 4));
DefineGlobalColor("VeryBad", CreateColor(216, 4, 4));

# SPX Overall
def SPX = Sector("SPX");
def spxPer = round(SPX,4) * 100;
def CurrSP = +close("SPX", period = AggregationPeriod.DAY);
def ChangeSP = CurrSP - CurrSP[1];

addLabel(1, "S&P500: "+ CurrSP + " Chg: " + ChangeSP + "  (" + spxPer + "%" + ")   ", if ChangeSP > 0 then color.cyan else if ChangeSP < 0 then color.gray else if spxPer > 0 then COLOR.CYAN else color.gray);

# Energy Sector
def Energy = Sector("$SP500#10");
def engPer = round(Energy,4) * 100;
AddLabel(
1,
"Energy: "+engPer+"% XLE #10",
if engPer > 1.50 then GlobalColor("VeryGood") else
if engPer > 1 && engPer <= 1.50 then GlobalColor("Good") else
if engPer > .5 && engPer <= 1 then GlobalColor("ModGood") else
if engPer > .25 && engPer <= .5 then GlobalColor("SlightlyGood") else
if engPer > 0 && engPer <= .25 then GlobalColor("SluggishGood") else
if engPer == 0 then GlobalColor("Neutral") else
if engPer < 0 && engPer >= -.25 then GlobalColor("SluggishBad") else
if engPer < -.25 && engPer >= -.5 then GlobalColor("SlightlyBad") else
if engPer < -.5 && engPer >= -1 then GlobalColor("ModBad") else
if engPer < -1 && engPer >= -1.50 then GlobalColor("Bad") else
if engPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Consumer Discretionary Spending Sector
def ConDisr = Sector("$SP500#25");
def conDPer = round(ConDisr,4);
AddLabel(
1,
"Con. Discretionary: "+conDPer+"% XLY #25",
if conDPer > 1.50 then GlobalColor("VeryGood") else
if conDPer > 1 && conDPer <= 1.50 then GlobalColor("Good") else
if conDPer > .5 && conDPer <= 1 then GlobalColor("ModGood") else
if conDPer > .25 && conDPer <= .5 then GlobalColor("SlightlyGood") else
if conDPer > 0 && conDPer <= .25 then GlobalColor("SluggishGood") else
if conDPer == 0 then GlobalColor("Neutral") else
if conDPer < 0 && conDPer >= -.25 then GlobalColor("SluggishBad") else
if conDPer < -.25 && conDPer >= -.5 then GlobalColor("SlightlyBad") else
if conDPer < -.5 && conDPer >= -1 then GlobalColor("ModBad") else
if conDPer < -1 && conDPer >= -1.50 then GlobalColor("Bad") else
if conDPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Financial Sector
def Finance = Sector("$SP500#40");
def finPer = round(Finance,4) * 100;
AddLabel(
1,
"Financials: "+finPer+"% XLF #40",
if finPer > 1.50 then GlobalColor("VeryGood") else
if finPer > 1 && finPer <= 1.50 then GlobalColor("Good") else
if finPer > .5 && finPer <= 1 then GlobalColor("ModGood") else
if finPer > .25 && finPer <= .5 then GlobalColor("SlightlyGood") else
if finPer > 0 && finPer <= .25 then GlobalColor("SluggishGood") else
if finPer == 0 then GlobalColor("Neutral") else
if finPer < 0 && finPer >= -.25 then GlobalColor("SluggishBad") else
if finPer < -.25 && finPer >= -.5 then GlobalColor("SlightlyBad") else
if finPer < -.5 && finPer >= -1 then GlobalColor("ModBad") else
if finPer < -1 && finPer >= -1.50 then GlobalColor("Bad") else
if finPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Utilities Sector
def Utilities = Sector("$SP500#55");
def utiPer = round(Utilities,4) * 100;
AddLabel(
1,
"Utilities: "+utiPer+"% XLU #55",
if utiPer > 1.50 then GlobalColor("VeryGood") else
if utiPer > 1 && utiPer <= 1.50 then GlobalColor("Good") else
if utiPer > .5 && utiPer <= 1 then GlobalColor("ModGood") else
if utiPer > .25 && utiPer <= .5 then GlobalColor("SlightlyGood") else
if utiPer > 0 && utiPer <= .25 then GlobalColor("SluggishGood") else
if utiPer == 0 then GlobalColor("Neutral") else
if utiPer < 0 && utiPer >= -.25 then GlobalColor("SluggishBad") else
if utiPer < -.25 && utiPer >= -.5 then GlobalColor("SlightlyBad") else
if utiPer < -.5 && utiPer >= -1 then GlobalColor("ModBad") else
if utiPer < -1 && utiPer >= -1.50 then GlobalColor("Bad") else
if utiPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Materials Sector
def Materials = Sector("$SP500#15");
def matPer = round(Materials,4) * 100;
AddLabel(
1,
"Materials: "+matPer+"% XLB #15",
if matPer > 1.50 then GlobalColor("VeryGood") else
if matPer > 1 && matPer <= 1.50 then GlobalColor("Good") else
if matPer > .5 && matPer <= 1 then GlobalColor("ModGood") else
if matPer > .25 && matPer <= .5 then GlobalColor("SlightlyGood") else
if matPer > 0 && matPer <= .25 then GlobalColor("SluggishGood") else
if matPer == 0 then GlobalColor("Neutral") else
if matPer < 0 && matPer >= -.25 then GlobalColor("SluggishBad") else
if matPer < -.25 && matPer >= -.5 then GlobalColor("SlightlyBad") else
if matPer < -.5 && matPer >= -1 then GlobalColor("ModBad") else
if matPer < -1 && matPer >= -1.50 then GlobalColor("Bad") else
if matPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Consumer Staples Sector
def ConStaple = Sector("$SP500#30");
def conSPer = round(ConStaple,4) * 100;
AddLabel(
1,
"Consumer Staples: "+conSPer+"% XLP #30",
if conSPer > 1.50 then GlobalColor("VeryGood") else
if conSPer > 1 && conSPer <= 1.50 then GlobalColor("Good") else
if conSPer > .5 && conSPer <= 1 then GlobalColor("ModGood") else
if conSPer > .25 && conSPer <= .5 then GlobalColor("SlightlyGood") else
if conSPer > 0 && conSPer <= .25 then GlobalColor("SluggishGood") else
if conSPer == 0 then GlobalColor("Neutral") else
if conSPer < 0 && conSPer >= -.25 then GlobalColor("SluggishBad") else
if conSPer < -.25 && conSPer >= -.5 then GlobalColor("SlightlyBad") else
if conSPer < -.5 && conSPer >= -1 then GlobalColor("ModBad") else
if conSPer < -1 && conSPer >= -1.50 then GlobalColor("Bad") else
if conSPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Information Technology Sector
def InfoTech = Sector("$SP500#45");
def infPer = round(InfoTech,4) * 100;
AddLabel(
1,
"Info Tech: " +infPer+"% XLK #45",
if infPer > 1.50 then GlobalColor("VeryGood") else
if infPer > 1 && infPer <= 1.50 then GlobalColor("Good") else
if infPer > .5 && infPer <= 1 then GlobalColor("ModGood") else
if infPer > .25 && infPer <= .5 then GlobalColor("SlightlyGood") else
if infPer > 0 && infPer <= .25 then GlobalColor("SluggishGood") else
if infPer == 0 then GlobalColor("Neutral") else
if infPer < 0 && infPer >= -.25 then GlobalColor("SluggishBad") else
if infPer < -.25 && infPer >= -.5 then GlobalColor("SlightlyBad") else
if infPer < -.5 && infPer >= -1 then GlobalColor("ModBad") else
if infPer < -1 && infPer >= -1.50 then GlobalColor("Bad") else
if infPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Real Estate Sector
def RealEste = Sector("$SP500#60");
def reaPer = round(RealEste,4) * 100;
AddLabel(
1,
"Real Estate: " +reaPer+"% XLRE #60",
if reaPer > 1.50 then GlobalColor("VeryGood") else
if reaPer > 1 && reaPer <= 1.50 then GlobalColor("Good") else
if reaPer > .5 && reaPer <= 1 then GlobalColor("ModGood") else
if reaPer > .25 && reaPer <= .5 then GlobalColor("SlightlyGood") else
if reaPer > 0 && reaPer <= .25 then GlobalColor("SluggishGood") else
if reaPer == 0 then GlobalColor("Neutral") else
if reaPer < 0 && reaPer >= -.25 then GlobalColor("SluggishBad") else
if reaPer < -.25 && reaPer >= -.5 then GlobalColor("SlightlyBad") else
if reaPer < -.5 && reaPer >= -1 then GlobalColor("ModBad") else
if reaPer < -1 && reaPer >= -1.50 then GlobalColor("Bad") else
if reaPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);


# Industrial Sector
def Industrl = Sector("$SP500#20");
def indPer = round(Industrl,4) * 100;
AddLabel(
1,
"Industrials: " +indPer+"% XLI #20",
if indPer > 1.50 then GlobalColor("VeryGood") else
if indPer > 1 && indPer <= 1.50 then GlobalColor("Good") else
if indPer > .5 && indPer <= 1 then GlobalColor("ModGood") else
if indPer > .25 && indPer <= .5 then GlobalColor("SlightlyGood") else
if indPer > 0 && indPer <= .25 then GlobalColor("SluggishGood") else
if indPer == 0 then GlobalColor("Neutral") else
if indPer < 0 && indPer >= -.25 then GlobalColor("SluggishBad") else
if indPer < -.25 && indPer >= -.5 then GlobalColor("SlightlyBad") else
if indPer < -.5 && indPer >= -1 then GlobalColor("ModBad") else
if indPer < -1 && indPer >= -1.50 then GlobalColor("Bad") else
if indPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Healthcare Sector
def Health = Sector("$SP500#35");
def heaPer = round(Health,4) * 100;
AddLabel(
1,
"Health Care: " +heaPer+"% XLV #35",
if heaPer > 1.50 then GlobalColor("VeryGood") else
if heaPer > 1 && heaPer <= 1.50 then GlobalColor("Good") else
if heaPer > .5 && heaPer <= 1 then GlobalColor("ModGood") else
if heaPer > .25 && heaPer <= .5 then GlobalColor("SlightlyGood") else
if heaPer > 0 && heaPer <= .25 then GlobalColor("SluggishGood") else
if heaPer == 0 then GlobalColor("Neutral") else
if heaPer < 0 && heaPer >= -.25 then GlobalColor("SluggishBad") else
if heaPer < -.25 && heaPer >= -.5 then GlobalColor("SlightlyBad") else
if heaPer < -.5 && heaPer >= -1 then GlobalColor("ModBad") else
if heaPer < -1 && heaPer >= -1.50 then GlobalColor("Bad") else
if heaPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Telecommunication Sector
def Telecoms = Sector("$SP500#50");
def telPef = round(Telecoms,4) * 100;
AddLabel(
1,
"Telecoms: " +telPef+"% XLC #50",
if telPef > 1.50 then GlobalColor("VeryGood") else
if telPef > 1 && telPef <= 1.50 then GlobalColor("Good") else
if telPef > .5 && telPef <= 1 then GlobalColor("ModGood") else
if telPef > .25 && telPef <= .5 then GlobalColor("SlightlyGood") else
if telPef > 0 && telPef <= .25 then GlobalColor("SluggishGood") else
if telPef == 0 then GlobalColor("Neutral") else
if telPef < 0 && telPef >= -.25 then GlobalColor("SluggishBad") else
if telPef < -.25 && telPef >= -.5 then GlobalColor("SlightlyBad") else
if telPef < -.5 && telPef >= -1 then GlobalColor("ModBad") else
if telPef < -1 && telPef >= -1.50 then GlobalColor("Bad") else
if telPef < -1.50 then GlobalColor("VeryBad") else
Color.black
);

def NDX = Sector("NDX");
def ndxPer = Round(NDX, 4) * 100;
def CurrND = +close("NDX", period = AggregationPeriod.DAY);
def ChangeNDX = CurrND - CurrND[1];

addLabel(1, "NASD: "+CurrND +" Chg :" + ChangeNDX + "  (" + ndxPer + "%" + ")  ", if ChangeNDX > 0 then color.cyan else if ChangeNDX < 0 then color.light_gray else if ndxPer > 0 then COLOR.CYAN else color.light_gray);

def DJI = Sector("$DJI");
def djiPer = Round(DJI, 4) * 100;
def CurrDJ = +close("$DJI", period = AggregationPeriod.DAY);
def ChangeDJ = CurrDJ - CurrDJ[1];

addLabel(yes, (Concat("DJI: ", Round (CurrDJ, 1))) + " Chg: " + Round(ChangeDJ) + " (" + djiPer + "%" + ")  ", if ChangeDJ > 0 then color.cyan else if ChangeDJ < 0 then color.LIGHT_GRAY else if djiPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

def COMP = Sector("COMP:GIDS");
def compPer = Round(COMP, 4) * 100;
def CurrC = +close("COMP:GIDS", period = AggregationPeriod.DAY);
def ChangeC = CurrC - CurrC[1];

addLabel(yes, (Concat("COMP: ", Round (CurrC, 1))) + " Chg: " + Round(ChangeC) + " (" + compPer + "%" + ")  ", if ChangeC > 0 then color.cyan else if ChangeC < 0 then color.LIGHT_GRAY else if compPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

def RUT = Sector("RUT");
def rutPer = Round(RUT, 4) * 100;
def CurrRU = +close("RUT", period = AggregationPeriod.DAY);
def ChangeRU = CurrRU - CurrRU[1];

addLabel(yes, (Concat("RUT: ", Round (CurrRU, 1))) + " Chg: " + Round(ChangeRU) + " (" + rutPer + "%" + ")  ", if ChangeRU > 0 then color.cyan else if ChangeRU < 0 then color.LIGHT_GRAY else if rutPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);


#---------------------------------




# Energy Sector
# Energy
# engPer

AddLabel(0,
"Energy: "+engPer+"% XLE #10",
if engPer > 1.50 then GlobalColor("VeryGood") else
if engPer > 1 && engPer <= 1.50 then GlobalColor("Good") else
if engPer > .5 && engPer <= 1 then GlobalColor("ModGood") else
if engPer > .25 && engPer <= .5 then GlobalColor("SlightlyGood") else
if engPer > 0 && engPer <= .25 then GlobalColor("SluggishGood") else
if engPer == 0 then GlobalColor("Neutral") else
if engPer < 0 && engPer >= -.25 then GlobalColor("SluggishBad") else
if engPer < -.25 && engPer >= -.5 then GlobalColor("SlightlyBad") else
if engPer < -.5 && engPer >= -1 then GlobalColor("ModBad") else
if engPer < -1 && engPer >= -1.50 then GlobalColor("Bad") else
if engPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Consumer Discretionary Spending Sector
# ConDisr 
# conDPer 

AddLabel(0,
"Con. Discretionary: "+conDPer+"% XLY #25",
if conDPer > 1.50 then GlobalColor("VeryGood") else
if conDPer > 1 && conDPer <= 1.50 then GlobalColor("Good") else
if conDPer > .5 && conDPer <= 1 then GlobalColor("ModGood") else
if conDPer > .25 && conDPer <= .5 then GlobalColor("SlightlyGood") else
if conDPer > 0 && conDPer <= .25 then GlobalColor("SluggishGood") else
if conDPer == 0 then GlobalColor("Neutral") else
if conDPer < 0 && conDPer >= -.25 then GlobalColor("SluggishBad") else
if conDPer < -.25 && conDPer >= -.5 then GlobalColor("SlightlyBad") else
if conDPer < -.5 && conDPer >= -1 then GlobalColor("ModBad") else
if conDPer < -1 && conDPer >= -1.50 then GlobalColor("Bad") else
if conDPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Financial Sector
# Finance
# finPer

AddLabel(0,
"Financials: "+finPer+"% XLF #40",
if finPer > 1.50 then GlobalColor("VeryGood") else
if finPer > 1 && finPer <= 1.50 then GlobalColor("Good") else
if finPer > .5 && finPer <= 1 then GlobalColor("ModGood") else
if finPer > .25 && finPer <= .5 then GlobalColor("SlightlyGood") else
if finPer > 0 && finPer <= .25 then GlobalColor("SluggishGood") else
if finPer == 0 then GlobalColor("Neutral") else
if finPer < 0 && finPer >= -.25 then GlobalColor("SluggishBad") else
if finPer < -.25 && finPer >= -.5 then GlobalColor("SlightlyBad") else
if finPer < -.5 && finPer >= -1 then GlobalColor("ModBad") else
if finPer < -1 && finPer >= -1.50 then GlobalColor("Bad") else
if finPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Utilities Sector
# Utilities
# utiPer

AddLabel(0,
"Utilities: "+utiPer+"% XLU #55",
if utiPer > 1.50 then GlobalColor("VeryGood") else
if utiPer > 1 && utiPer <= 1.50 then GlobalColor("Good") else
if utiPer > .5 && utiPer <= 1 then GlobalColor("ModGood") else
if utiPer > .25 && utiPer <= .5 then GlobalColor("SlightlyGood") else
if utiPer > 0 && utiPer <= .25 then GlobalColor("SluggishGood") else
if utiPer == 0 then GlobalColor("Neutral") else
if utiPer < 0 && utiPer >= -.25 then GlobalColor("SluggishBad") else
if utiPer < -.25 && utiPer >= -.5 then GlobalColor("SlightlyBad") else
if utiPer < -.5 && utiPer >= -1 then GlobalColor("ModBad") else
if utiPer < -1 && utiPer >= -1.50 then GlobalColor("Bad") else
if utiPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Materials Sector
# Materials
# matPer

AddLabel(0,
"Materials: "+matPer+"% XLB #15",
if matPer > 1.50 then GlobalColor("VeryGood") else
if matPer > 1 && matPer <= 1.50 then GlobalColor("Good") else
if matPer > .5 && matPer <= 1 then GlobalColor("ModGood") else
if matPer > .25 && matPer <= .5 then GlobalColor("SlightlyGood") else
if matPer > 0 && matPer <= .25 then GlobalColor("SluggishGood") else
if matPer == 0 then GlobalColor("Neutral") else
if matPer < 0 && matPer >= -.25 then GlobalColor("SluggishBad") else
if matPer < -.25 && matPer >= -.5 then GlobalColor("SlightlyBad") else
if matPer < -.5 && matPer >= -1 then GlobalColor("ModBad") else
if matPer < -1 && matPer >= -1.50 then GlobalColor("Bad") else
if matPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Consumer Staples Sector
# ConStaple
# conSPer

AddLabel(0,
"Consumer Staples: "+conSPer+"% XLP #30",
if conSPer > 1.50 then GlobalColor("VeryGood") else
if conSPer > 1 && conSPer <= 1.50 then GlobalColor("Good") else
if conSPer > .5 && conSPer <= 1 then GlobalColor("ModGood") else
if conSPer > .25 && conSPer <= .5 then GlobalColor("SlightlyGood") else
if conSPer > 0 && conSPer <= .25 then GlobalColor("SluggishGood") else
if conSPer == 0 then GlobalColor("Neutral") else
if conSPer < 0 && conSPer >= -.25 then GlobalColor("SluggishBad") else
if conSPer < -.25 && conSPer >= -.5 then GlobalColor("SlightlyBad") else
if conSPer < -.5 && conSPer >= -1 then GlobalColor("ModBad") else
if conSPer < -1 && conSPer >= -1.50 then GlobalColor("Bad") else
if conSPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Information Technology Sector
# InfoTech
# infPer

AddLabel(0,
"Info Tech: " +infPer+"% XLK #45",
if infPer > 1.50 then GlobalColor("VeryGood") else
if infPer > 1 && infPer <= 1.50 then GlobalColor("Good") else
if infPer > .5 && infPer <= 1 then GlobalColor("ModGood") else
if infPer > .25 && infPer <= .5 then GlobalColor("SlightlyGood") else
if infPer > 0 && infPer <= .25 then GlobalColor("SluggishGood") else
if infPer == 0 then GlobalColor("Neutral") else
if infPer < 0 && infPer >= -.25 then GlobalColor("SluggishBad") else
if infPer < -.25 && infPer >= -.5 then GlobalColor("SlightlyBad") else
if infPer < -.5 && infPer >= -1 then GlobalColor("ModBad") else
if infPer < -1 && infPer >= -1.50 then GlobalColor("Bad") else
if infPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Real Estate Sector
# RealEste
# reaPer

AddLabel(0,
"Real Estate: " +reaPer+"% XLRE #60",
if reaPer > 1.50 then GlobalColor("VeryGood") else
if reaPer > 1 && reaPer <= 1.50 then GlobalColor("Good") else
if reaPer > .5 && reaPer <= 1 then GlobalColor("ModGood") else
if reaPer > .25 && reaPer <= .5 then GlobalColor("SlightlyGood") else
if reaPer > 0 && reaPer <= .25 then GlobalColor("SluggishGood") else
if reaPer == 0 then GlobalColor("Neutral") else
if reaPer < 0 && reaPer >= -.25 then GlobalColor("SluggishBad") else
if reaPer < -.25 && reaPer >= -.5 then GlobalColor("SlightlyBad") else
if reaPer < -.5 && reaPer >= -1 then GlobalColor("ModBad") else
if reaPer < -1 && reaPer >= -1.50 then GlobalColor("Bad") else
if reaPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);


# Industrial Sector
# Industrl
# indPer

AddLabel(0,
"Industrials: " +indPer+"% XLI #20",
if indPer > 1.50 then GlobalColor("VeryGood") else
if indPer > 1 && indPer <= 1.50 then GlobalColor("Good") else
if indPer > .5 && indPer <= 1 then GlobalColor("ModGood") else
if indPer > .25 && indPer <= .5 then GlobalColor("SlightlyGood") else
if indPer > 0 && indPer <= .25 then GlobalColor("SluggishGood") else
if indPer == 0 then GlobalColor("Neutral") else
if indPer < 0 && indPer >= -.25 then GlobalColor("SluggishBad") else
if indPer < -.25 && indPer >= -.5 then GlobalColor("SlightlyBad") else
if indPer < -.5 && indPer >= -1 then GlobalColor("ModBad") else
if indPer < -1 && indPer >= -1.50 then GlobalColor("Bad") else
if indPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Healthcare Sector
# Health
# heaPer

AddLabel(0,
"Health Care: " +heaPer+"% XLV #35",
if heaPer > 1.50 then GlobalColor("VeryGood") else
if heaPer > 1 && heaPer <= 1.50 then GlobalColor("Good") else
if heaPer > .5 && heaPer <= 1 then GlobalColor("ModGood") else
if heaPer > .25 && heaPer <= .5 then GlobalColor("SlightlyGood") else
if heaPer > 0 && heaPer <= .25 then GlobalColor("SluggishGood") else
if heaPer == 0 then GlobalColor("Neutral") else
if heaPer < 0 && heaPer >= -.25 then GlobalColor("SluggishBad") else
if heaPer < -.25 && heaPer >= -.5 then GlobalColor("SlightlyBad") else
if heaPer < -.5 && heaPer >= -1 then GlobalColor("ModBad") else
if heaPer < -1 && heaPer >= -1.50 then GlobalColor("Bad") else
if heaPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Telecommunication Sector
# Telecoms
# telPef

AddLabel(0,
"Telecoms: " +telPef+"% XLC #50",
if telPef > 1.50 then GlobalColor("VeryGood") else
if telPef > 1 && telPef <= 1.50 then GlobalColor("Good") else
if telPef > .5 && telPef <= 1 then GlobalColor("ModGood") else
if telPef > .25 && telPef <= .5 then GlobalColor("SlightlyGood") else
if telPef > 0 && telPef <= .25 then GlobalColor("SluggishGood") else
if telPef == 0 then GlobalColor("Neutral") else
if telPef < 0 && telPef >= -.25 then GlobalColor("SluggishBad") else
if telPef < -.25 && telPef >= -.5 then GlobalColor("SlightlyBad") else
if telPef < -.5 && telPef >= -1 then GlobalColor("ModBad") else
if telPef < -1 && telPef >= -1.50 then GlobalColor("Bad") else
if telPef < -1.50 then GlobalColor("VeryBad") else
Color.black
);


#def NDX = Sector("NDX");
#def ndxPer = Round(NDX, 4) * 100;
#def CurrND = +close("NDX", period = AggregationPeriod.DAY);
#def ChangeNDX = CurrND - CurrND[1];

#addLabel(1, "NASD: "+CurrND +" Chg :" + ChangeNDX + "  (" + ndxPer + "%" + ")  ", if ChangeNDX > 0 then color.cyan else if ChangeNDX < 0 then color.light_gray else if ndxPer > 0 then COLOR.CYAN else color.light_gray);

#def DJI = Sector("$DJI");
#def djiPer = Round(DJI, 4) * 100;
#def CurrDJ = +close("$DJI", period = AggregationPeriod.DAY);
#def ChangeDJ = CurrDJ - CurrDJ[1];

#addLabel(yes, (Concat("DJI: ", Round (CurrDJ, 1))) + " Chg: " + Round(ChangeDJ) + " (" + djiPer + "%" + ")  ", if ChangeDJ > 0 then color.cyan else if ChangeDJ < 0 then color.LIGHT_GRAY else if djiPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

#def COMP = Sector("COMP:GIDS");
#def compPer = Round(COMP, 4) * 100;
#def CurrC = +close("COMP:GIDS", period = AggregationPeriod.DAY);
#def ChangeC = CurrC - CurrC[1];

#addLabel(yes, (Concat("COMP: ", Round (CurrC, 1))) + " Chg: " + Round(ChangeC) + " (" + compPer + "%" + ")  ", if ChangeC > 0 then color.cyan else if ChangeC < 0 then color.LIGHT_GRAY else if compPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

#def RUT = Sector("RUT");
#def rutPer = Round(RUT, 4) * 100;
#def CurrRU = +close("RUT", period = AggregationPeriod.DAY);
#def ChangeRU = CurrRU - CurrRU[1];

#addLabel(yes, (Concat("RUT: ", Round (CurrRU, 1))) + " Chg: " + Round(ChangeRU) + " (" + rutPer + "%" + ")  ", if ChangeRU > 0 then color.cyan else if ChangeRU < 0 then color.LIGHT_GRAY else if rutPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);


#--------------------


# Energy Sector
# Energy
# engPer
plot s1 = engPer;
s1.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
s1.AssignValueColor(if engPer > 0 then color.green else color.red);


# Consumer Discretionary Spending Sector
# ConDisr 
# conDPer 
plot s2 = conDPer;
s2.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
s2.AssignValueColor(if conDPer > 0 then color.green else color.red);


# Financial Sector
# Finance
# finPer
plot s3 = finPer;
s3.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
s3.AssignValueColor(if finPer > 0 then color.green else color.red);


# Utilities Sector
# Utilities
# utiPer
plot s4 = utiPer;
s4.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
s4.AssignValueColor(if utiPer > 0 then color.green else color.red);


# Materials Sector
# Materials
# matPer
plot s5 = matPer;
s5.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
s5.AssignValueColor(if matPer > 0 then color.green else color.red);


# Consumer Staples Sector
# ConStaple
# conSPer
plot s6 = conSPer;
s6.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
s6.AssignValueColor(if conSPer > 0 then color.green else color.red);


# Information Technology Sector
# InfoTech
# infPer
plot s7 = infPer;
s7.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
s7.AssignValueColor(if infPer> 0 then color.green else color.red);


# Real Estate Sector
# RealEste
# reaPer
plot s8 = reaPer;
s8.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
s8.AssignValueColor(if reaPer > 0 then color.green else color.red);


# Industrial Sector
# Industrl
# indPer
plot s9 = indPer;
s9.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
s9.AssignValueColor(if indPer > 0 then color.green else color.red);


# Healthcare Sector
# Health
# heaPer
plot s10 = heaPer;
s10.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
s10.AssignValueColor(if heaPer > 0 then color.green else color.red);


# Telecommunication Sector
# Telecoms
# telPef
plot s11 = telPef;
s11.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
s11.AssignValueColor(if telPef > 0 then color.green else color.red);
#
# End Study
#

11 sector histograms , on top of each other
aX3eUXC.jpg
 
Hi Halcyonguy,
First of all, thanks for the follow up. I really appreciate this.
Please refer to the below for your reference.

The goal is to create two lower indicators and inputs for switches:

* The first lower indicator should plot the 11 sectors separated in two, gaging to plot the following in the below.
1. The weighted sectors.
2. The unweighted sectors.

* The second lower indicator should plot only the major markets which are SPX, NDX, DJI, COMP and RUT (so, one zero line following up with the SPX plot defined as the 11 sectors in one as a whole, the NDX plot, the DJI plot, the COMP plot and the RUT plot).

The reason I requested to be a histogram is because in settings these can be changed to lines and combined with histograms to see divergences and use them as needed.

The zero line for any of these indicators should change colors based on: if all markets or sectors are above zero then color green or if all markets are below the zero line then color red else color gray.

In addition, a separate input to turn on or off the upper labels which should be separated as:
- first input for the 11 sectors only.
- second input for the markets (SPX, NDX, DJI, COMP and RUT).

And finally two additional inputs:
- first input is for the first lower indicator
- second input is for the second lower indicator.
 
Hi Halcyonguy,
First of all, thanks for the follow up. I really appreciate this.
Please refer to the below for your reference.

The goal is to create two lower indicators and inputs for switches:

* The first lower indicator should plot the 11 sectors separated in two, gaging to plot the following in the below.
1. The weighted sectors.
2. The unweighted sectors.

* The second lower indicator should plot only the major markets which are SPX, NDX, DJI, COMP and RUT (so, one zero line following up with the SPX plot defined as the 11 sectors in one as a whole, the NDX plot, the DJI plot, the COMP plot and the RUT plot).

The reason I requested to be a histogram is because in settings these can be changed to lines and combined with histograms to see divergences and use them as needed.

The zero line for any of these indicators should change colors based on: if all markets or sectors are above zero then color green or if all markets are below the zero line then color red else color gray.

In addition, a separate input to turn on or off the upper labels which should be separated as:
- first input for the 11 sectors only.
- second input for the markets (SPX, NDX, DJI, COMP and RUT).

And finally two additional inputs:
- first input is for the first lower indicator
- second input is for the second lower indicator.


i'm sorry, i still don't understand what you are asking for.
you are using a lot of words, but are not describing WHAT you want to see.
you didn't make 1 reference to my post and say, like that but change it this way, or,.....


* The first lower indicator should plot the 11 sectors separated in two, gaging to plot the following in the below.
1. The weighted sectors.
2. The unweighted sectors.
plot the 11 sectors? so you want 11 histograms?
separate in 2 groups of what? do you want the 2 groups of sectors combined into 2 histograms? add up the sector prices? average them?
i don't know what gaging is.
if you want 2 groups of sectors, them you create 2 lists and tell us what to do with them.


* The second lower indicator should plot only the major markets which are SPX, NDX, DJI, COMP and RUT (so, one zero line following up with the SPX plot defined as the 11 sectors in one as a whole, the NDX plot, the DJI plot, the COMP plot and the RUT plot).
so you want 5 histograms ?....
 
* The lower indicator should plot only the major markets which are SPX, NDX, DJI, COMP and RUT (so, one zero line following up with the SPX plot defined as the 11 sectors in one as a whole, the NDX plot, the DJI plot, the COMP plot and the RUT plot).

Yes, I need 5 histograms.
 

Attachments

  • Screenshot 2023-05-31 at 10.45.29 AM.png
    Screenshot 2023-05-31 at 10.45.29 AM.png
    258.9 KB · Views: 169
Last edited:
I don't see how plotting 5 or more histograms on top of each other is going to give you an edge?

You have colored each level with a different color, so assign each sector to a separate line and then use AssignValueColor to that sector
 
I don't see how plotting 5 or more histograms on top of each other is going to give you an edge?

You have colored each level with a different color, so assign each sector to a separate line and then use AssignValueColor to that sector
I drew an image so you can have an idea of what I'm looking for. It represents the 5 markets for the second indicator needed Combining histograms and lines is just my personal preference.
 

Attachments

  • Screenshot 2023-05-31 at 1.15.51 PM.png
    Screenshot 2023-05-31 at 1.15.51 PM.png
    75.5 KB · Views: 141
Last edited:
Hi BenTen,

I appreciate the link provided and I've seen it before but it's not what I'm looking for.
Would you please be kind enough to use the code provided in the below and add a lower indicator that plots histograms with a zero line only for the following markets: SPX, NDX, DJI, COMP and RUT (Use the attached image as a reference).

script Sector {
input symb = "SPX";
def c = close(symbol = symb, period = AggregationPeriod.DAY);
def PctChg = (c / c[1]) - 1;
plot pct = PctChg;
}

def SPX = Sector("SPX");
def spxPer = Round(SPX, 4) * 100;

def CurrSP = +close("SPX", period = AggregationPeriod.DAY);
def ChangeSP = CurrSP - CurrSP[1];

addLabel(1, "SPX: "+ CurrSP + " Chg: " + ChangeSP + " (" + spxPer + "%" + ") ", if ChangeSP > 0 then color.cyan else if ChangeSP < 0 then color.LIGHT_GRAY else if spxPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

AddLabel(1, ":", Color.YELLOW);

def NDX = Sector("NDX");
def NDXPer = Round(NDX, 4) * 100;

def CurrNDX = +close("NDX", period = AggregationPeriod.DAY);
def ChangeNDX = CurrNDX - CurrNDX[1];

addLabel(1, "NDX: "+ CurrNDX + " Chg: " + ChangeNDX + " (" + NDXPer + "%" + ") ", if ChangeNDX > 0 then color.cyan else if ChangeNDX < 0 then color.LIGHT_GRAY else if NDXPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

AddLabel(1, ":", Color.YELLOW);

def DJI = Sector("$DJI");
def djiPer = Round(DJI, 4) * 100;

def CurrDJ = +close("$DJI", period = AggregationPeriod.DAY);
def ChangeDJ = CurrDJ - CurrDJ[1];

addLabel(1, "DJI: "+CurrDJ +" Chg : " + ChangeDJ + " (" + djiPer + "%" + ") ", if ChangeDJ > 0 then color.cyan else if ChangeDJ < 0 then color.LIGHT_GRAY else if spxPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

AddLabel(1, ":", Color.YELLOW);

def COMP = Sector("COMP:GIDS");
def compPer = Round(COMP, 4) * 100;

def CurrC = +close("COMP:GIDS", period = AggregationPeriod.DAY);
def ChangeC = CurrC - CurrC[1];

addLabel(1, "COMP: "+CurrC +" Chg : " + ChangeC + " (" + compPer + "%" + ") " + " ", if ChangeC > 0 then color.cyan else if ChangeC < 0 then color.LIGHT_GRAY else if compPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

def RUT = Sector("RUT");
def rutPer = Round(RUT, 4) * 100;

def CurrRU = +close("RUT", period = AggregationPeriod.DAY);
def ChangeRU = CurrRU - CurrRU[1];

addLabel(1, "RUT: "+CurrRU +" Chg :" + ChangeRU + " (" + rutPer + "%" + ") " + " ", if ChangeRU > 0 then color.cyan else if ChangeRU < 0 then color.LIGHT_GRAY else if rutPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

AddLabel(yes, ":", Color.YELLOW);
 

Attachments

  • Screenshot 2023-05-31 at 1.15.51 PM.png
    Screenshot 2023-05-31 at 1.15.51 PM.png
    75.5 KB · Views: 116
Last edited:
Hi BenTen,

I appreciate the link provided and I've seen it before but it's not what I'm looking for.
Would you please be kind enough to use the code provided in the below and add a lower indicator that plots histograms with a zero line only for the following markets: SPX, NDX, DJI, COMP and RUT (Use the attached image as a reference).

script Sector {
input symb = "SPX";
def c = close(symbol = symb, period = AggregationPeriod.DAY);
def PctChg = (c / c[1]) - 1;
plot pct = PctChg;
}

def SPX = Sector("SPX");
def spxPer = Round(SPX, 4) * 100;

def CurrSP = +close("SPX", period = AggregationPeriod.DAY);
def ChangeSP = CurrSP - CurrSP[1];

addLabel(1, "SPX: "+ CurrSP + " Chg: " + ChangeSP + " (" + spxPer + "%" + ") ", if ChangeSP > 0 then color.cyan else if ChangeSP < 0 then color.LIGHT_GRAY else if spxPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

AddLabel(1, ":", Color.YELLOW);

def NDX = Sector("NDX");
def NDXPer = Round(NDX, 4) * 100;

def CurrNDX = +close("NDX", period = AggregationPeriod.DAY);
def ChangeNDX = CurrNDX - CurrNDX[1];

addLabel(1, "NDX: "+ CurrNDX + " Chg: " + ChangeNDX + " (" + NDXPer + "%" + ") ", if ChangeNDX > 0 then color.cyan else if ChangeNDX < 0 then color.LIGHT_GRAY else if NDXPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

AddLabel(1, ":", Color.YELLOW);

def DJI = Sector("$DJI");
def djiPer = Round(DJI, 4) * 100;

def CurrDJ = +close("$DJI", period = AggregationPeriod.DAY);
def ChangeDJ = CurrDJ - CurrDJ[1];

addLabel(1, "DJI: "+CurrDJ +" Chg : " + ChangeDJ + " (" + djiPer + "%" + ") ", if ChangeDJ > 0 then color.cyan else if ChangeDJ < 0 then color.LIGHT_GRAY else if spxPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

AddLabel(1, ":", Color.YELLOW);

def COMP = Sector("COMP:GIDS");
def compPer = Round(COMP, 4) * 100;

def CurrC = +close("COMP:GIDS", period = AggregationPeriod.DAY);
def ChangeC = CurrC - CurrC[1];

addLabel(1, "COMP: "+CurrC +" Chg : " + ChangeC + " (" + compPer + "%" + ") " + " ", if ChangeC > 0 then color.cyan else if ChangeC < 0 then color.LIGHT_GRAY else if compPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

def RUT = Sector("RUT");
def rutPer = Round(RUT, 4) * 100;

def CurrRU = +close("RUT", period = AggregationPeriod.DAY);
def ChangeRU = CurrRU - CurrRU[1];

addLabel(1, "RUT: "+CurrRU +" Chg :" + ChangeRU + " (" + rutPer + "%" + ") " + " ", if ChangeRU > 0 then color.cyan else if ChangeRU < 0 then color.LIGHT_GRAY else if rutPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

AddLabel(yes, ":", Color.YELLOW);
Hi BenTen,

Please provide updates for this request. I'll really appreciate it if this could be completed soon.

Thanks.
 
Hey Guys,

Not sure what else is missing or why isn't working. I've been playing around with for bit but can't get it done.
Can someone take a look and check what's missing? Thanks in advance.

declare lower;input timeframe = AggregationPeriod.DAY;input Open_Time = 930;### SECTOR SYMBOLS ###input s08_Technology = "XLK";input s06_Health_Care = "XLV";input s04_discretionary = "XLY";input s07_Financials = "XLF";input s09_services = "XLC";input s03_Industrials = "XLI";input s05_Staples = "XLP";input s01_Energy = "XLE";input s10_Utilities = "XLU";input s11_Real_Estate = "XLRE";input s02_Materials = "XLB";def XLK_PRnow = (close("XLK") - close("XLK")[1]) / close("XLK")[1] * s08_Technology / 100;def XLV_PRnow = (close("XLV") - close("XLV")[1]) / close("XLV")[1] * s06_Health_Care / 100;def XLY_PRnow = (close("XLY") - close("XLY")[1]) / close("XLY")[1] * s04_discretionary / 100;def XLF_PRnow = (close("XLF") - close("XLF")[1]) / close("XLF")[1] * s07_Financials / 100;def XLC_PRnow = (close("XLC") - close("XLC")[1]) / close("XLC")[1] * s09_services / 100;def XLI_PRnow = (close("XLI") - close("XLI")[1]) / close("XLI")[1] * s03_Industrials / 100;def XLP_PRnow = (close("XLP") - close("XLP")[1]) / close("XLP")[1] * s05_Staples / 100;def XLE_PRnow = (close("XLE") - close("XLE")[1]) / close("XLE")[1] * s01_Energy / 100;def XLU_PRnow = (close("XLU") - close("XLU")[1]) / close("XLU")[1] * s10_Utilities / 100;def XLRE_PRnow = (close("XLRE") - close("XLRE")[1]) / close("XLRE")[1] * s11_Real_Estate / 100;def XLB_PRnow = (close("XLB") - close("XLB")[1]) / close("XLB")[1] * s02_Materials / 100;def CAD = XLK_PRnow + XLV_PRnow + XLY_PRnow + XLF_PRnow + XLC_PRnow + XLI_PRnow + XLP_PRnow + XLE_PRnow + XLU_PRnow + XLRE_PRnow + XLB_PRnow;def Divider = 6.5 * 60 / getAggregationPeriod() * 200 * 500;def notFirstBar = if SecondsFromTime(Open_Time) >= 0 and SecondsFromTime(Open_Time)[1] >= 0 then 1 else 0;def X = if getAggregationPeriod() == AggregationPeriod.MIN then 70000 else if getAggregationPeriod() == AggregationPeriod.TWO_MIN then 60000 else if getAggregationPeriod() == AggregationPeriod.THREE_MIN then 55000 else if getAggregationPeriod() == AggregationPeriod.FOUR_MIN then 50000 else if getAggregationPeriod() == AggregationPeriod.FIVE_MIN then 45000 else if getAggregationPeriod() == AggregationPeriod.TEN_MIN then 37500 else if getAggregationPeriod() == AggregationPeriod.FIFTEEN_MIN then 35000 else if getAggregationPeriod() == AggregationPeriod.THIRTY_MIN then 32500 else if getAggregationPeriod() == AggregationPeriod.HOUR then 27500 else double.nan;def CAD2 = 11 * (XLK_PRnow / s08_Technology + XLV_PRnow / s06_Health_Care + XLY_PRnow / s04_discretionary + XLF_PRnow / s07_Financials + XLC_PRnow / s09_services + XLI_PRnow / s03_Industrials + XLP_PRnow / s05_Staples + XLE_PRnow / s01_Energy + XLU_PRnow / s10_Utilities + XLRE_PRnow / s11_Real_Estate + XLB_PRnow / s02_Materials);def CT2 = if GetDay() != GetDay()[1] then 0 else if notFirstBar then CT2[1] + CAD2 else 0;plot Non_Weighted_AD = if !IsNaN(CAD2) then CT2 * X else Double.NaN;def CT = if GetDay() != GetDay()[1] then 0 else if notFirstBar then CT[1] + CAD else 0;plot Weighted_AD = if !IsNaN(CAD) then CT * X else Double.NaN;plot zero = 0;zero.SetDefaultColor(Color.WHITE);zero.HideBubble();zero.HideTitle();Weighted_AD.AssignValueColor(if Weighted_AD >= Weighted_AD[1] then Color.MAGENTA else Color.ORANGE);
 
Hey Guys,

Not sure what else is missing or why isn't working. I've been playing around with for bit but can't get it done.
Can someone take a look and check what's missing? Thanks in advance.

declare lower;input timeframe = AggregationPeriod.DAY;input Open_Time = 930;### SECTOR SYMBOLS ###input s08_Technology = "XLK";input s06_Health_Care = "XLV";input s04_discretionary = "XLY";input s07_Financials = "XLF";input s09_services = "XLC";input s03_Industrials = "XLI";input s05_Staples = "XLP";input s01_Energy = "XLE";input s10_Utilities = "XLU";input s11_Real_Estate = "XLRE";input s02_Materials = "XLB";def XLK_PRnow = (close("XLK") - close("XLK")[1]) / close("XLK")[1] * s08_Technology / 100;def XLV_PRnow = (close("XLV") - close("XLV")[1]) / close("XLV")[1] * s06_Health_Care / 100;def XLY_PRnow = (close("XLY") - close("XLY")[1]) / close("XLY")[1] * s04_discretionary / 100;def XLF_PRnow = (close("XLF") - close("XLF")[1]) / close("XLF")[1] * s07_Financials / 100;def XLC_PRnow = (close("XLC") - close("XLC")[1]) / close("XLC")[1] * s09_services / 100;def XLI_PRnow = (close("XLI") - close("XLI")[1]) / close("XLI")[1] * s03_Industrials / 100;def XLP_PRnow = (close("XLP") - close("XLP")[1]) / close("XLP")[1] * s05_Staples / 100;def XLE_PRnow = (close("XLE") - close("XLE")[1]) / close("XLE")[1] * s01_Energy / 100;def XLU_PRnow = (close("XLU") - close("XLU")[1]) / close("XLU")[1] * s10_Utilities / 100;def XLRE_PRnow = (close("XLRE") - close("XLRE")[1]) / close("XLRE")[1] * s11_Real_Estate / 100;def XLB_PRnow = (close("XLB") - close("XLB")[1]) / close("XLB")[1] * s02_Materials / 100;def CAD = XLK_PRnow + XLV_PRnow + XLY_PRnow + XLF_PRnow + XLC_PRnow + XLI_PRnow + XLP_PRnow + XLE_PRnow + XLU_PRnow + XLRE_PRnow + XLB_PRnow;def Divider = 6.5 * 60 / getAggregationPeriod() * 200 * 500;def notFirstBar = if SecondsFromTime(Open_Time) >= 0 and SecondsFromTime(Open_Time)[1] >= 0 then 1 else 0;def X = if getAggregationPeriod() == AggregationPeriod.MIN then 70000 else if getAggregationPeriod() == AggregationPeriod.TWO_MIN then 60000 else if getAggregationPeriod() == AggregationPeriod.THREE_MIN then 55000 else if getAggregationPeriod() == AggregationPeriod.FOUR_MIN then 50000 else if getAggregationPeriod() == AggregationPeriod.FIVE_MIN then 45000 else if getAggregationPeriod() == AggregationPeriod.TEN_MIN then 37500 else if getAggregationPeriod() == AggregationPeriod.FIFTEEN_MIN then 35000 else if getAggregationPeriod() == AggregationPeriod.THIRTY_MIN then 32500 else if getAggregationPeriod() == AggregationPeriod.HOUR then 27500 else double.nan;def CAD2 = 11 * (XLK_PRnow / s08_Technology + XLV_PRnow / s06_Health_Care + XLY_PRnow / s04_discretionary + XLF_PRnow / s07_Financials + XLC_PRnow / s09_services + XLI_PRnow / s03_Industrials + XLP_PRnow / s05_Staples + XLE_PRnow / s01_Energy + XLU_PRnow / s10_Utilities + XLRE_PRnow / s11_Real_Estate + XLB_PRnow / s02_Materials);def CT2 = if GetDay() != GetDay()[1] then 0 else if notFirstBar then CT2[1] + CAD2 else 0;plot Non_Weighted_AD = if !IsNaN(CAD2) then CT2 * X else Double.NaN;def CT = if GetDay() != GetDay()[1] then 0 else if notFirstBar then CT[1] + CAD else 0;plot Weighted_AD = if !IsNaN(CAD) then CT * X else Double.NaN;plot zero = 0;zero.SetDefaultColor(Color.WHITE);zero.HideBubble();zero.HideTitle();Weighted_AD.AssignValueColor(if Weighted_AD >= Weighted_AD[1] then Color.MAGENTA else Color.ORANGE);


reply to #15

you didn't post code in a window
every line is run together, so i have to separate every line.....
just a minute... looking

--------------------

this variable isn't defined
* s08_Technology


you are trying to multiply numbers times text
def XLV_PRnow = (close("XLV") - close("XLV")[1]) / close("XLV")[1] * s06_Health_Care / 100;

the last parameter is text, not a number
s06_Health_Care


not sure why you are /100 with percent numbers. usually you *100

Code:
#Sector_Histogram_day_00

#Sector Histogram
#woulf1004  6/9

#Not sure what else is missing or why isn't working. I've been playing around with for bit but can't get it done.
#Can someone take a look and check what's missing? Thanks in advance.

declare lower;

input timeframe = AggregationPeriod.DAY;
input Open_Time = 930;
### SECTOR SYMBOLS
###input s08_Technology = "XLK";
input s06_Health_Care = "XLV";
input s04_discretionary = "XLY";
input s07_Financials = "XLF";
input s09_services = "XLC";
input s03_Industrials = "XLI";
input s05_Staples = "XLP";
input s01_Energy = "XLE";
input s10_Utilities = "XLU";
input s11_Real_Estate = "XLRE";
input s02_Materials = "XLB";

#def XLK_PRnow = (close("XLK") - close("XLK")[1]) / close("XLK")[1] * s08_Technology / 100;
def XLV_PRnow = (close("XLV") - close("XLV")[1]) / close("XLV")[1] * s06_Health_Care / 100;
def XLY_PRnow = (close("XLY") - close("XLY")[1]) / close("XLY")[1] * s04_discretionary / 100;
def XLF_PRnow = (close("XLF") - close("XLF")[1]) / close("XLF")[1] * s07_Financials / 100;
def XLC_PRnow = (close("XLC") - close("XLC")[1]) / close("XLC")[1] * s09_services / 100;
def XLI_PRnow = (close("XLI") - close("XLI")[1]) / close("XLI")[1] * s03_Industrials / 100;
def XLP_PRnow = (close("XLP") - close("XLP")[1]) / close("XLP")[1] * s05_Staples / 100;
def XLE_PRnow = (close("XLE") - close("XLE")[1]) / close("XLE")[1] * s01_Energy / 100;
def XLU_PRnow = (close("XLU") - close("XLU")[1]) / close("XLU")[1] * s10_Utilities / 100;
def XLRE_PRnow = (close("XLRE") - close("XLRE")[1]) / close("XLRE")[1] * s11_Real_Estate / 100;
def XLB_PRnow = (close("XLB") - close("XLB")[1]) / close("XLB")[1] * s02_Materials / 100;

def CAD = XLK_PRnow + XLV_PRnow + XLY_PRnow + XLF_PRnow + XLC_PRnow + XLI_PRnow + XLP_PRnow + XLE_PRnow + XLU_PRnow + XLRE_PRnow + XLB_PRnow;
def Divider = 6.5 * 60 / GetAggregationPeriod() * 200 * 500;

def notFirstBar = if SecondsFromTime(Open_Time) >= 0 and SecondsFromTime(Open_Time)[1] >= 0 then 1 else 0;
def X = if GetAggregationPeriod() == AggregationPeriod.MIN then 70000 else if GetAggregationPeriod() == AggregationPeriod.TWO_MIN then 60000 else if GetAggregationPeriod() == AggregationPeriod.THREE_MIN then 55000 else if GetAggregationPeriod() == AggregationPeriod.FOUR_MIN then 50000 else if GetAggregationPeriod() == AggregationPeriod.FIVE_MIN then 45000 else if GetAggregationPeriod() == AggregationPeriod.TEN_MIN then 37500 else if GetAggregationPeriod() == AggregationPeriod.FIFTEEN_MIN then 35000 else if GetAggregationPeriod() == AggregationPeriod.THIRTY_MIN then 32500 else if GetAggregationPeriod() == AggregationPeriod.HOUR then 27500 else Double.NaN;

def CAD2 = 11 * (XLK_PRnow / s08_Technology + XLV_PRnow / s06_Health_Care + XLY_PRnow / s04_discretionary + XLF_PRnow / s07_Financials + XLC_PRnow / s09_services + XLI_PRnow / s03_Industrials + XLP_PRnow / s05_Staples + XLE_PRnow / s01_Energy + XLU_PRnow / s10_Utilities + XLRE_PRnow / s11_Real_Estate + XLB_PRnow / s02_Materials);
def CT2 = if GetDay() != GetDay()[1] then 0 else if notFirstBar then CT2[1] + CAD2 else 0;

;
plot Non_Weighted_AD = if !IsNaN(CAD2) then CT2 * X else Double.NaN;
def CT = if GetDay() != GetDay()[1] then 0 else if notFirstBar then CT[1] + CAD else 0;
plot Weighted_AD = if !IsNaN(CAD) then CT * X else Double.NaN;
plot zero = 0;
zero.SetDefaultColor(Color.WHITE);
zero.HideBubble();
zero.HideTitle();
Weighted_AD.AssignValueColor(if Weighted_AD >= Weighted_AD[1] then Color.MAGENTA else Color.ORANGE);
#


tweaking the code.........

..
 
Last edited:
I need these sectors to automatically update based on the current market sectors and have tried everything I could. Maybe I'm missing the data needed but my I'm very limited on this coding skills. Could you please provide a hand to fix this script? Oh, and I'm very sorry for the mess..
 
Hi All,

I have made slight changes to add markets of interest for quick over view. Now that we have the SPX, NDX, DJI, COMP and RUT. Can someone create a lower single indicator that plots a histogram for these markets that has a zero line? Plot bullish in color green if is above zero or red when bearish when it's below zero. This zero line should also change colors based on bullish or bearish sentiment.

Code:
# S&P 500 Sector Performance (Percentage)
# Paris
# 4.12.2018
# After reviewing chubbyboy's S&P sector study, I thought it might
# be a good idea to display labels of relative S&P sector performance
# in percentages. At one glance this will enable us to determine
# which sectors are happening and which are not. Decided to use a
# script() to retrieve the data. Also, I changed the formula slightly.
# The percentage displayed is the current price as a percentage over
# yesterday's closing rather than the open today as was used in chubbyboy's
# study.
#====== Further Modified by Killing Hours ======#
# 5/4/2020 #
# Added Color Mapping #
# to distinguish more suddle movements #
#===============================================#
#Modified slightly by Headhunter20.


######################################################################################
script Sector {
input symb = "SPX";
def c = close(symbol = symb, period = AggregationPeriod.day);
def PctChg = (c / c[1]) - 1;
plot pct = PctChg;
}

#Define the color map. Change as you see fit
DefineGlobalColor("VeryGood", CreateColor(4, 216, 22));
DefineGlobalColor("Good", CreateColor(46, 216, 4));
DefineGlobalColor("ModGood", CreateColor(121, 216, 4));
DefineGlobalColor("SlightlyGood", CreateColor(167, 216, 4));
DefineGlobalColor("SluggishGood", CreateColor(210,252,126));
DefineGlobalColor("Neutral", CreateColor(252, 231, 126));
DefineGlobalColor("SluggishBad", CreateColor(252,168,126));
DefineGlobalColor("SlightlyBad", CreateColor(216, 163, 4));
DefineGlobalColor("ModBad", CreateColor(216, 117, 4));
DefineGlobalColor("Bad", CreateColor(216, 43, 4));
DefineGlobalColor("VeryBad", CreateColor(216, 4, 4));

# SPX Overall
def SPX = Sector("SPX");
def spxPer = round(SPX,4) * 100;
def CurrSP = +close("SPX", period = AggregationPeriod.DAY);
def ChangeSP = CurrSP - CurrSP[1];

addLabel(1, "S&P500: "+ CurrSP + " Chg: " + ChangeSP + "  (" + spxPer + "%" + ")   ", if ChangeSP > 0 then color.cyan else if ChangeSP < 0 then color.gray else if spxPer > 0 then COLOR.CYAN else color.gray);

# Energy Sector
def Energy = Sector("$SP500#10");
def engPer = round(Energy,4) * 100;
AddLabel(
1,
"Energy: "+engPer+"% XLE #10",
if engPer > 1.50 then GlobalColor("VeryGood") else
if engPer > 1 && engPer <= 1.50 then GlobalColor("Good") else
if engPer > .5 && engPer <= 1 then GlobalColor("ModGood") else
if engPer > .25 && engPer <= .5 then GlobalColor("SlightlyGood") else
if engPer > 0 && engPer <= .25 then GlobalColor("SluggishGood") else
if engPer == 0 then GlobalColor("Neutral") else
if engPer < 0 && engPer >= -.25 then GlobalColor("SluggishBad") else
if engPer < -.25 && engPer >= -.5 then GlobalColor("SlightlyBad") else
if engPer < -.5 && engPer >= -1 then GlobalColor("ModBad") else
if engPer < -1 && engPer >= -1.50 then GlobalColor("Bad") else
if engPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Consumer Discretionary Spending Sector
def ConDisr = Sector("$SP500#25");
def conDPer = round(ConDisr,4);
AddLabel(
1,
"Con. Discretionary: "+conDPer+"% XLY #25",
if conDPer > 1.50 then GlobalColor("VeryGood") else
if conDPer > 1 && conDPer <= 1.50 then GlobalColor("Good") else
if conDPer > .5 && conDPer <= 1 then GlobalColor("ModGood") else
if conDPer > .25 && conDPer <= .5 then GlobalColor("SlightlyGood") else
if conDPer > 0 && conDPer <= .25 then GlobalColor("SluggishGood") else
if conDPer == 0 then GlobalColor("Neutral") else
if conDPer < 0 && conDPer >= -.25 then GlobalColor("SluggishBad") else
if conDPer < -.25 && conDPer >= -.5 then GlobalColor("SlightlyBad") else
if conDPer < -.5 && conDPer >= -1 then GlobalColor("ModBad") else
if conDPer < -1 && conDPer >= -1.50 then GlobalColor("Bad") else
if conDPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Financial Sector
def Finance = Sector("$SP500#40");
def finPer = round(Finance,4) * 100;
AddLabel(
1,
"Financials: "+finPer+"% XLF #40",
if finPer > 1.50 then GlobalColor("VeryGood") else
if finPer > 1 && finPer <= 1.50 then GlobalColor("Good") else
if finPer > .5 && finPer <= 1 then GlobalColor("ModGood") else
if finPer > .25 && finPer <= .5 then GlobalColor("SlightlyGood") else
if finPer > 0 && finPer <= .25 then GlobalColor("SluggishGood") else
if finPer == 0 then GlobalColor("Neutral") else
if finPer < 0 && finPer >= -.25 then GlobalColor("SluggishBad") else
if finPer < -.25 && finPer >= -.5 then GlobalColor("SlightlyBad") else
if finPer < -.5 && finPer >= -1 then GlobalColor("ModBad") else
if finPer < -1 && finPer >= -1.50 then GlobalColor("Bad") else
if finPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Utilities Sector
def Utilities = Sector("$SP500#55");
def utiPer = round(Utilities,4) * 100;
AddLabel(
1,
"Utilities: "+utiPer+"% XLU #55",
if utiPer > 1.50 then GlobalColor("VeryGood") else
if utiPer > 1 && utiPer <= 1.50 then GlobalColor("Good") else
if utiPer > .5 && utiPer <= 1 then GlobalColor("ModGood") else
if utiPer > .25 && utiPer <= .5 then GlobalColor("SlightlyGood") else
if utiPer > 0 && utiPer <= .25 then GlobalColor("SluggishGood") else
if utiPer == 0 then GlobalColor("Neutral") else
if utiPer < 0 && utiPer >= -.25 then GlobalColor("SluggishBad") else
if utiPer < -.25 && utiPer >= -.5 then GlobalColor("SlightlyBad") else
if utiPer < -.5 && utiPer >= -1 then GlobalColor("ModBad") else
if utiPer < -1 && utiPer >= -1.50 then GlobalColor("Bad") else
if utiPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Materials Sector
def Materials = Sector("$SP500#15");
def matPer = round(Materials,4) * 100;
AddLabel(
1,
"Materials: "+matPer+"% XLB #15",
if matPer > 1.50 then GlobalColor("VeryGood") else
if matPer > 1 && matPer <= 1.50 then GlobalColor("Good") else
if matPer > .5 && matPer <= 1 then GlobalColor("ModGood") else
if matPer > .25 && matPer <= .5 then GlobalColor("SlightlyGood") else
if matPer > 0 && matPer <= .25 then GlobalColor("SluggishGood") else
if matPer == 0 then GlobalColor("Neutral") else
if matPer < 0 && matPer >= -.25 then GlobalColor("SluggishBad") else
if matPer < -.25 && matPer >= -.5 then GlobalColor("SlightlyBad") else
if matPer < -.5 && matPer >= -1 then GlobalColor("ModBad") else
if matPer < -1 && matPer >= -1.50 then GlobalColor("Bad") else
if matPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Consumer Staples Sector
def ConStaple = Sector("$SP500#30");
def conSPer = round(ConStaple,4) * 100;
AddLabel(
1,
"Consumer Staples: "+conSPer+"% XLP #30",
if conSPer > 1.50 then GlobalColor("VeryGood") else
if conSPer > 1 && conSPer <= 1.50 then GlobalColor("Good") else
if conSPer > .5 && conSPer <= 1 then GlobalColor("ModGood") else
if conSPer > .25 && conSPer <= .5 then GlobalColor("SlightlyGood") else
if conSPer > 0 && conSPer <= .25 then GlobalColor("SluggishGood") else
if conSPer == 0 then GlobalColor("Neutral") else
if conSPer < 0 && conSPer >= -.25 then GlobalColor("SluggishBad") else
if conSPer < -.25 && conSPer >= -.5 then GlobalColor("SlightlyBad") else
if conSPer < -.5 && conSPer >= -1 then GlobalColor("ModBad") else
if conSPer < -1 && conSPer >= -1.50 then GlobalColor("Bad") else
if conSPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Information Technology Sector
def InfoTech = Sector("$SP500#45");
def infPer = round(InfoTech,4) * 100;
AddLabel(
1,
"Info Tech: " +infPer+"% XLK #45",
if infPer > 1.50 then GlobalColor("VeryGood") else
if infPer > 1 && infPer <= 1.50 then GlobalColor("Good") else
if infPer > .5 && infPer <= 1 then GlobalColor("ModGood") else
if infPer > .25 && infPer <= .5 then GlobalColor("SlightlyGood") else
if infPer > 0 && infPer <= .25 then GlobalColor("SluggishGood") else
if infPer == 0 then GlobalColor("Neutral") else
if infPer < 0 && infPer >= -.25 then GlobalColor("SluggishBad") else
if infPer < -.25 && infPer >= -.5 then GlobalColor("SlightlyBad") else
if infPer < -.5 && infPer >= -1 then GlobalColor("ModBad") else
if infPer < -1 && infPer >= -1.50 then GlobalColor("Bad") else
if infPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Real Estate Sector
def RealEste = Sector("$SP500#60");
def reaPer = round(RealEste,4) * 100;
AddLabel(
1,
"Real Estate: " +reaPer+"% XLRE #60",
if reaPer > 1.50 then GlobalColor("VeryGood") else
if reaPer > 1 && reaPer <= 1.50 then GlobalColor("Good") else
if reaPer > .5 && reaPer <= 1 then GlobalColor("ModGood") else
if reaPer > .25 && reaPer <= .5 then GlobalColor("SlightlyGood") else
if reaPer > 0 && reaPer <= .25 then GlobalColor("SluggishGood") else
if reaPer == 0 then GlobalColor("Neutral") else
if reaPer < 0 && reaPer >= -.25 then GlobalColor("SluggishBad") else
if reaPer < -.25 && reaPer >= -.5 then GlobalColor("SlightlyBad") else
if reaPer < -.5 && reaPer >= -1 then GlobalColor("ModBad") else
if reaPer < -1 && reaPer >= -1.50 then GlobalColor("Bad") else
if reaPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);


# Industrial Sector
def Industrl = Sector("$SP500#20");
def indPer = round(Industrl,4) * 100;
AddLabel(
1,
"Industrials: " +indPer+"% XLI #20",
if indPer > 1.50 then GlobalColor("VeryGood") else
if indPer > 1 && indPer <= 1.50 then GlobalColor("Good") else
if indPer > .5 && indPer <= 1 then GlobalColor("ModGood") else
if indPer > .25 && indPer <= .5 then GlobalColor("SlightlyGood") else
if indPer > 0 && indPer <= .25 then GlobalColor("SluggishGood") else
if indPer == 0 then GlobalColor("Neutral") else
if indPer < 0 && indPer >= -.25 then GlobalColor("SluggishBad") else
if indPer < -.25 && indPer >= -.5 then GlobalColor("SlightlyBad") else
if indPer < -.5 && indPer >= -1 then GlobalColor("ModBad") else
if indPer < -1 && indPer >= -1.50 then GlobalColor("Bad") else
if indPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Healthcare Sector
def Health = Sector("$SP500#35");
def heaPer = round(Health,4) * 100;
AddLabel(
1,
"Health Care: " +heaPer+"% XLV #35",
if heaPer > 1.50 then GlobalColor("VeryGood") else
if heaPer > 1 && heaPer <= 1.50 then GlobalColor("Good") else
if heaPer > .5 && heaPer <= 1 then GlobalColor("ModGood") else
if heaPer > .25 && heaPer <= .5 then GlobalColor("SlightlyGood") else
if heaPer > 0 && heaPer <= .25 then GlobalColor("SluggishGood") else
if heaPer == 0 then GlobalColor("Neutral") else
if heaPer < 0 && heaPer >= -.25 then GlobalColor("SluggishBad") else
if heaPer < -.25 && heaPer >= -.5 then GlobalColor("SlightlyBad") else
if heaPer < -.5 && heaPer >= -1 then GlobalColor("ModBad") else
if heaPer < -1 && heaPer >= -1.50 then GlobalColor("Bad") else
if heaPer < -1.50 then GlobalColor("VeryBad") else
Color.black
);

# Telecommunication Sector
def Telecoms = Sector("$SP500#50");
def telPef = round(Telecoms,4) * 100;
AddLabel(
1,
"Telecoms: " +telPef+"% XLC #50",
if telPef > 1.50 then GlobalColor("VeryGood") else
if telPef > 1 && telPef <= 1.50 then GlobalColor("Good") else
if telPef > .5 && telPef <= 1 then GlobalColor("ModGood") else
if telPef > .25 && telPef <= .5 then GlobalColor("SlightlyGood") else
if telPef > 0 && telPef <= .25 then GlobalColor("SluggishGood") else
if telPef == 0 then GlobalColor("Neutral") else
if telPef < 0 && telPef >= -.25 then GlobalColor("SluggishBad") else
if telPef < -.25 && telPef >= -.5 then GlobalColor("SlightlyBad") else
if telPef < -.5 && telPef >= -1 then GlobalColor("ModBad") else
if telPef < -1 && telPef >= -1.50 then GlobalColor("Bad") else
if telPef < -1.50 then GlobalColor("VeryBad") else
Color.black
);

def NDX = Sector("NDX");
def ndxPer = Round(NDX, 4) * 100;
def CurrND = +close("NDX", period = AggregationPeriod.DAY);
def ChangeNDX = CurrND - CurrND[1];

addLabel(1, "NASD: "+CurrND +" Chg :" + ChangeNDX + "  (" + ndxPer + "%" + ")  ", if ChangeNDX > 0 then color.cyan else if ChangeNDX < 0 then color.light_gray else if ndxPer > 0 then COLOR.CYAN else color.light_gray);

def DJI = Sector("$DJI");
def djiPer = Round(DJI, 4) * 100;
def CurrDJ = +close("$DJI", period = AggregationPeriod.DAY);
def ChangeDJ = CurrDJ - CurrDJ[1];

addLabel(yes, (Concat("DJI: ", Round (CurrDJ, 1))) + " Chg: " + Round(ChangeDJ) + " (" + djiPer + "%" + ")  ", if ChangeDJ > 0 then color.cyan else if ChangeDJ < 0 then color.LIGHT_GRAY else if djiPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

def COMP = Sector("COMP:GIDS");
def compPer = Round(COMP, 4) * 100;
def CurrC = +close("COMP:GIDS", period = AggregationPeriod.DAY);
def ChangeC = CurrC - CurrC[1];

addLabel(yes, (Concat("COMP: ", Round (CurrC, 1))) + " Chg: " + Round(ChangeC) + " (" + compPer + "%" + ")  ", if ChangeC > 0 then color.cyan else if ChangeC < 0 then color.LIGHT_GRAY else if compPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

def RUT = Sector("RUT");
def rutPer = Round(RUT, 4) * 100;
def CurrRU = +close("RUT", period = AggregationPeriod.DAY);
def ChangeRU = CurrRU - CurrRU[1];

addLabel(yes, (Concat("RUT: ", Round (CurrRU, 1))) + " Chg: " + Round(ChangeRU) + " (" + rutPer + "%" + ")  ", if ChangeRU > 0 then color.cyan else if ChangeRU < 0 then color.LIGHT_GRAY else if rutPer > 0 then COLOR.CYAN else color.LIGHT_GRAY);

# End Study

reply to #15

i still don't understand what you are trying to do. which is why i haven't responded to your other post.
you repeated yourself, but didn't add any new info.


maybe this will help?
not sure what this is plotting?
it has % change formulas for the 11 sectors .

i disabled some of the formulas at the end, because trying to multiply text * numbers.

i put all the sector variables in number order. was driving me crazy... and makes it easier to look at and very all 11 are there


Code:
#Sector_Histogram_day_00

#Sector Histogram
#woulf1004  6/9

#Not sure what else is missing or why isn't working. I've been playing around with for bit but can't get it done.
#Can someone take a look and check what's missing? Thanks in advance.

declare lower;

input timeframe = AggregationPeriod.DAY;
#input timeframe2 = AggregationPeriod.DAY;
def timeframe2 = getaggregationPeriod();

input Open_Time = 930;
### SECTOR SYMBOLS
input s01_Energy = "XLE";
input s02_Materials = "XLB";
input s03_Industrials = "XLI";
input s04_discretionary = "XLY";
input s05_Staples = "XLP";
input s06_Health_Care = "XLV";
input s07_Financials = "XLF";
input s08_Technology = "XLK";
input s09_services = "XLC";
input s10_Utilities = "XLU";
input s11_Real_Estate = "XLRE";


def s01_Energy_cls = close(symbol = "XLE", period = timeframe2);
def s02_Materials_cls = close(symbol = "XLB", period = timeframe2);
def s03_Industrials_cls = close(symbol = "XLI", period = timeframe2);
def s04_discretionary_cls = close(symbol = "XLY", period = timeframe2);
def s05_Staples_cls = close(symbol = "XLP", period = timeframe2);
def s06_Health_Care_cls = close(symbol = "XLV", period = timeframe2);
def s07_Financials_cls = close(symbol = "XLF", period = timeframe2);
def s08_Technology_cls = close(symbol = "XLK", period = timeframe2);
def s09_services_cls = close(symbol = "XLC", period = timeframe2);
def s10_Utilities_cls = close(symbol = "XLU", period = timeframe2);
def s11_Real_Estate_cls = close(symbol = "XLRE", period = timeframe2);

#def XLE_PRnow = (close("XLE") - close("XLE")[1]) / close("XLE")[1] * s01_Energy / 100;
#def XLB_PRnow = (close("XLB") - close("XLB")[1]) / close("XLB")[1] * s02_Materials / 100;
#def XLI_PRnow = (close("XLI") - close("XLI")[1]) / close("XLI")[1] * s03_Industrials / 100;
#def XLY_PRnow = (close("XLY") - close("XLY")[1]) / close("XLY")[1] * s04_discretionary / 100;
#def XLP_PRnow = (close("XLP") - close("XLP")[1]) / close("XLP")[1] * s05_Staples / 100;
#def XLV_PRnow = (close("XLV") - close("XLV")[1]) / close("XLV")[1] * s06_Health_Care / 100;
#def XLF_PRnow = (close("XLF") - close("XLF")[1]) / close("XLF")[1] * s07_Financials / 100;
#def XLK_PRnow = (close("XLK") - close("XLK")[1]) / close("XLK")[1] * s08_Technology / 100;
#def XLC_PRnow = (close("XLC") - close("XLC")[1]) / close("XLC")[1] * s09_services / 100;
#def XLU_PRnow = (close("XLU") - close("XLU")[1]) / close("XLU")[1] * s10_Utilities / 100;
#def XLRE_PRnow = (close("XLRE") - close("XLRE")[1]) / close("XLRE")[1] * s11_Real_Estate / 100;


# % chg of some sectors
#def XLE_per = 100 * (close("XLE") - close("XLE")[1]) / close("XLE")[1];
#def XLB_per = 100 * (close("XLB") - close("XLB")[1]) / close("XLB")[1];
#def XLI_per = 100 * (close("XLI") - close("XLI")[1]) / close("XLI")[1];
#def XLY_per = 100 * (close("XLY") - close("XLY")[1]) / close("XLY")[1];
#def XLP_per = 100 * (close("XLP") - close("XLP")[1]) / close("XLP")[1];
#def XLV_per = 100 * (close("XLV") - close("XLV")[1]) / close("XLV")[1];
#def XLF_per = 100 * (close("XLF") - close("XLF")[1]) / close("XLF")[1];
#def XLK_per = 100 * (close("XLK") - close("XLK")[1]) / close("XLK")[1];
#def XLC_per = 100 * (close("XLC") - close("XLC")[1]) / close("XLC")[1];
#def XLU_per = 100 * (close("XLU") - close("XLU")[1]) / close("XLU")[1];
#def XLRE_per = 100 * (close("XLRE") - close("XLRE")[1]) / close("XLRE")[1];


#   % chg of some sectors
def XLE_per = 100 * (s01_Energy_cls - s01_Energy_cls[1]) / s01_Energy_cls[1];
def XLB_per = 100 * (s02_Materials_cls - s02_Materials_cls[1]) / s02_Materials_cls[1];
def XLI_per = 100 * (s03_Industrials_cls - s03_Industrials_cls[1]) / s03_Industrials_cls[1];
def XLY_per = 100 * (s04_discretionary_cls - s04_discretionary_cls[1]) / s04_discretionary_cls[1];
def XLP_per = 100 * (s05_Staples_cls - s05_Staples_cls[1]) / s05_Staples_cls[1];
def XLV_per = 100 * (s06_Health_Care_cls - s06_Health_Care_cls[1]) / s06_Health_Care_cls[1];
def XLF_per = 100 * (s07_Financials_cls - s07_Financials_cls[1]) / s07_Financials_cls[1];
def XLK_per = 100 * (s08_Technology_cls - s08_Technology_cls[1]) / s08_Technology_cls[1];
def XLC_per = 100 * (s09_services_cls - s09_services_cls[1]) / s09_services_cls[1];
def XLU_per = 100 * (s10_Utilities_cls - s10_Utilities_cls[1]) / s10_Utilities_cls[1];
def XLRE_per = 100 * (s11_Real_Estate_cls - s11_Real_Estate_cls[1]) / s11_Real_Estate_cls[1];


#   $ chg of some sectors  ,  % chg * the price
def XLE_PRnow = s01_Energy_cls * XLE_per / 100;
def XLB_PRnow = s02_Materials_cls * XLB_per / 100;
def XLI_PRnow = s03_Industrials_cls * XLI_per / 100;
def XLY_PRnow = s04_discretionary_cls * XLY_per / 100;
def XLP_PRnow = s05_Staples_cls * XLP_per / 100;
def XLV_PRnow = s06_Health_Care_cls * XLV_per / 100;
def XLF_PRnow = s07_Financials_cls * XLF_per / 100;
def XLK_PRnow = s08_Technology_cls * XLK_per / 100;
def XLC_PRnow = s09_services_cls * XLC_per / 100;
def XLU_PRnow = s10_Utilities_cls * XLU_per / 100;
def XLRE_PRnow = s11_Real_Estate_cls * XLRE_per / 100;



def CAD = XLK_PRnow + XLV_PRnow + XLY_PRnow + XLF_PRnow + XLC_PRnow + XLI_PRnow + XLP_PRnow + XLE_PRnow + XLU_PRnow + XLRE_PRnow + XLB_PRnow;
def Divider = 6.5 * 60 / GetAggregationPeriod() * 200 * 500;

def notFirstBar = if SecondsFromTime(Open_Time) >= 0 and SecondsFromTime(Open_Time)[1] >= 0 then 1 else 0;
def X = if GetAggregationPeriod() == AggregationPeriod.MIN then 70000 else if GetAggregationPeriod() == AggregationPeriod.TWO_MIN then 60000 else if GetAggregationPeriod() == AggregationPeriod.THREE_MIN then 55000 else if GetAggregationPeriod() == AggregationPeriod.FOUR_MIN then 50000 else if GetAggregationPeriod() == AggregationPeriod.FIVE_MIN then 45000 else if GetAggregationPeriod() == AggregationPeriod.TEN_MIN then 37500 else if GetAggregationPeriod() == AggregationPeriod.FIFTEEN_MIN then 35000 else if GetAggregationPeriod() == AggregationPeriod.THIRTY_MIN then 32500 else if GetAggregationPeriod() == AggregationPeriod.HOUR then 27500 else Double.NaN;

#  text * numbers
#def CAD2 = 11 * (XLK_PRnow / s08_Technology + XLV_PRnow / s06_Health_Care + XLY_PRnow / s04_discretionary + XLF_PRnow / s07_Financials + XLC_PRnow / s09_services + XLI_PRnow / s03_Industrials + XLP_PRnow / s05_Staples + XLE_PRnow / s01_Energy + XLU_PRnow / s10_Utilities + XLRE_PRnow / s11_Real_Estate + XLB_PRnow / s02_Materials);
#def CT2 = if GetDay() != GetDay()[1] then 0 else if notFirstBar then CT2[1] + CAD2 else 0;


#plot Non_Weighted_AD = if !IsNaN(CAD2) then CT2 * X else Double.NaN;

def CT = if GetDay() != GetDay()[1] then 0 else if notFirstBar then CT[1] + CAD else 0;
plot Weighted_AD = if !IsNaN(CAD) then CT * X else Double.NaN;
plot zero = 0;
zero.SetDefaultColor(Color.WHITE);
zero.HideBubble();
zero.HideTitle();
Weighted_AD.AssignValueColor(if Weighted_AD >= Weighted_AD[1] then Color.MAGENTA else Color.ORANGE);


#
 
I need these sectors to automatically update based on the current market sectors and have tried everything I could. Maybe I'm missing the data needed but my I'm very limited on this coding skills. Could you please provide a hand to fix this script? Oh, and I'm very sorry for the mess..

i am going to be blunt. i will try to help you. i don't intend to sound mean.
but, you have to learn how to describe what you want to see on the chart.
you have made several posts and i'm still lost.

go read your post17. it tells us nothing.
....need these sectors to automatically update based on the current market....
every study ever written needs to read data and update...

try to think about and describe WHAT you want to see on the chart
you don't need to know code to do that. maybe scribble something on paper will help you get some ideas flowing , and be able to describe it.

if you can convey what you want, then people can help

there are many posts about sectors. maybe a search for them will find something to give you some ideas. here is one.
https://usethinkscript.com/threads/sector-rotation-indicator-for-thinkorswim.845/
 
Thanks for your honesty and response halcyonguy. I will be more detailed going forward and ask one request at a time to avoid confusions. Please disregard all previous request and use the code in the below which will give you a better view and understanding for what I need to re-organize this request.
I have attached an image for your reference with annotations as well. You will se a red circled area in the settings where the values of each sector needs to be manually updated to plot the correct values.
Now, here's the request. Can this be automated so there is no need for manual updates for these sectors?
The circle in yellow in the below is the result and histogram + plots based on these values.

#######################

declare lower;

Input Open_Time = 930;

input XLK_TECH = 25.74;
input XLV_HEALTH = 15.82;
input XLY_DISCRETIONARY = 9.80;
input XLF_FINANCIALS = 11.66;
input XLC_SERVICES = 7.28;
input XLI_INDUSTRIALS = 8.65;
input XLP_STAPLES = 7.20;
input XLE_ENERGY = 5.23;
input XLU_UTILITIES = 3.18;
input XLRE_RESTATE = 2.71;
input XLB_MATERIALS = 2.73;


### SECTOR SYMBOLS
#input s08_Technology = "XLK";
#input s06_Health_Care = "XLV";
#input s04_descretionary = "XLY";
#input s07_Financials = "XLF";
#input s09_services = "XLC";
#input s03_Industrials = "XLI";
#input s05_Staples = "XLP";
#input s01_Energy = "XLE";
#input s10_Utilities = "XLU";
#input s11_Real_Estate = "XLRE";
#input s02_Materials = "XLB";

def XLK_PRnow = (close("XLK")-close("XLK")[1])/close("XLK")[1]*XLK_TECH/100;
def XLV_PRnow = (close("XLV")-close("XLV")[1])/close("XLV")[1]*XLV_HEALTH/100;
def XLY_PRnow = (close("XLY")-close("XLY")[1])/close("XLY")[1]*XLY_DISCRETIONARY/100;
def XLF_PRnow = (close("XLF") -close("XLF")[1])/close("XLF")[1]*XLF_FINANCIALS/100;
def XLC_PRnow = (close("XLC")-close("XLC")[1])/close("XLC")[1]*XLC_SERVICES/100;
def XLI_PRnow = (close("XLI")-close("XLI")[1])/close("XLI")[1]*XLI_INDUSTRIALS/100;
def XLP_PRnow = (close("XLP")-close("XLP")[1])/close("XLP")[1]*XLP_STAPLES/100;
def XLE_PRnow = (close("XLE")-close("XLE")[1])/close("XLE")[1]*XLE_ENERGY/100;
def XLU_PRnow = (close("XLU")-close("XLU")[1])/close("XLU")[1]*XLU_UTILITIES/100;
def XLRE_PRnow = (close("XLRE")-close("XLRE")[1])/close("XLRE")[1]*XLRE_RESTATE/100;
def XLB_PRnow = (close("XLB")-close("XLB")[1])/close("XLB")[1]*XLB_MATERIALS/100;

DEF CAD = XLK_PRnow + XLV_PRnow + XLY_PRnow + XLF_PRnow + XLC_PRnow + XLI_PRnow + XLP_PRnow + XLE_PRnow + XLU_PRnow + XLRE_PRnow + XLB_PRnow ;

Def Divider = 6.5*60/getAggregationPeriod()*200*500;

def notFirstBar = if SecondsFromTime(open_Time) >= 0 and SecondsFromTime(open_Time)[1] >= 0 then 1 else 0;

Def X = if getAggregationPeriod()== AggregationPeriod.MIN then 70000 else if getAggregationPeriod() == AggregationPeriod.TWO_MIN then 60000 else if getAggregationPeriod() == aggregationPeriod.THREE_MIN then 55000 else if getAggregationPeriod() == aggregationPeriod.FOUR_MIN then 50000 else if getAggregationPeriod() == aggregationPeriod.FIVE_MIN then 45000 else if getAggregationPeriod() == aggregationPeriod.TEN_MIN then 37500
else if getAggregationPeriod() == aggregationPeriod.FIFTEEN_MIN then 35000 else if getAggregationPeriod() == aggregationPeriod.THIRTY_MIN then 32500 else if getAggregationPeriod() == aggregationPeriod.HOUR then 27500 else double.nan;

DEF CAD2 = 11* (XLK_PRnow/XLK_TECH + XLV_PRnow/XLV_HEALTH + XLY_PRnow/XLY_DISCRETIONARY + XLF_PRnow/XLF_FINANCIALS + XLC_PRnow/XLC_SERVICES + XLI_PRnow/XLI_INDUSTRIALS + XLP_PRnow/XLP_STAPLES + XLE_PRnow/XLE_ENERGY + XLU_PRnow/XLU_UTILITIES + XLRE_PRnow/XLRE_RESTATE + XLB_PRnow/XLB_MATERIALS);

def CT2 = if GetDay() != GetDay()[1] then 0 else if notFirstBar then CT2[1] + CAD2 else 0;
plot Non_Weighted_AD = if !IsNaN(CAD2) then CT2*X
else Double.NaN;

def CT = if GetDay() != GetDay()[1] then 0 else if notFirstBar then CT[1] + CAD else 0;
plot Weighted_AD = if !IsNaN(CAD) then CT*X else Double.NaN;

plot zero = 0;
zero.SetDefaultColor(Color.WHITE);
zero.HideBubble();
zero.HideTitle();
Weighted_AD.DefineColor(“Positive”, Color.MAGENTA);
Weighted_AD.DefineColor(“Negative”, Color.ORANGE);
Weighted_AD.AssignValueColor(if Weighted_AD >= Weighted_AD [1] then Weighted_AD.Color(“Positive”) else Weighted_AD.Color(“Negative”));
 

Attachments

  • Screenshot 2023-06-09 at 10.28.11 AM.png
    Screenshot 2023-06-09 at 10.28.11 AM.png
    480.6 KB · Views: 163

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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