Sector Labels Percent change from Previous Day's Close

tradegoals23

New member
Hello all, I have a sector comparison chart I am using to determine leading sectors that day. I am writing to see if anyone can help me code this to reflect add Percent change from previous day's close to current value of the labels at the top right of the charte.. I would like to keep the current price and add the % changed to the label. For example: "VGT: 602.16 3.5%". Additionally, I would like a label bubble on the comparison item for easy reference when looking at the line chart.

Currently my code is as follows and only shows current value and I am using with comparison study. I have added images as well.

def VGT = Close ("VGT");
def XLF = Close ("XLF");
def XLV = Close("XLV");
def XLY = Close ("XLY");
def XLC = Close ("XLC");
def XLI = Close("XLI");
def XLP = Close ("XLP");
def XLE = Close ("XLE");
def XLU = Close("XLU");
def XLB = Close ("XLB");
def VNQ = Close ("VNQ");
AddLabel(Yes,"VGT: " + VGT, Color.Plum);
AddLabel(Yes,"XLF: " + XLF, Color.Cyan);
AddLabel(Yes,"XLV: " + XLV, Color.Magenta);
AddLabel(Yes,"XLY: " + XLY, Color.Violet);
AddLabel(Yes,"XLC: " + XLC, Color.Yellow);
AddLabel(Yes,"XLI: " + XLI, Color.Light_red);
AddLabel(Yes,"XLP: " + XLP, Color.Light_green);
AddLabel(Yes,"XLE: " + XLE, Color.Gray);
AddLabel(Yes,"XLU: " + XLU, Color.White);
AddLabel(Yes,"XLB: " + XLB, Color.Blue);
AddLabel(Yes,"VNQ: " + VNQ, Color.Pink);

I am not a coder so it's been difficult to learn via snippets of other codes. So please keep this in mind and forgive me if I am missing some information. Thank you a ton in advance.
 

Attachments

  • Screenshot 2024-10-27 094312.png
    Screenshot 2024-10-27 094312.png
    349.6 KB · Views: 27
  • Screenshot 2024-10-27 094253.png
    Screenshot 2024-10-27 094253.png
    85.7 KB · Views: 26
  • Screenshot 2024-10-27 094242.png
    Screenshot 2024-10-27 094242.png
    100.1 KB · Views: 27
Solution
Hello all, I have a sector comparison chart I am using to determine leading sectors that day. I am writing to see if anyone can help me code this to reflect add Percent change from previous day's close to current value of the labels at the top right of the charte.. I would like to keep the current price and add the % changed to the label. For example: "VGT: 602.16 3.5%". Additionally, I would like a label bubble on the comparison item for easy reference when looking at the line chart.

Currently my code is as follows and only shows current value and I am using with comparison study. I have added images as well.

def VGT = Close ("VGT");
def XLF = Close ("XLF");
def XLV = Close("XLV");
def XLY = Close ("XLY");
def XLC = Close...
Hello all, I have a sector comparison chart I am using to determine leading sectors that day. I am writing to see if anyone can help me code this to reflect add Percent change from previous day's close to current value of the labels at the top right of the charte.. I would like to keep the current price and add the % changed to the label. For example: "VGT: 602.16 3.5%". Additionally, I would like a label bubble on the comparison item for easy reference when looking at the line chart.

Currently my code is as follows and only shows current value and I am using with comparison study. I have added images as well.

def VGT = Close ("VGT");
def XLF = Close ("XLF");
def XLV = Close("XLV");
def XLY = Close ("XLY");
def XLC = Close ("XLC");
def XLI = Close("XLI");
def XLP = Close ("XLP");
def XLE = Close ("XLE");
def XLU = Close("XLU");
def XLB = Close ("XLB");
def VNQ = Close ("VNQ");
AddLabel(Yes,"VGT: " + VGT, Color.Plum);
AddLabel(Yes,"XLF: " + XLF, Color.Cyan);
AddLabel(Yes,"XLV: " + XLV, Color.Magenta);
AddLabel(Yes,"XLY: " + XLY, Color.Violet);
AddLabel(Yes,"XLC: " + XLC, Color.Yellow);
AddLabel(Yes,"XLI: " + XLI, Color.Light_red);
AddLabel(Yes,"XLP: " + XLP, Color.Light_green);
AddLabel(Yes,"XLE: " + XLE, Color.Gray);
AddLabel(Yes,"XLU: " + XLU, Color.White);
AddLabel(Yes,"XLB: " + XLB, Color.Blue);
AddLabel(Yes,"VNQ: " + VNQ, Color.Pink);

I am not a coder so it's been difficult to learn via snippets of other codes. So please keep this in mind and forgive me if I am missing some information. Thank you a ton in advance.

this compares current price to yesterdays closing price and displays a % change

Code:
#sectors_per_chg2
#https://usethinkscript.com/threads/sector-labels-percent-change-from-previous-days-close.19896/
#Sector Labels Percent change from Previous Day's Close

def na = double.nan;
def bn = barnumber();
def d = getday();
def newday = d != d[1];

def VGT = Close("VGT");
def XLF = Close("XLF");
def XLV = Close("XLV");
def XLY = Close("XLY");
def XLC = Close("XLC");
def XLI = Close("XLI");
def XLP = Close("XLP");
def XLE = Close("XLE");
def XLU = Close("XLU");
def XLB = Close("XLB");
def VNQ = Close("VNQ");

def vgtpr = if newday then vgt[1] else vgtpr[1];
def vgtper = round(100*(vgt - vgtpr)/vgtpr,2);
def xlfpr = if newday then xlf[1] else xlfpr[1];
def xlfper = round(100*(xlf - xlfpr)/xlfpr,2);
def XLVpr = if newday then XLV[1] else XLVpr[1];
def XLVper = round(100*(XLV - XLVpr)/XLVpr,2);
def XLYpr = if newday then XLY[1] else XLYpr[1];
def XLYper = round(100*(XLY - XLYpr)/XLYpr,2);
def XLCpr = if newday then XLC[1] else XLCpr[1];
def XLCper = round(100*(XLC - XLCpr)/XLCpr,2);
def XLIpr = if newday then XLI[1] else XLIpr[1];
def XLIper = round(100*(XLI - XLIpr)/XLIpr,2);
def XLPpr = if newday then XLP[1] else XLPpr[1];
def XLPper = round(100*(XLP - XLPpr)/XLPpr,2);
def XLEpr = if newday then XLE[1] else XLEpr[1];
def XLEper = round(100*(XLE - XLEpr)/XLEpr,2);
def XLUpr = if newday then XLU[1] else XLUpr[1];
def XLUper = round(100*(XLU - XLUpr)/XLUpr,2);
def XLBpr = if newday then XLB[1] else XLBpr[1];
def XLBper = round(100*(XLB - XLBpr)/XLBpr,2);
def VNQpr = if newday then VNQ[1] else VNQpr[1];
def VNQper = round(100*(VNQ - VNQpr)/VNQpr,2);

AddLabel(Yes,"VGT: " + VGT + "  " + vgtper + "%", Color.Plum);
AddLabel(Yes,"XLF: " + XLF + "  " + xlfper + "%", Color.Cyan);
AddLabel(Yes,"XLV: " + XLV + "  " + xlvper + "%", Color.Magenta);
AddLabel(Yes,"XLY: " + XLY + "  " + xlyper + "%", Color.Violet);
AddLabel(Yes,"XLC: " + XLC + "  " + xlcper + "%", Color.Yellow);
AddLabel(Yes,"XLI: " + XLI + "  " + xliper + "%", Color.Light_red);
AddLabel(Yes,"XLP: " + XLP + "  " + xlpper + "%", Color.Light_green);
AddLabel(Yes,"XLE: " + XLE + "  " + xleper + "%", Color.Gray);
AddLabel(Yes,"XLU: " + XLU + "  " + xluper + "%", Color.White);
AddLabel(Yes,"XLB: " + XLB + "  " + xlbper + "%", Color.Blue);
AddLabel(Yes,"VNQ: " + VNQ + "  " + vnqper + "%", Color.Pink);


# verify line 
# plot z1 = vgtpr;
#
 
Solution

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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