Momentum
RSI with Shaded Zones
Relative strength index in its own pane with the overbought and oversold bands shaded, and alerts for the moment price leaves either zone rather than the moment it enters.
indicator
//@version=6
indicator("RSI with Shaded Zones", "RSI Zones")
length = input.int(14, "Length", minval = 2, group = "Settings")
upper = input.int(70, "Overbought", minval = 50, maxval = 99, group = "Settings")
lower = input.int(30, "Oversold", minval = 1, maxval = 50, group = "Settings")
hot = input.color(#EF5350, "Overbought", group = "Style")
cold = input.color(#26A69A, "Oversold", group = "Style")
lineCol = input.color(#787B86, "Line", group = "Style")
rsi = ta.rsi(close, length)
hline(upper, "Overbought", color = color.new(lineCol, 50))
hline(50, "Midline", color = color.new(lineCol, 75), linestyle = hline.style_dotted)
hline(lower, "Oversold", color = color.new(lineCol, 50))
plot(rsi, "RSI", color = lineCol, linewidth = 2)
bgcolor(rsi > upper ? color.new(hot, 90) : rsi < lower ? color.new(cold, 90) : na, title = "Zone")
leftOversold = ta.crossover(rsi, lower)
leftOverbought = ta.crossunder(rsi, upper)
alertcondition(leftOversold, "Left oversold", "RSI crossed back above the oversold level")
alertcondition(leftOverbought, "Left overbought", "RSI crossed back below the overbought level")
This runs in TradingView, not here
Pine Script only executes inside TradingView. Paste the source into the Pine Editor and add it to a chart to see it plotted.
What it will not do
- A high RSI means a strong trend at least as often as it means an imminent reversal. Leaving the zone is the event worth watching, not entering it.
- The 70/30 defaults are convention, not evidence. They suit some instruments and timeframes and not others.
Written from this description
Show RSI with adjustable overbought and oversold levels, shade the background when RSI is beyond either level, and alert when it crosses back out of a zone.
Educational only, not financial advice. The maths is simple arithmetic on the numbers you enter; it knows nothing about your broker, fees, slippage or the market. Something wrong with it? Say so in Site Feedback.