Label Text and Color question

poutses

New member
Hello, I'm trying to add a label that dynamically changes its text and color depending on a condition being met. My code below:

Code:
#EMA3vsEMA9
#Checks if the previous day's closing EMA3 is higher or lower than the previous days closing EMA9

input MA_1_length = 3; #exponential
input MA_2_length = 9; #exponential

input MA_1_closeType = ohlc4;
input MA_2_closeType = ohlc4;

AddLabel(yes, if MA_1_closeType > MA_2_closeType then "HIGHER" else "LOWER");

Essentially I have this working to the point where it displays HIGHER or LOWER. What I want it to do is if MA_1_closeType > MA_2_closeType then display HIGHER and color the label green, and if it MA_1_closeType < MA_2_closeType then display LOWER and color the label red.

Thank you for your help.
 
Solution
Hello, I'm trying to add a label that dynamically changes its text and color depending on a condition being met. My code below:

Code:
#EMA3vsEMA9
#Checks if the previous day's closing EMA3 is higher or lower than the previous days closing EMA9

input MA_1_length = 3; #exponential
input MA_2_length = 9; #exponential

input MA_1_closeType = ohlc4;
input MA_2_closeType = ohlc4;

AddLabel(yes, if MA_1_closeType > MA_2_closeType then "HIGHER" else "LOWER");

Essentially I have this working to the point where it displays HIGHER or LOWER. What I want it to do is if MA_1_closeType > MA_2_closeType then display HIGHER and color the label green, and if it MA_1_closeType < MA_2_closeType then display LOWER and color the label red.

Thank...
Hello, I'm trying to add a label that dynamically changes its text and color depending on a condition being met. My code below:

Code:
#EMA3vsEMA9
#Checks if the previous day's closing EMA3 is higher or lower than the previous days closing EMA9

input MA_1_length = 3; #exponential
input MA_2_length = 9; #exponential

input MA_1_closeType = ohlc4;
input MA_2_closeType = ohlc4;

AddLabel(yes, if MA_1_closeType > MA_2_closeType then "HIGHER" else "LOWER");

Essentially I have this working to the point where it displays HIGHER or LOWER. What I want it to do is if MA_1_closeType > MA_2_closeType then display HIGHER and color the label green, and if it MA_1_closeType < MA_2_closeType then display LOWER and color the label red.

Thank you for your help.

Try this

Code:
AddLabel(yes, if MA_1_closeType > MA_2_closeType then "HIGHER" else "LOWER", if MA_1_closeType > MA_2_closeType then color.green else color.red);
 
Solution

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

Try this

Code:
AddLabel(yes, if MA_1_closeType > MA_2_closeType then "HIGHER" else "LOWER", if MA_1_closeType > MA_2_closeType then color.green else color.red);
Ahhh, I was going down this route but was putting the colors after the string value, which is why it wasn't working for me. Thank you!
 
Thread starter Similar threads Forum Replies Date
P Change text size for Label Questions 2
B Chart Label Text formating Questions 1
evanevans Add text label to horizontal lines? Questions 32
B Need RVOL Label Questions 0
M Help with this label Questions 2

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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