Paste this entire indicator into Pine Editor, save it, and add it to a standard Candles chart. With the default settings, a closed bar becomes orange when its 14-period RSI is above 70 or blue when RSI is below 30. Equality and the middle range receive no override. These thresholds demonstrate branching; they are not entry or exit instructions. Select Draw custom candles to compare the second rendering method without running a second script.
One complete indicator with two rendering modes and an RSI Data Window readout.pinescript
//@version=6
indicator("Conditional Candle Colors", overlay=true, behind_chart=false)
mode = input.string("Recolor chart bars", "Rendering", options=["Recolor chart bars", "Draw custom candles"])
enabled = input.bool(true, "Enable highlights")
waitForClose = input.bool(true, "Wait for bar close")
length = input.int(14, "RSI length", minval=1)
upperColor = input.color(color.orange, "RSI above 70")
lowerColor = input.color(color.blue, "RSI below 30")
customWick = input.color(color.gray, "Custom candle wick")
rsiValue = ta.rsi(close, length)
isReady = enabled and not na(rsiValue) and (not waitForClose or barstate.isconfirmed)
color ruleColor = na
if isReady
if rsiValue > 70
ruleColor := upperColor
else if rsiValue < 30
ruleColor := lowerColor
useChartBars = mode == "Recolor chart bars"
barcolor(useChartBars ? ruleColor : na, title="RSI chart highlights")
drawCustom = not useChartBars and not na(ruleColor)
plotcandle(drawCustom ? open : na, high, low, close, title="RSI custom candles", color=ruleColor, wickcolor=customWick, bordercolor=ruleColor)
plot(rsiValue, title="RSI for color rule", display=display.data_window)