oneill13
Pine Script Rookie
Pine Script Rookie
Posts: 2
Joined: March 11th, 2021

change color RSI

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

kmarryat
Pine Script Rookie
Pine Script Rookie
Posts: 20
Joined: December 21st, 2020
Contact: TradingView Profile

Re: change color RSI

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")

oneill13
Pine Script Rookie
Pine Script Rookie
Posts: 2
Joined: March 11th, 2021

Re: change color RSI

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!

Return to “Request Scripts”