Need Help with Background Color

T

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
 
M

mashume

Active member
VIP
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
 
P

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

mashume

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.

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
 
P

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

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

Playstation

Active member
VIP
Found out there were some errors, revised above.
 

Similar threads

Top