Label that shows SPY DIA QQQ and their % difference from yesterday?

rmmorgan

New member
Hello, I made 3 labels to have the SPY DIA and QQQ on top of my charts, which is really helpful for me, but I was wondering if there's way to have the % difference from yesterday for each of those in the same label or in another one right next to it. Any help would be immensely appreciated.
 

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

Post what you have and then we can help you add on top of it.
Extremely simple, this is just the only thing that I have:

Code:
def SPY = Close ("SPY");
def QQQ = Close ("QQQ");
def DJI = Close("DIA");
AddLabel(Yes,"SPY: " + SPY, Color.Blue);
AddLabel(Yes,"QQQ: " + QQQ, Color.Blue);
AddLabel(Yes,"DJI: " + DJI, Color.Blue);

So it would be great just to have the % change from yesterday for each of those. Really new into coding so I have no idea on how to do this. I have been reading a lot trying to figure out, but I've only been able to find ways to display the % difference for the ticker of the chart that's showing.

TIA!
 
the current price compared to the close from the previous day would be what would help me out the most

I came up with this. I tested it in OnDeMand, since today's a Saturday, and it at least shows percentages. I have not double-checked for accuracy. Hope it fits your use case (or, the use case of the next person that stumbles upon this thread)

Note: I included the aggregation period because the comparison might break down at lower time frames (imagine looking at a 5-minute chart, when you want to know how well SPY did since yesterday, not since 5 minutes ago). Of course, adding the aggregation period then means this label won't do you any good on weekly or monthly charts.

Code:
# Label that shows SPY DIA QQQ and their % difference from yesterday?
# by tradecombine - 2021-10-02
# requested by rmmorgan @ usethinkscript
# Thread: https://usethinkscript.com/threads/label-that-shows-spy-dia-qqq-and-their-difference-from-yesterday.4862/
#
#

def SPY = close("SPY", period = AggregationPeriod.DAY);
def QQQ = close("QQQ", period = AggregationPeriod.DAY);
def DIA = close("DIA", period = AggregationPeriod.DAY);

AddLabel(yes, "SPY: " + SPY + " | " + AsPercent((SPY - SPY[1])/SPY[1]), Color.BLUE);
AddLabel(yes, "QQQ: " + QQQ + " | " + AsPercent((QQQ - QQQ[1])/QQQ[1]), Color.BLUE);
AddLabel(yes, "DIA: " + DIA + " | " + AsPercent((DIA - DIA[1])/DIA[1]), Color.BLUE);


Some references:
https://tlc.thinkorswim.com/center/...hapter-11---Referencing-Secondary-Aggregation
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/AsPercent
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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