Stock percentage

lguides

New member
Hello, scripters out there! I need help with this indicator below its shows me nothing but black with N/A any help is much appreciated

declare upper;

def a1 = open("AAPL");
def a2 = close("AAPL");

def m1 = open("MSFT");
def m2 = close("MSFT");

def am1 = open("AMZN");
def am2 = close("AMZN");

def f1 = open("FB");
def f2 = close("FB");

def g1 = open("GOOGL");
def g2 = close("GOOGL");

def go1 = open("GOOG");
def go2 = close("GOOG");

def pppp1 = a1 + m1 + am1 + f1 + g1 + go1;
def pppp2 = a2 + m2 + am2 + f2 + g2 + go2;

def pppp3 = pppp1 / pppp2;

AddLabel(yes, "%Chg: " + round(pppp3,2)+"%", if pppp3 > 1 then color.green else if pppp3 < -1 then color.red else color.yellow);
 
Solution
Hello, scripters out there! I need help with this indicator below its shows me nothing but black with N/A any help is much appreciated

declare upper;

def a1 = open("AAPL");
def a2 = close("AAPL");

def m1 = open("MSFT");
def m2 = close("MSFT");

def am1 = open("AMZN");
def am2 = close("AMZN");

def f1 = open("FB");
def f2 = close("FB");

def g1 = open("GOOGL");
def g2 = close("GOOGL");

def go1 = open("GOOG");
def go2 = close("GOOG");

def pppp1 = a1 + m1 + am1 + f1 + g1 + go1;
def pppp2 = a2 + m2 + am2 + f2 + g2 + go2;

def pppp3 = pppp1 / pppp2;

AddLabel(yes, "%Chg: " + round(pppp3,2)+"%", if pppp3 > 1 then color.green else if pppp3 < -1 then color.red else color.yellow);

Modify
def f1 = open("FB");
def f2 = close("FB")...
Hello, scripters out there! I need help with this indicator below its shows me nothing but black with N/A any help is much appreciated

declare upper;

def a1 = open("AAPL");
def a2 = close("AAPL");

def m1 = open("MSFT");
def m2 = close("MSFT");

def am1 = open("AMZN");
def am2 = close("AMZN");

def f1 = open("FB");
def f2 = close("FB");

def g1 = open("GOOGL");
def g2 = close("GOOGL");

def go1 = open("GOOG");
def go2 = close("GOOG");

def pppp1 = a1 + m1 + am1 + f1 + g1 + go1;
def pppp2 = a2 + m2 + am2 + f2 + g2 + go2;

def pppp3 = pppp1 / pppp2;

AddLabel(yes, "%Chg: " + round(pppp3,2)+"%", if pppp3 > 1 then color.green else if pppp3 < -1 then color.red else color.yellow);

Modify
def f1 = open("FB");
def f2 = close("FB");
to
def f1 = open("META");
def f2 = close("META");
 
Solution
Hello, scripters out there! I need help with this indicator below its shows me nothing but black with N/A any help is much appreciated

declare upper;

def a1 = open("AAPL");
def a2 = close("AAPL");

def m1 = open("MSFT");
def m2 = close("MSFT");

def am1 = open("AMZN");
def am2 = close("AMZN");

def f1 = open("FB");
def f2 = close("FB");

def g1 = open("GOOGL");
def g2 = close("GOOGL");

def go1 = open("GOOG");
def go2 = close("GOOG");

def pppp1 = a1 + m1 + am1 + f1 + g1 + go1;
def pppp2 = a2 + m2 + am2 + f2 + g2 + go2;

def pppp3 = pppp1 / pppp2;

AddLabel(yes, "%Chg: " + round(pppp3,2)+"%", if pppp3 > 1 then color.green else if pppp3 < -1 then color.red else color.yellow);

EDIT - sleepyz has the answer in post 2

i came across something similar to this recently , where it was one of the stocks that didn't trade on a candle when the others did,...
but that doesn't seem to be the case with these stocks ( with after hours off)

if after hours are on, then you may have to do something like i mention below

----------------------------
labels show data from the last candle traded. my guess, 1 or more stocks did not have a trade on a candle when others did, resulting in a n/a price, resulting in n/a formula values.

could add a formula for each price formula,
if an error, use the previous value.

def a1 = if isnan(open("AAPL")) then a1[1] else open("AAPL");


you could verify the error, by adding a bubble to the end of your code,

Code:
addchartbubble( 1, low*0.999,
a1 + " a\n" +
m1 +  " m\n" +
am1 + " am\n" +
f1 +  " f\n" +
g1 +  " g\n" +
go1 + " go"
, color.yellow, no);
 
Last edited:
Thanks men! I tried it but it doesn't work, still stuck on black label with N/A
Worked for me
Capture.jpg
 
Yes it work but it's stay on 1 the whole day still something wrong

If you are using a Daily chart, I am assuming that you want the percent change from the open.

Capture.jpg
Ruby:
declare upper;

def a1 = open("AAPL");
def a2 = close("AAPL");

def m1 = open("MSFT");
def m2 = close("MSFT");

def am1 = open("AMZN");
def am2 = close("AMZN");

def f1 = open("META");
def f2 = close("META");

def g1 = open("GOOGL");
def g2 = close("GOOGL");

def go1 = open("GOOG");
def go2 = close("GOOG");

def pppp1 = a1 + m1 + am1 + f1 + g1 + go1;
def pppp2 = a2 + m2 + am2 + f2 + g2 + go2;

def pppp3 =  100 * (pppp2 / pppp1 - 1);


AddLabel(yes, "%Chg from Open: " + Round(pppp3) + "%", if pppp3 > 1 then Color.GREEN else if pppp3 < -1 then Color.RED else Color.YELLOW);
 
Click the Click to expand in post #7 and you will see the code
def pppp3 = 100 * (pppp2 / pppp1 - 1); #can you please tell me what is the use of this formula and why is it "-1" I am checking the result but unfortunately I have still doubt on what we have because nasdaq is above 1% why we are getting -0.3 or something, it should be 1% up too.
 
If you are using a Daily chart, I am assuming that you want the percent change from the open.

I do not know where you are getting the nasdaq % and what timeframe chart you are using to view the -0.3.

The image below is a Daily chart that I chose one of the symbols in your code to use. The white label is the Daily values for open and the light_gray is the Daily closes. The yellow is 1.0068 equal to pppp2/pppp1 (909.68/903.50). The subtract of 1 removes the 1 in 1.0068 and the 100 results in .68 to present the percentage.

If you are not using a Daily timeframe chart, then the values for open and close will be the current bars open and close, not open and close for the Day. You can add an Daily aggregation period timeframe to the open and close in your code to have it display those Daily values when using a lower timeframe chart.

Capture.jpg
 
I do not know where you are getting the nasdaq % and what timeframe chart you are using to view the -0.3.

The image below is a Daily chart that I chose one of the symbols in your code to use. The white label is the Daily values for open and the light_gray is the Daily closes. The yellow is 1.0068 equal to pppp2/pppp1 (909.68/903.50). The subtract of 1 removes the 1 in 1.0068 and the 100 results in .68 to present the percentage.

If you are not using a Daily timeframe chart, then the values for open and close will be the current bars open and close, not open and close for the Day. You can add an Daily aggregation period timeframe to the open and close in your code to have it display those Daily values when using a lower timeframe chart.

Capture.jpg
Hello Sleepyz! I'm sorry but I didn't see the picture you mean.
 

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
468 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