OPEN-SOURCE SCRIPT

RSI Trendlines and Divergences

401
█OVERVIEW
The "RSI Trendlines and Divergences" indicator is an advanced technical analysis tool that leverages the Relative Strength Index (RSI) to draw trendlines and detect divergences. Designed for traders seeking precise market signals, the indicator identifies key pivot points on the RSI chart, draws trendlines between pivots, and detects bullish and bearish divergences. It offers flexible settings, background coloring for breakout signals, and divergence labels, supported by alerts for key events. The indicator is universal and works across all markets (stocks, forex, cryptocurrencies) and timeframes.

█CONCEPTS
The indicator was developed to provide an alternative signal source for the RSI oscillator. Trendline breakouts and bounces off trendlines offer a broader perspective on potential price behavior. Combining these with traditional RSI signal interpretation can serve as a foundation for creating various trading strategies.

█FEATURES
- RSI and Pivot Calculation: Calculates RSI based on the selected source price (default: close) with a customizable period (default: 14). Identifies pivot points on RSI and price for trendlines and divergences.
- RSI Trendlines: Draws trendlines connecting RSI pivots (upper for downtrends, lower for uptrends) with optional extension (default: 30 bars). The trendline appears and generates a signal only after the first RSI crossover. Lines are colored (red for upper, green for lower).
- Trendline Fill: Widens the trendline with a tolerance margin expressed in RSI points, reducing signal noise and visually highlighting trend zones. Breaking this zone is a condition for generating signals, minimizing false signals. The tolerance margin can be increased or decreased.
- Divergence Detection: Identifies bullish and bearish divergences based on RSI and price pivots, displaying labels (“Bull” for bullish, “Bear” for bearish) with adjustable transparency. Divergence labels appear with a delay equal to the specified pivot length (default: 5). Higher values yield stronger signals but with greater delay.
- Breakout Signals: Generates signals when RSI crosses the trendline (bullish for upper lines, bearish for lower lines), with background coloring for signal confirmation.
- Alerts: Built-in alerts for:
Detection of bullish and bearish divergences.
Upper trendline crossover (bullish signal).
Lower trendline crossover (bearish signal).
- Customization: Allows adjustment of RSI length, pivot settings, line colors, fills, labels, and transparency of signals and background.

█HOW TO USE
Add the indicator to your TradingView chart via the Pine Editor or Indicators menu.
Configuring Settings.

RSI Settings

- RSI Length: Period for RSI calculation (default: 14).
- SMA Length: Period for RSI moving average (default: 9).
- Source: Source price for RSI (default: close).

Pivot Settings for Trend

- Left Bars for Pivot: Number of bars back for detecting pivots (default: 10).
- Right Bars for Pivot: Number of bars forward for confirming pivots (default: 10).
- Extension after Second Pivot: Number of bars to extend the trendline (default: 30, 0 = none). Extension increases the number of signals, while shortening reduces them.
- Tolerance: Deviation in RSI points to widen the breakout margin, reducing signal noise (default: 3.0).

Divergence Settings
- Enable Divergence Detection: Enables/disables divergence detection (default: enabled).
- Pivot Length for Divergence: Pivot period for divergences (default: 5).

Style Settings

- Upper Trendline Color: Color for downtrend lines (default: red).
- Upper Fill Color: Fill color for upper lines (default: red, transparency 70).
- Lower Trendline Color: Color for uptrend lines (default: green).
- Lower Fill Color: Fill color for lower lines (default: green, transparency 70).
- SMA Color: Color for RSI moving average (default: yellow).
- Bullish Divergence Color: Color for bullish labels (default: green).
- Bearish Divergence Color: Color for bearish labels (default: red).
- Text Color: Color for label text (default: white).
- Divergence Label Transparency: Transparency of labels (0-100, default: 40).
- Signal Background Transparency: Transparency of breakout signal background (0-100, default: 80).

Interpreting Signals

- Trendlines: Upper lines (red) indicate RSI downtrends, lower lines (green) indicate uptrends. The trendline appears and generates a signal only after the first RSI crossover. Trendline breakouts suggest potential trend reversals.
- Divergences: “Bull” labels indicate bullish divergence (potential rise), “Bear” labels indicate bearish divergence (potential decline), with a delay based on pivot length (default: 5). Divergences serve as confirmation or warning of trend reversal, not as standalone signals.
- Signal Background: Green background signals bullish breakouts, red background signals bearish breakouts.
- RSI Levels: Horizontal lines at 70 (overbought), 50 (midline), and 30 (oversold) help assess market zones.
- Alerts: Set up alerts in TradingView for divergences or trendline breakouts.

Combining with Other Tools: Use with support/resistance levels, Fibonacci levels, or other indicators for signal confirmation.

█APPLICATIONS
The "RSI Trendlines and Divergence" indicator is designed to identify trends and potential reversal points, supporting both trend-following and reversal strategies:

- Trend Confirmation: Trendlines indicate the RSI trend direction, with breakouts signaling potential reversals. The indicator is functional in traditional RSI usage, allowing classic RSI interpretation (e.g., returning from overbought/oversold zones). Combining trendline breakouts with RSI signal levels, such as a return from overbought or oversold zones paired with a trendline breakout, strengthens the signal.
- Divergence Detection: Divergences serve as confirmation or warning of trend reversal, not as standalone signals.

syot kilat

█NOTES
- Adjust settings (e.g., RSI length, pivots, tolerance) to suit your trading style and timeframe.
- Combine with other technical analysis tools to enhance signal accuracy.

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.