Need help with labels-

METAL

Active member
Plus
I created a set of labels that I want to show Red when1m candle is red and green when 1min candle is green.
What I made isn't working properly so any help will be greatly appreciated. For some odd reason all of the labels turn at the same time even when one of the others is different. I am not sure if this is showing the one minute TF.
Code:
# Candle Color Indicator

declare upper;

# Calculate candle color
def isGreen = close > open;
def isRed = close < open;

# Plot labels
AddLabel(isGreen, "AAPL: " + close("$AAPL"), Color.GREEN);
AddLabel(isRed, "AAPL: " + close("$AAPL"), Color.RED);
AddLabel(isGreen, "QQQ: " + close, Color.GREEN);
AddLabel(isRed, "QQQ: " + close, Color.RED);
AddLabel(isGreen, "$ADD: " + close("$ADD"), Color.GREEN);
AddLabel(isRed, "$ADD: " + close("$ADD"), Color.RED);
 
I created a set of labels that I want to show Red when1m candle is red and green when 1min candle is green.
What I made isn't working properly so any help will be greatly appreciated. For some odd reason all of the labels turn at the same time even when one of the others is different. I am not sure if this is showing the one minute TF.
Code:
# Candle Color Indicator

declare upper;

# Calculate candle color
def isGreen = close > open;
def isRed = close < open;

# Plot labels
AddLabel(isGreen, "AAPL: " + close("$AAPL"), Color.GREEN);
AddLabel(isRed, "AAPL: " + close("$AAPL"), Color.RED);
AddLabel(isGreen, "QQQ: " + close, Color.GREEN);
AddLabel(isRed, "QQQ: " + close, Color.RED);
AddLabel(isGreen, "$ADD: " + close("$ADD"), Color.GREEN);
AddLabel(isRed, "$ADD: " + close("$ADD"), Color.RED);

By using isGreen and isRed, you were using the comparison for all of the labels based upon the chart's candles you were viewing. Also, the symbol for using $AAPL was corrected to AAPL.

The following should work how you expected.

Code:
# Candle Color Indicator

declare upper;

# Calculate candle color
#def isGreen = close > open;
#def isRed = close < open;

# Plot labels
AddLabel(close("AAPL") > open("AAPL"), "AAPL: " + close("AAPL"), Color.GREEN);
AddLabel(close("AAPL") < open("AAPL"), "AAPL: " + close("AAPL"), Color.RED);
AddLabel(close("QQQ") > open("QQQ"), "QQQ: " + close("QQQ"), Color.GREEN);
AddLabel(close("QQQ") < open("QQQ"), "QQQ: " + close("QQQ"), Color.RED);
AddLabel(close("$ADD") > open("$ADD"), "$ADD: " + close("$ADD"), Color.GREEN);
AddLabel(close("$ADD") < open("$ADD"), "$ADD: " + close("$ADD"), Color.RED);
 

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

By using isGreen and isRed, you were using the comparison for all of the labels based upon the chart's candles you were viewing. Also, the symbol for using $AAPL was corrected to AAPL.

The following should work how you expected.
Hi SleepyZ, can we do this for any symbol? I used getsymbol() instead of ""AAPL" it did not produce any label. Thanks for your help.
 
Hi SleepyZ, can we do this for any symbol? I used getsymbol() instead of ""AAPL" it did not produce any label. Thanks for your help.

See if this helps

Screenshot 2023-06-23 095234.png

#Label Shown for the Symbol on the Chart being Viewed using Getsymbol(),based upon the Chart's Settings

AddLabel(close(GetSymbol()) >= open(GetSymbol()), GetSymbol() + ": " + close(GetSymbol()), Color.GREEN);
AddLabel(close(GetSymbol()) < open(GetSymbol()), GetSymbol() + ": " + close(GetSymbol()), Color.RED);

#Label Shown for a Symbol Input @Sym on Any Chart, based upon the Settings of the Chart being viewed

input sym = "DAL";
AddLabel(close(sym) >= open(sym), sym + ": " + close(sym), Color.GREEN);
AddLabel(close(sym) < open(sym), sym + ": " + close(sym), Color.RED);
 
This should be what you're looking for.



declare lower;

input TICKER1 = "aapl";
input TICKER2 = "bac";
input TICKER3 = "ebay";
input TICKER4 = "nvda";
input TICKER5 = "t";
input TICKER6 = "qqq";

def price1 = close(TICKER1);
def netchg1 = round(price1 - price1[1], 2);
def PChange1 = ((price1 - price1[1]) / price1[1]);
def lastPrice1 = close(TICKER1);

def price2 = close(TICKER2);
def netchg2 = round(price2 - price2[1], 2);
def PChange2 = ((price2 - price2[1]) / price2[1]);
def lastPrice2 = close(TICKER2);

def price3 = close(TICKER3);
def netchg3 = round(price3 - price3[1], 2);
def PChange3 = ((price3 - price3[1]) / price3[1]);
def lastPrice3 = close(TICKER3);

def price4 = close(TICKER4);
def netchg4 = round(price4 - price4[1], 2);
def PChange4 = ((price4 - price4[1]) / price4[1]);
def lastPrice4 = close(TICKER4);

def price5 = close(TICKER5);
def netchg5 = round(price5 - price5[1], 2);
def PChange5 = ((price5 - price5[1]) / price5[1]);
def lastPrice5 = close(TICKER5);

def price6 = close(TICKER6);
def netchg6 = round(price6 - price6[1], 2);
def PChange6 = ((price6 - price6[1]) / price6[1]);
def lastPrice6 = close(TICKER6);

# Additional calculations for other ticker symbols can be added here

# Create labels indicating change direction with ticker symbol and last price
AddLabel(PChange1 >= 0, TICKER1 + " Up - Last Price: " + lastPrice1, Color.GREEN);
AddLabel(PChange1 < 0, TICKER1 + " Down - Last Price: " + lastPrice1, Color.RED);

AddLabel(PChange2 >= 0, TICKER2 + " Up - Last Price: " + lastPrice2, Color.GREEN);
AddLabel(PChange2 < 0, TICKER2 + " Down - Last Price: " + lastPrice2, Color.RED);

AddLabel(PChange3 >= 0, TICKER3 + " Up - Last Price: " + lastPrice3, Color.GREEN);
AddLabel(PChange3 < 0, TICKER3 + " Down - Last Price: " + lastPrice3, Color.RED);

AddLabel(PChange4 >= 0, TICKER4 + " Up - Last Price: " + lastPrice4, Color.GREEN);
AddLabel(PChange4 < 0, TICKER4 + " Down - Last Price: " + lastPrice4, Color.RED);

AddLabel(PChange5 >= 0, TICKER5 + " Up - Last Price: " + lastPrice5, Color.GREEN);
AddLabel(PChange5 < 0, TICKER5 + " Down - Last Price: " + lastPrice5, Color.RED);

AddLabel(PChange6 >= 0, TICKER6 + " Up - Last Price: " + lastPrice6, Color.GREEN);
AddLabel(PChange6 < 0, TICKER6 + " Down - Last Price: " + lastPrice6, Color.RED);

The code I posted will match a bar chart not Candlestick it's too much work to code for open close high low . it should work keep in mind I haven't tested it it is in the after hours
 
By using isGreen and isRed, you were using the comparison for all of the labels based upon the chart's candles you were viewing. Also, the symbol for using $AAPL was corrected to AAPL.

The following should work how you expected.
SleepyZ, Thank you for the above fix. It works but the labels flash on and off. Is there a way to make the labels be static?
 
SleepyZ, Thank you for the above fix. It works but the labels flash on and off. Is there a way to make the labels be static?

This should help by combining the coloring condition into one label and setting the label to always appear.

Edited code to add standard dollars and/or rounding. Note that a label may not appear if there is not a corresponding bar on the labels and the chart you are viewing. This particularly appears to happen with $ADD
Code:
# Calculate candle color
#def isGreen = close > open;
#def isRed = close < open;

# Plot labels
AddLabel(1, "AAPL: " + asdollars(close("AAPL")), if close("AAPL") <= open("AAPL") then color.red else Color.GREEN);
#AddLabel(close("AAPL") < open("AAPL"), "AAPL: " + close("AAPL"), Color.RED);
AddLabel(1, "QQQ: " + asdollars(close("QQQ")), if close("QQQ") <= open("QQQ") then color.red else Color.GREEN);
#AddLabel(close("QQQ") < open("QQQ"), "QQQ: " + close("QQQ"), Color.RED);
AddLabel(1, "$ADD: " + round(close("$ADD"),0), if close("$ADD") <= open("$ADD") then color.red else Color.GREEN);
#AddLabel(close("$ADD") < open("$ADD"), "$ADD: " + close("$ADD"), Color.RED);
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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