*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:

rad14733

Well-known member
VIP
@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);
 

ERHorner

New member
@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

Top