Momentum

RSI Buy Sell Signals: Thresholds and Confirmed Divergence

Read RSI threshold exits, centerline crosses and confirmed price-pivot divergence. Includes Pine Script v6, input definitions and signal timing limits.

RSI Signal Interpretation

Quick-reference guide to 6 signal types you will see on the chart.

Signal TypeIndicator ConditionMarket MeaningInterpretation limits
Oversold exitRSI crosses above the configured lower threshold on a closed bar.Momentum has recovered through the threshold; default 30.It does not prove that a price bottom has formed.
Overbought exitRSI crosses below the configured upper threshold on a closed bar.Momentum has fallen back through the threshold; default 70.An uptrend can continue after the signal.
Regular bullish divergenceTwo confirmed price lows form a lower low while RSI sampled at those lows forms a higher value.Price and sampled momentum disagree at the two swing points.Requires right-hand bars to confirm. No wider trend or oversold filter is included.
Regular bearish divergenceTwo confirmed price highs form a higher high while sampled RSI forms a lower value.Price has reached a higher high with a lower RSI reading.The script does not separately find or pair RSI pivots.
Centerline up-crossRSI crosses above 50 on a closed bar.Smoothed gains have become greater than smoothed losses for the selected source.This describes the RSI balance; it does not establish a future price trend.
Centerline down-crossRSI crosses below 50 on a closed bar.Smoothed losses have become greater than smoothed gains.Repeated centerline crosses can occur in a narrow trading range.

RSI Pine Script Signal Code

Educational indicator example. Review its exact rules and compare its plots with your intended calculation in TradingView. It does not place orders or establish profitability.

Pine Script v6
//@version=6
indicator("RSI Threshold and Pivot Signals", overlay=false)
len = input.int(14, "RSI Length", minval=1)
src = input.source(close, "Source")
ob = input.float(70, "Upper Threshold", minval=50.1, maxval=100)
os = input.float(30, "Lower Threshold", minval=0, maxval=49.9)
pivotBars = input.int(2, "Pivot Bars Each Side", minval=1, maxval=20)
rsi = ta.rsi(src, len)
exitLowRaw = ta.crossover(rsi, os)
exitHighRaw = ta.crossunder(rsi, ob)
midUpRaw = ta.crossover(rsi, 50)
midDownRaw = ta.crossunder(rsi, 50)
exitLow = barstate.isconfirmed and exitLowRaw
exitHigh = barstate.isconfirmed and exitHighRaw
midUp = barstate.isconfirmed and midUpRaw
midDown = barstate.isconfirmed and midDownRaw

priceLow = ta.pivotlow(low, pivotBars, pivotBars)
priceHigh = ta.pivothigh(high, pivotBars, pivotBars)
newLow = not na(priceLow)
newHigh = not na(priceHigh)
priorLow = ta.valuewhen(newLow, priceLow, 1)
priorLowRsi = ta.valuewhen(newLow, rsi[pivotBars], 1)
priorHigh = ta.valuewhen(newHigh, priceHigh, 1)
priorHighRsi = ta.valuewhen(newHigh, rsi[pivotBars], 1)
bullDiv = barstate.isconfirmed and newLow and priceLow < priorLow and rsi[pivotBars] > priorLowRsi
bearDiv = barstate.isconfirmed and newHigh and priceHigh > priorHigh and rsi[pivotBars] < priorHighRsi
plot(rsi, "RSI", color.blue)
hline(ob, "Upper", color.red)
hline(50, "Center", color.gray)
hline(os, "Lower", color.green)
plotshape(exitLow, "Lower Exit", shape.triangleup, location.bottom, color.green, text="OS")
plotshape(exitHigh, "Upper Exit", shape.triangledown, location.top, color.red, text="OB")
// Divergence markers stay on the confirmation bar; there is no negative offset.
plotshape(bullDiv, "Bull Divergence", shape.labelup, location.bottom, color.teal, text="DIV")
plotshape(bearDiv, "Bear Divergence", shape.labeldown, location.top, color.orange, text="DIV")
plotshape(midUp, "Center Up", shape.circle, location.bottom, color.blue, size=size.tiny)
plotshape(midDown, "Center Down", shape.circle, location.top, color.purple, size=size.tiny)
alertcondition(exitLow, "RSI Lower Exit", "RSI crossed above the configured lower threshold")
alertcondition(exitHigh, "RSI Upper Exit", "RSI crossed below the configured upper threshold")
alertcondition(midUp, "RSI Center Up", "RSI crossed above 50")
alertcondition(midDown, "RSI Center Down", "RSI crossed below 50")
alertcondition(bullDiv, "RSI Bullish Divergence", "Confirmed price-pivot bullish RSI divergence")
alertcondition(bearDiv, "RSI Bearish Divergence", "Confirmed price-pivot bearish RSI divergence")

Example settings for RSI

Record the inputs used by the example. These settings are not an optimized trading recommendation.

Feature comparison table: Default vs Description
ParameterDefaultDescription
RSI Length14Number of bars in the Wilder-smoothed gain/loss calculation. Changing it changes the measured horizon; no optimal length is established here.
SourcecloseSeries whose changes feed RSI. Choosing HLC3 changes the calculation; it is not a guarantee of smoother or more profitable signals.
Upper / Lower Threshold70 / 30Defines the exit events. Inputs keep the upper threshold above 50 and the lower threshold below 50.
Pivot Bars Each Side2A price swing must have this many bars on both sides. With 2, divergence can first be reported two bars after the swing, at the confirmation bar close.

Turn the condition into an explicit rule

Specify the calculation, confirmation time, entry and exit rules before asking Pineify to draft or revise Pine Script. Review the code and simulate realistic costs before evaluating a strategy.

Explore Pine Script coding

FAQ

RSI Signals FAQ

How does RSI calculate momentum?
RSI compares Wilder-smoothed positive and negative changes in the selected source. For nonzero average loss, RSI = 100 - 100 / (1 + average gain / average loss). For example, hypothetical average gain of 2 and average loss of 1 gives RSI of about 66.67. The example uses the built-in ta.rsi function.
Is crossing above 70 a sell signal in this code?
No. The upper-exit signal requires RSI to cross back below the upper threshold. With a threshold of 70, a move from 69 to 72 is not an upper exit; 72 to 69 is. Likewise, the lower exit requires a move back above 30, rather than merely entering the oversold region.
When does the divergence marker appear?
At the close of the bar that confirms the second price pivot. With two right-hand bars, a swing on bar 100 cannot be confirmed until bar 102 closes. The marker appears on bar 102. Hypothetical lows of 100 and 98 with RSI readings of 25 and 29 qualify as bullish divergence once both pivots are confirmed; they do not prove a reversal.
Does the script detect RSI failure swings?
No. A bullish failure swing is a separate multi-stage RSI pattern: an oversold reading, a recovery, a pullback that stays above the oversold threshold, and a break of the recovery high. One threshold crossover or a price-pivot divergence is not the whole pattern. This example supplies six conditions and no failure-swing detector.
Does RSI repaint?
RSI changes while the current chart bar develops. These alert conditions wait for barstate.isconfirmed, and divergence labels are not moved back to the earlier swing. Feed corrections or changed settings can still change historical calculations. Other RSI scripts may use different confirmation or higher-timeframe logic.
Which RSI settings have the best win rate?
No comparative backtest is supplied for these defaults. Win rate also requires explicit entry, exit, stop, sizing and execution rules; this indicator supplies none of those. Compare complete strategies on separate evaluation data with costs instead of treating 14/30/70 or a divergence marker as a performance result.
How is RSI different from Stochastic?
RSI compares smoothed gains and losses in a source series. Stochastic locates the close within a recent high-low range and may smooth that position into K and D lines. Their relative responsiveness depends on the chosen inputs; neither has a universal signal-frequency or accuracy advantage.