Page 1 of 1

change color RSI

Posted: Thu Mar 11, 2021 6:28 pm
by oneill13
Hello,

Sorry I don't speak English very well!
I am just starting out in programming!
I wish something simple but hard to code !!

On the RSI I want the line that represents the RSI to turn yellow when it goes above 70%, and turn purple when it drops below 60%.
And that it turns yellow again only when it exceeds 70%

It sounds simple but I can't do it!

Thanks so much if you can give me a lead!

Have a nice day

Re: change color RSI

Posted: Mon Mar 15, 2021 2:16 am
by kmarryat
Hi,
I think this is what you described.

Code: Select all

//@version=4
study("RSI Color")

//RSI Calc
RSI = rsi(close, 14)

//Ternary Condition to Set Color - if RSI > 70 then yellow, if RSI < 60 then purple, otherwise white
RSIColor = RSI > 70 ? color.yellow : RSI < 60 ? color.purple : color.white

//Plot RSI using defined RSIColor
plot(RSI, title="RSI", color=RSIColor)
OBline = hline(70, "OB", color=color.white, linestyle=hline.style_dashed)
OSline = hline(30, "OS", color=color.white, linestyle=hline.style_dashed)
fill(OBline, OSline, color=RSIColor, transp=90, title="Fill")

Re: change color RSI

Posted: Sat Mar 20, 2021 8:28 pm
by oneill13
Hello!
Thanks for the answer but that's not quite it.
I would like the RSI to turn yellow when it crosses 70%, and only turn purple again when it drops below 60%
But if the RSI goes up without hitting 70% I don't want it to turn yellow.
And if it has crossed the 70% I want it to come back purple only if it goes below 60%
But I don't think that's possible ...
But thank you for your help!