AAPL MSFT AMZN cumulative % change (from the open)

grapetux

Member
Im attempting to make a label that will calculate the sum of the percentage change (from the open) on
MSFT, AAPL, AMZN. While this is a crude tool it will be nice to have a cumulative look at the market change in terms of these big 3 tickers (which make up ~30% of QQQ

example - MSFT +1%, AAPL -1%, AMZN +2% -- Label will show a positive 2% reading on the day.

Thanks for the help
cheers
 
Solution
Here's a lower and an upper for you. These only work on time charts (no tick charts)

Code:
declare lower;

def aapl = close(symbol = "AAPL");
def msft = close(symbol = "MSFT");
def amzn = close(symbol = "AMZN");

# addLabel(yes, "   " + aapl + "     " + msft + "      " + amzn);

def day_open = if secondsFromTime(0930) == 0
#  and secondsFromTime(0930)[1] < 0 
then 1 else 0;

def aapl_open = if day_open == 1 then aapl else aapl_open[1];
def msft_open = if day_open == 1 then msft else msft_open[1];
def amzn_open = if day_open == 1 then amzn else amzn_open[1];

# addLabel(yes, "   " + aapl_open + "     " + msft_open + "      " + amzn_open);

def aapl_change = (aapl - aapl_open) / aapl_open;
def msft_change = (msft - msft_open) / msft_open...
Here's a lower and an upper for you. These only work on time charts (no tick charts)

Code:
declare lower;

def aapl = close(symbol = "AAPL");
def msft = close(symbol = "MSFT");
def amzn = close(symbol = "AMZN");

# addLabel(yes, "   " + aapl + "     " + msft + "      " + amzn);

def day_open = if secondsFromTime(0930) == 0
#  and secondsFromTime(0930)[1] < 0 
then 1 else 0;

def aapl_open = if day_open == 1 then aapl else aapl_open[1];
def msft_open = if day_open == 1 then msft else msft_open[1];
def amzn_open = if day_open == 1 then amzn else amzn_open[1];

# addLabel(yes, "   " + aapl_open + "     " + msft_open + "      " + amzn_open);

def aapl_change = (aapl - aapl_open) / aapl_open;
def msft_change = (msft - msft_open) / msft_open;
def amzn_change = (amzn - amzn_open) / amzn_open;

plot total_change = 
# if secondsFromTime(0930) >= 0 and secondsTillTime(1600) >= 0 then 
(aapl_change + msft_change + amzn_change) * 100
#  else double.nan
;

plot zero = 0;

AddLabel(yes, aspercent(total_change / 100), if total_change > 0 then color.green else if total_change < 0 then color.red else color.gray);

Code:
declare upper;

def aapl = close(symbol = "AAPL");
def msft = close(symbol = "MSFT");
def amzn = close(symbol = "AMZN");

def day_open = if secondsFromTime(0930) == 0 then 1 else 0;

def aapl_open = if day_open == 1 then aapl else aapl_open[1];
def msft_open = if day_open == 1 then msft else msft_open[1];
def amzn_open = if day_open == 1 then amzn else amzn_open[1];

def aapl_change = (aapl - aapl_open) / aapl_open;
def msft_change = (msft - msft_open) / msft_open;
def amzn_change = (amzn - amzn_open) / amzn_open;

def total_change = (aapl_change + msft_change + amzn_change);

AddLabel(yes, aspercent(total_change), if total_change > 0 then color.green else if total_change < 0 then color.red else color.gray);

the lower has some extra code in it for debugging that I removed from the cleaned up upper.

Happy Trading,
-mashume
 
Solution

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
418 Online
Create Post

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