OPEN-SOURCE SCRIPT

RSI with Zone Colors

41
//version=6
indicator(title="RSI with Zone Colors", shorttitle="RSI+", format=format.price, precision=2, timeframe="", timeframe_gaps=true)

//// ==== INPUT SETTINGS ====
rsiLength = input.int(14, title="RSI Length", minval=1)
source = input.source(close, title="Source")
ob_level = input.int(70, title="Overbought Level")
os_level = input.int(30, title="Oversold Level")

//// ==== RSI CALCULATION ====
change = ta.change(source)
up = ta.ma(math.max(change, 0), rsiLength)
down = ta.ma(-math.min(change, 0), rsiLength)
rsi = down == 0 ? 100 : 100 - (100 / (1 + up / down))

//// ==== COLOR BASED ON ZONES ====
rsiColor = rsi > ob_level ? color.red : rsi < os_level ? color.green : #2962FF

//// ==== PLOT RSI ====
plot(rsi, title="RSI", color=rsiColor, linewidth=2)

//// ==== ZONE LINES ====
hline(ob_level, "Overbought", color=#787B86)
hline(50, "Middle", color=color.new(#787B86, 50))
hline(os_level, "Oversold", color=#787B86)

//// ==== FILL ZONES ====
zoneColor = rsi > ob_level ? color.new(color.red, 85) : rsi < os_level ? color.new(color.green, 85) : na

fill(plot(ob_level, display=display.none), plot(rsi > ob_level ? rsi : ob_level, display=display.none), color=zoneColor, title="OB Fill")
fill(plot(os_level, display=display.none), plot(rsi < os_level ? rsi : os_level, display=display.none), color=zoneColor, title="OS Fill")

//// ==== COLOR CANDLE WHEN RSI IN ZONE ====
barcolor(rsi > ob_level ? color.red : rsi < os_level ? color.green : na)

Aviso legal

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.