OPEN-SOURCE SCRIPT
Relative Strength Index - RSI | TR

🎯 Overview
Relative Strength Index - RSI | TR is a sophisticated momentum oscillator that measures the speed and magnitude of recent price changes to evaluate overbought and oversold conditions. Developed by Tiagorocha1989, this enhanced version of Welles Wilder's classic RSI offers dual-mode operation with moving average customization and comprehensive visual features, helping traders identify potential reversals, confirm trends, and generate clear entry and exit signals with greater precision.
🔧 How It Works
The RSI compares the magnitude of recent gains to recent losses, creating an oscillator that ranges from 0 to 100. Traditional interpretation suggests that readings above 70 indicate overbought conditions (potential for reversal downward), while readings below 30 indicate oversold conditions (potential for reversal upward).
Core Calculation Logic:
The indicator calculates the RSI using the standard formula:
Average gain over the specified period divided by average loss over the same period
This ratio is normalized to create a value between 0 and 100
The RSI is then compared to a reference line that can be either:
The traditional 50 level (centerline)
A user-defined moving average of the RSI itself
When the RSI crosses above the reference line, it generates a bullish signal. When it crosses below, it generates a bearish signal.
✨ Key Features
🔹 Dual Operating Modes
50 Level Mode: Classic RSI implementation where signals occur when the RSI crosses above or below the 50 centerline, indicating momentum shifts
RSI MA Mode: Enhanced version where signals occur when the RSI crosses its own moving average, providing smoother, filtered entries
🔹 Flexible Moving Average Selection
Choose from six MA types for the RSI MA mode:
EMA (Exponential Moving Average) for responsive signals
SMA (Simple Moving Average) for smoother readings
RMA (Rolling Moving Average) for weighted recent data
WMA (Weighted Moving Average) for customizable weighting
VWMA (Volume-Weighted Moving Average) incorporating volume
HMA (Hull Moving Average) for reduced lag
🔹 Customizable RSI Parameters
Length RSI: Lookback period for RSI calculation (default 14)
Source RSI: Price source for calculations (default Close)
🔹 Customizable Color Themes
Eight distinct color schemes to match your charting preferences:
Classic – Green for bullish, Red for bearish
Modern – White for bullish, Purple for bearish
Robust – Amber for bullish, Maroon for bearish
Accented – Violet for bullish, Pink for bearish
Monochrome – Light gray for bullish, Dark gray for bearish
Moderate – Green for bullish, Red for bearish
Aqua – Blue for bullish, Orange for bearish
Cosmic – Pink for bullish, Purple for bearish
🔹 Comprehensive Visual Feedback
Colored RSI Line: Changes color based on position relative to the reference line
Gradient Fill Zones: Clear visualization of overbought (above 80) and oversold (below 20) conditions
Dynamic Zone Fills: Semi-transparent fills showing when RSI is above or below the reference line
Color-Coded Candles: Bars reflect current RSI bias
Signal Markers: Triangle up/down symbols at crossover points
Live Value Display: Current RSI value shown in a floating label
Trend Table: Bullish/Bearish status displayed on the chart
🔹 Ready-to-Use Alerts
Built-in alert conditions trigger LONG signals on bullish crossovers and SHORT signals on bearish crossunders across both operating modes.
⚙️ Settings Summary
Color Choice: Select from eight visual themes (Default: Classic)
Length RSI: Lookback period for RSI calculation (Default: 14)
Source RSI: Price source for calculations (Default: Close)
Entry/Exit Signal: Choose between 50 level or RSI MA mode (Default: 50)
Length RSI MA: Moving average period for RSI MA mode (Default: 365)
RSI MA Type: Moving average method for signal line (Default: EMA)
📈 Practical Applications
🔹 Overbought/Oversold Detection
Traditional RSI usage identifies extreme conditions:
Readings above 70-80 suggest overbought conditions and potential reversal down
Readings below 20-30 suggest oversold conditions and potential reversal up
The indicator provides gradient fills in these zones for visual clarity
🔹 Centerline Crossovers
In 50 Level mode, crossovers provide momentum signals:
Crossover above 50 → Bullish momentum strengthening
Crossunder below 50 → Bearish momentum strengthening
These signals often align with trend direction
🔹 Signal Line Crossovers
In RSI MA mode, crossovers between RSI and its moving average provide filtered signals that reduce whipsaws in ranging markets while maintaining sensitivity in trends.
🔹 Divergence Trading
One of the most powerful RSI applications is spotting divergences:
Bullish Divergence: Price makes lower low, RSI makes higher low → Potential upside reversal
Bearish Divergence: Price makes higher high, RSI makes lower high → Potential downside reversal
🔹 Failure Swings
Look for RSI moves above 70 (or below 30), a pullback, and then a move beyond the previous extreme:
Bullish Failure Swing: RSI falls below 30, rises above 30, pulls back without crossing below 30, then breaks above its recent high
Bearish Failure Swing: RSI rises above 70, falls below 70, rallies without crossing above 70, then breaks below its recent low
🔹 Trend Confirmation
In trending markets, RSI can confirm strength:
Uptrend: RSI tends to stay above 40-50, with pullbacks finding support at these levels
Downtrend: RSI tends to stay below 60-50, with rallies finding resistance at these levels
🎯 Ideal For
✅ Mean Reversion Traders seeking overbought and oversold opportunities
✅ Divergence Traders looking for hidden reversal signals
✅ Trend Traders wanting momentum confirmation
✅ Swing Traders capturing medium-term momentum shifts
✅ System Developers needing reliable crossover logic for automated strategies
📌 Key Takeaways
Dual-Mode Flexibility: Choose between classic 50-level crossovers for traditional signals or MA-smoothed signals for filtered entries
Comprehensive Visualization: Color themes, gradient fills for overbought/oversold zones, candles, and labels provide immediate market awareness
Divergence Capability: Excellent for spotting both regular and hidden divergences that signal trend reversals or continuations
Multiple Timeframe Application: Works effectively across all timeframes, from intraday to weekly charts
Alert-Ready: Built-in alerts for both LONG and SHORT signals across both operating modes
⚠️ Important Notes
In strong trends, RSI can remain in overbought or oversold territory for extended periods, so traditional overbought/oversold signals should be used with caution. The 365-day MA default in RSI MA mode is designed for longer-term trend context on daily charts. Divergences are most reliable when they occur at extreme readings (above 70 or below 30). Always combine with proper risk management and additional confirmation for best results.
Disclaimer: This indicator is provided for educational and informational purposes only. Past performance is not indicative of future results. Always conduct thorough testing and align with your risk management strategy before live deployment.
Relative Strength Index - RSI | TR is a sophisticated momentum oscillator that measures the speed and magnitude of recent price changes to evaluate overbought and oversold conditions. Developed by Tiagorocha1989, this enhanced version of Welles Wilder's classic RSI offers dual-mode operation with moving average customization and comprehensive visual features, helping traders identify potential reversals, confirm trends, and generate clear entry and exit signals with greater precision.
🔧 How It Works
The RSI compares the magnitude of recent gains to recent losses, creating an oscillator that ranges from 0 to 100. Traditional interpretation suggests that readings above 70 indicate overbought conditions (potential for reversal downward), while readings below 30 indicate oversold conditions (potential for reversal upward).
Core Calculation Logic:
The indicator calculates the RSI using the standard formula:
Average gain over the specified period divided by average loss over the same period
This ratio is normalized to create a value between 0 and 100
The RSI is then compared to a reference line that can be either:
The traditional 50 level (centerline)
A user-defined moving average of the RSI itself
When the RSI crosses above the reference line, it generates a bullish signal. When it crosses below, it generates a bearish signal.
✨ Key Features
🔹 Dual Operating Modes
50 Level Mode: Classic RSI implementation where signals occur when the RSI crosses above or below the 50 centerline, indicating momentum shifts
RSI MA Mode: Enhanced version where signals occur when the RSI crosses its own moving average, providing smoother, filtered entries
🔹 Flexible Moving Average Selection
Choose from six MA types for the RSI MA mode:
EMA (Exponential Moving Average) for responsive signals
SMA (Simple Moving Average) for smoother readings
RMA (Rolling Moving Average) for weighted recent data
WMA (Weighted Moving Average) for customizable weighting
VWMA (Volume-Weighted Moving Average) incorporating volume
HMA (Hull Moving Average) for reduced lag
🔹 Customizable RSI Parameters
Length RSI: Lookback period for RSI calculation (default 14)
Source RSI: Price source for calculations (default Close)
🔹 Customizable Color Themes
Eight distinct color schemes to match your charting preferences:
Classic – Green for bullish, Red for bearish
Modern – White for bullish, Purple for bearish
Robust – Amber for bullish, Maroon for bearish
Accented – Violet for bullish, Pink for bearish
Monochrome – Light gray for bullish, Dark gray for bearish
Moderate – Green for bullish, Red for bearish
Aqua – Blue for bullish, Orange for bearish
Cosmic – Pink for bullish, Purple for bearish
🔹 Comprehensive Visual Feedback
Colored RSI Line: Changes color based on position relative to the reference line
Gradient Fill Zones: Clear visualization of overbought (above 80) and oversold (below 20) conditions
Dynamic Zone Fills: Semi-transparent fills showing when RSI is above or below the reference line
Color-Coded Candles: Bars reflect current RSI bias
Signal Markers: Triangle up/down symbols at crossover points
Live Value Display: Current RSI value shown in a floating label
Trend Table: Bullish/Bearish status displayed on the chart
🔹 Ready-to-Use Alerts
Built-in alert conditions trigger LONG signals on bullish crossovers and SHORT signals on bearish crossunders across both operating modes.
⚙️ Settings Summary
Color Choice: Select from eight visual themes (Default: Classic)
Length RSI: Lookback period for RSI calculation (Default: 14)
Source RSI: Price source for calculations (Default: Close)
Entry/Exit Signal: Choose between 50 level or RSI MA mode (Default: 50)
Length RSI MA: Moving average period for RSI MA mode (Default: 365)
RSI MA Type: Moving average method for signal line (Default: EMA)
📈 Practical Applications
🔹 Overbought/Oversold Detection
Traditional RSI usage identifies extreme conditions:
Readings above 70-80 suggest overbought conditions and potential reversal down
Readings below 20-30 suggest oversold conditions and potential reversal up
The indicator provides gradient fills in these zones for visual clarity
🔹 Centerline Crossovers
In 50 Level mode, crossovers provide momentum signals:
Crossover above 50 → Bullish momentum strengthening
Crossunder below 50 → Bearish momentum strengthening
These signals often align with trend direction
🔹 Signal Line Crossovers
In RSI MA mode, crossovers between RSI and its moving average provide filtered signals that reduce whipsaws in ranging markets while maintaining sensitivity in trends.
🔹 Divergence Trading
One of the most powerful RSI applications is spotting divergences:
Bullish Divergence: Price makes lower low, RSI makes higher low → Potential upside reversal
Bearish Divergence: Price makes higher high, RSI makes lower high → Potential downside reversal
🔹 Failure Swings
Look for RSI moves above 70 (or below 30), a pullback, and then a move beyond the previous extreme:
Bullish Failure Swing: RSI falls below 30, rises above 30, pulls back without crossing below 30, then breaks above its recent high
Bearish Failure Swing: RSI rises above 70, falls below 70, rallies without crossing above 70, then breaks below its recent low
🔹 Trend Confirmation
In trending markets, RSI can confirm strength:
Uptrend: RSI tends to stay above 40-50, with pullbacks finding support at these levels
Downtrend: RSI tends to stay below 60-50, with rallies finding resistance at these levels
🎯 Ideal For
✅ Mean Reversion Traders seeking overbought and oversold opportunities
✅ Divergence Traders looking for hidden reversal signals
✅ Trend Traders wanting momentum confirmation
✅ Swing Traders capturing medium-term momentum shifts
✅ System Developers needing reliable crossover logic for automated strategies
📌 Key Takeaways
Dual-Mode Flexibility: Choose between classic 50-level crossovers for traditional signals or MA-smoothed signals for filtered entries
Comprehensive Visualization: Color themes, gradient fills for overbought/oversold zones, candles, and labels provide immediate market awareness
Divergence Capability: Excellent for spotting both regular and hidden divergences that signal trend reversals or continuations
Multiple Timeframe Application: Works effectively across all timeframes, from intraday to weekly charts
Alert-Ready: Built-in alerts for both LONG and SHORT signals across both operating modes
⚠️ Important Notes
In strong trends, RSI can remain in overbought or oversold territory for extended periods, so traditional overbought/oversold signals should be used with caution. The 365-day MA default in RSI MA mode is designed for longer-term trend context on daily charts. Divergences are most reliable when they occur at extreme readings (above 70 or below 30). Always combine with proper risk management and additional confirmation for best results.
Disclaimer: This indicator is provided for educational and informational purposes only. Past performance is not indicative of future results. Always conduct thorough testing and align with your risk management strategy before live deployment.
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。