Need Help with Background Color

TwoWayTrader

New member
Hey all!

I need help creating specific background color for different tiers of percentages for my Watchlist column:

50% + = violet
30% - 50% = cyan
0% - 30% = light green
0% = black
Less than 0% = grey

Here's the code I have so far ...Thank you!!

Code:
def chng = round((close / close[1] -1),2);

addlabel(yes, asPercent(chng));

assignBackgroundColor(if chng > 0 then color.BLUE else if chng < 0 then  color.GrAY else color.CuRRENT);


#end
 

mashume

Well-known member
VIP
Lifetime
Perhaps this will help you get where you want to be...

Code:
def chng = round((close / close[1] -1),2);

addlabel(yes, asPercent(chng));

plot CHANGE = chng;

assignBackgroundColor(
    if chng >= 0.5 then COLOR.violet
    else if chng >= 0.3 then COLOR.cyan
         else if chng > 0 then COLOR.LIGHT_GREEN
              else COLOR.GRAY);

Happy Trading

-mashume
 

Playstation

Active member
VIP
hi @mashume could you help give me a direction below?
i want chart background colors to change per my rules:
So long as current price's close is above 180 WMA, background will turn color green, or
So long as current price's close is above 180 WMA, background will turn color red.
 

mashume

Well-known member
VIP
Lifetime
hi @mashume could you help give me a direction below?
i want chart background colors to change per my rules:
So long as current price's close is above 180 WMA, background will turn color green, or
So long as current price's close is above 180 WMA, background will turn color red.

As far as I know, you can't dynamically alter the actual background colors. You can add a label in the upper left of the chart window that is colored as you wish.

Code:
declare upper;

def wma = plot WildersAvg = WildersAverage(close, 180);
AddLabel(yes, if close > wma then "Above" else "Below", if close > wma then color.green else color.red);
This code should be close, but I closed thinkorswim for the long weekend. may open it up sunday, but this is just from my head (untested). You may have to tweak it a bit.

Have fun trading

-mashume
 

Playstation

Active member
VIP
declare upper;

input price = close;
input length = 180;
input displace = 0;

plot AvgWtd = wma(price, length)[-displace];
AvgWtd.SetDefaultColor(GetColor(1));
AvgWtd.SetLineWeight(3);

assignBackgroundColor(if close > AvgWtd then COLOR.DARK_GREEN else COLOR.DARK_RED);

thanks @mashume I did it! (although the charts now look really ugly hahahahaha)
 
Last edited:

Playstation

Active member
VIP
Actually the logic behind this request is actually very simple. I learnt this piece of knowledge on FX factory forum given by an extremely profitable trader.

1. Draw a line.
2. Price will either be above or below this line 95% of the time.

This request of background change is a reminder to myself, sometimes i do forget these 2 points.
 

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.
Top