Colour the watchlist with if then


Category:
0
0

Thank you Pete for the custom watch list video. I was able to create a watchlist that brings up my scan but I can’t find a way to colour the two findings in different colours.

//This part I can’t figure out

def clsAbove = SimpleMovingAvg(“length” = 22).”SMA” crosses below close;
def clsBelow = SimpleMovingAvg(“length” = 22).”SMA” crosses above close;

//

plot signal = SimpleMovingAvg(“length” = 22).”SMA” crosses below close or SimpleMovingAvg(“length” = 22).”SMA” crosses above close;
AssignBackgroundColor(if signal then color.DARK_GREEN else color.WHITE);

What I’m trying to do is if clsAbove is true the BackgroundColor is Green if clsBelow is true it is Red.

I can’t figure out the if-then logic as I don’t know enough of the syntax to figure it out.

 

RESOLVED
Marked as spam
Posted by (Questions: 4, Answers: 5)
Asked on December 24, 2020 8:50 pm
76 views
0
Private answer

Solved with the help of the code Pete posted in the Background color change example.

--

def clsAbove = SimpleMovingAvg("length" = 22)."SMA" crosses below close;

def clsBelow = SimpleMovingAvg("length" = 22)."SMA" crosses above close;

 

#main code

plot signal = clsAbove or clsBelow ;

AssignBackgroundColor(if clsAbove > clsBelow then Color.UPTICK else if clsAbove < clsBelow then Color.DOWNTICK else Color.GRAY);

 

Marked as spam
Posted by (Questions: 4, Answers: 5)
Answered on December 25, 2020 5:10 pm
Hi Pete, I would like to add to this code if possible. I'm looking for a way to make the watchlist purple IF the stock stays above the 22SMA at 11am the next day after the previous cross above the moving average.
( at January 21, 2021 12:02 pm)