RSI Tops and Bottoms
Oct 27, 2020

The RSI Tops and Bottoms indicator identifies local peaks and troughs when the Relative Strength Index (RSI) is in overbought or oversold territory and calculates divergences between them to highlight potential trend reversals.
Usage
The Usage section describes how the script can be used to identify market reversals through RSI divergence. The indicator plots lines connecting sequential RSI tops or bottoms once the RSI value exits the overbought (OB) or oversold (OS) zones.
- Bullish Divergence: Occurs when the price makes a lower low while the RSI makes a higher low within the oversold region. This is signaled by a green line and an optional bar color change, suggesting a potential move upward.
- Bearish Divergence: Occurs when the price makes a higher high while the RSI makes a lower high within the overbought region. This is signaled by a red line and an optional bar color change, suggesting a potential move downward.
Users can utilize these signals to set entry orders. For example, a "Buy Stop" order could be placed slightly above the high of the candle where a bullish divergence was confirmed to avoid false signals.
Details
The script executes by tracking the RSI's movement in and out of user-defined threshold levels. It requires that tops and bottoms be sequential; if a new top or bottom occurs while the script is evaluating a previous pair, the sequence is reset.
Specific logic includes:
- Duration Filtering: The script monitors how many bars the RSI spends in the OB/OS zone. If it stays beyond the "Max Number of Bars in OB/OS," the peak or trough is invalidated.
- Distance Constraints: To ensure the divergence is significant, the script checks the distance between sequential tops or bottoms. They must be further apart than the "Min Distance" and closer than the "Max Distance."
- Exit Trigger: Signals are only generated after the RSI has fully exited the overbought or oversold area, ensuring the peak or trough is established.
Settings
- RSI Length: The lookback period used to calculate the RSI (default is 14).
- RSI Source: The price data used for the RSI calculation (default is Close).
- Upper Band: The threshold level for overbought conditions (default is 70).
- Lower Band: The threshold level for oversold conditions (default is 30).
- Max Number of Bars in OB/OS: The maximum time the RSI can spend beyond the bands for a top or bottom to be considered valid.
- Min Number of Bars between Tops/Bottoms: The minimum horizontal distance required between two sequential peaks or troughs.
- Max Number of Bars between Tops/Bottoms: The maximum horizontal distance allowed between two sequential peaks or troughs.
- Line Colors: Customization for the visual lines connecting the RSI points.
- Line Width: Adjusts the thickness of the divergence lines.
- Change Bar Color: Toggles the highlighting of price bars when a divergence is detected.
FAQ
How do I interpret the lines drawn on the RSI panel? The lines connect two sequential RSI extremes where a price divergence has been detected. An arrow pointing left indicates the relationship between the current established peak/trough and the previous one.
Why did a signal appear several bars after a price peak? The script waits for the RSI to exit the overbought or oversold zone and confirms the "Max Bars" and "Distance" settings before triggering a signal, which ensures the trend shift has begun.
How can I access the RSI Tops and Bottoms indicator? You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
Free indicator
Get free access to this indicator on the platforms below.
Unlock the entire LuxAlgo Library
Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.