• Get $40 off VIP by signing up for a free account! Sign Up

*Need Help* Adding prices for major indices

ERHorner

New member
I'm looking for assistance with adding AddLabel for each of the following: "spx", "djx", "ndx", "hui", "xau", "rut", "vix", "tnx". I would like to have the most current prices listed and to have the color of the label change based on the previous day closing price for each (Green for uptrend and Red for downtrend. Thank you for your help!

Below is what I have created so far. I know it's not correct, but wanted to give it a try based on some of the other scripts I've looked at. I just know know how to add the current prices or how to add the correct formula.

declare lower;

input n = close;
input o = open;

input spx = open;
AddLabel (Yes, “spx “ + close, if(spx<=open) then Color.GREEN else Color.Red);
def spx_1 = spx;
addlabel(1, "spx : " + Round(spx_1,2) + (if spx then " RISING "
else if spx then " FALLING "
else " NEUTRAL"),
if spx then Color.GREEN else if spx then Color.PINK else Color.YELLOW);

input djx = open;
AddLabel (Yes, “djx “ + close, if(djx<=open) then Color.GREEN else Color.Red);
input ndx = open;
AddLabel (Yes, “ndx “ + close, if(ndx<=open) then Color.GREEN else Color.Red);
input hui = open;
AddLabel (Yes, “hui “ + close, if(hui<=open) then Color.GREEN else Color.Red);
input xau = open;
AddLabel (Yes, “xau “ + close, if(xau<=open) then Color.GREEN else Color.Red);
input rut = open;
AddLabel (Yes, “rut “ + close, if(rut<=open) then Color.GREEN else Color.Red);
input vix = open;
AddLabel (Yes, “vix “ + close, if(vix<=open) then Color.GREEN else Color.Red);
input tnx = open;
AddLabel (Yes, “tnx “ + close, if(tnx<=open) then Color.GREEN else Color.Red);
 
Last edited:
@ERHorner No need for it to be that complicated... Just replicate the following code for each symbol... It displays last price and trend all-in-one...

Ruby:
AddLabel(yes, "SPY: " + close(symbol = "SPY"), if close(symbol = "SPY") > close(symbol = "SPY")[1] then Color.GREEN else Color.RED);
 

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

@rad14733, That was exactly what I was looking for. Thank you for the help. I will paste a copy of what I added in case anyone else would like to use it.

declare lower;
AddLabel(yes, "S&P: " + close(symbol = "SPX"), if close(symbol = "SPX") > close(symbol = "SPX")[1] then Color.GREEN else Color.RED);
AddLabel(yes, "Dow Jones: " + close(symbol = "DJX"), if close(symbol = "DJX") > close(symbol = "DJX")[1] then Color.GREEN else Color.RED);
AddLabel(yes, "Nasdaq: " + close(symbol = "NDX"), if close(symbol = "NDX") > close(symbol = "NDX")[1] then Color.GREEN else Color.RED);
AddLabel(yes, "Gold: " + close(symbol = "HUI"), if close(symbol = "HUI") > close(symbol = "HUI")[1] then Color.GREEN else Color.RED);
AddLabel(yes, "Gold & Silver: " + close(symbol = "XAU"), if close(symbol = "XAU") > close(symbol = "XAU")[1] then Color.GREEN else Color.RED);
AddLabel(yes, "Russell2000: " + close(symbol = "RUT"), if close(symbol = "RUT") > close(symbol = "RUT")[1] then Color.GREEN else Color.RED);
AddLabel(yes, "VIX: " + close(symbol = "VIX"), if close(symbol = "VIX") > close(symbol = "VIX")[1] then Color.GREEN else Color.RED);
AddLabel(yes, "10 YR T-Note: " + close(symbol = "TNX"), if close(symbol = "TNX") > close(symbol = "TNX")[1] then Color.GREEN else Color.RED);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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