Background Color for Watchlist

bobbyaxelrod

New member
Hi, I'm having trouble getting background colors to show for a particular script. Right now the background doesn't change color at all, it stays black, though the calculation of the script for "ADR" does work. The full script is below. Any suggestions are much appreciated. Thanks!

#Hint: Average Daily Range

def len = 1;
def price = close;

def dayHigh = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyHigh;
def dayLow = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyLow;

def ADR = (price - dayLow) / (dayHigh - dayLow)*100;
AddLabel(yes,Round(ADR,0)+"%");

AssignBackgroundColor (if ADR>.80 then Color.GREEN else if ADR>.60 then color.LIGHT_GREEN else if ADR>.40 then color.YELLOW else if ADR>.20 then color.PINK else color.RED);
 

Attachments

  • Screenshot 2023-07-07 at 1.19.37 PM.png
    Screenshot 2023-07-07 at 1.19.37 PM.png
    246.7 KB · Views: 194
Solution
Hi, I'm having trouble getting background colors to show for a particular script. Right now the background doesn't change color at all, it stays black, though the calculation of the script for "ADR" does work. The full script is below. Any suggestions are much appreciated. Thanks!

#Hint: Average Daily Range

def len = 1;
def price = close;

def dayHigh = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyHigh;
def dayLow = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyLow;

def ADR = (price - dayLow) / (dayHigh - dayLow)*100;
AddLabel(yes,Round(ADR,0)+"%");

AssignBackgroundColor (if ADR>.80 then Color.GREEN else if ADR>.60 then color.LIGHT_GREEN else if ADR>.40 then color.YELLOW else if ADR>.20 then color.PINK else...
Hi, I'm having trouble getting background colors to show for a particular script. Right now the background doesn't change color at all, it stays black, though the calculation of the script for "ADR" does work. The full script is below. Any suggestions are much appreciated. Thanks!

#Hint: Average Daily Range

def len = 1;
def price = close;

def dayHigh = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyHigh;
def dayLow = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyLow;

def ADR = (price - dayLow) / (dayHigh - dayLow)*100;
AddLabel(yes,Round(ADR,0)+"%");

AssignBackgroundColor (if ADR>.80 then Color.GREEN else if ADR>.60 then color.LIGHT_GREEN else if ADR>.40 then color.YELLOW else if ADR>.20 then color.PINK else color.RED);

how can you say the adr works, when most of the values are N/A ?

changed a few things. added notes in code. works now.
removed 2nd agg and set column to DAY.


Code:
def len = 1;
def price = close;

# 2nd agg causing issues
#def dayHigh = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyHigh;
#def dayLow = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyLow;
# change formulas.  set column to day
def dayHigh = High;
def dayLow = Low;

def ADR = (price - dayLow) / (dayHigh - dayLow)*100;
# no color, defaults to white , cant read it
#AddLabel(yes,Round(ADR,0)+"%");
# add black so can read the numbers
#AddLabel(yes,Round(ADR,0)+"%", color.black);
# add leading 0 for small numbers, so the text can be sorted in column
AddLabel(yes,
(if adr < 10 then "0" else "") + Round(ADR,0)+"%"
, color.black);

# numbers too small, every cell is green
#AssignBackgroundColor (if ADR>.80 then Color.GREEN else if ADR>.60 then color.LIGHT_GREEN else if ADR>.40 then color.YELLOW else if ADR>.20 then color.PINK else color.RED);

# chg numbers
AssignBackgroundColor (if ADR>80 then Color.GREEN else if ADR>60 then color.LIGHT_GREEN else if ADR>40 then color.YELLOW else if ADR>20 then color.PINK else color.RED);
#
 
Solution

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

Hi @halcyonguy, thank you so much for the help!
I just updated TOS with the new code that you provided and it works perfectly! Interesting that you had a bunch of values show as N/A, as I was able to get that original code that I wrote to do the calculations on my TOS, but not show the background colors due to the errors that you helped correct. Either way, everything is working perfectly with the new and better code that you provided. Also, I really appreciate you providing the #explanations of what you changed and why you changed it, that is very helpful for improving my knowledge of coding on TOS. Thanks again for your help and have a great day!
 
Last edited by a moderator:
Also, I really appreciate you providing the #explanations of what you changed and why you changed it, that is very helpful for improving my knowledge of coding on TOS. Thanks again for your help and have a great day!

there are comments to the code.
here are a couple more comments

your are trying to plot ADR numbers, but many values are N/A
you are using the same ADR in formula to decide a color.
i know that variables with N/A's cause a black color when used in a bubble color formula.

AssignBackgroundColor (if ADR>80 then Color.GREEN else if ADR>60 then color.LIGHT_GREEN else if ADR>40 then color.YELLOW else if ADR>20 then color.PINK 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
427 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