OPEN-SOURCE SCRIPT
Smart RSI Candles [MarkitTick]

💡 The Smart RSI Candles indicator redefines how traders visualize momentum by converting the standard Relative Strength Index (RSI) into an intuitive, multi-dimensional candlestick chart. Instead of relying on a single oscillating line that only shows the final value of a period, this tool provides Open, High, Low, and Close (OHLC) data for the RSI itself. This methodology offers far deeper insights into momentum volatility, internal strength, and intra-bar price action within any given timeframe. Furthermore, it features an advanced, automated divergence detection engine. This engine continuously scans the market for both regular and hidden divergences, instantly plotting them directly on the oscillator pane alongside actionable alert conditions. Whether you are a reversal trader looking for exhaustion or a trend-follower waiting for a pullback, this indicator provides a complete, self-contained momentum ecosystem.
✨ Originality and Utility
🔬 Methodology and Concepts
● The RSI Candlestick Calculation
● Divergence Detection Engine
🎨 Visual Guide
● RSI Candlesticks
● Threshold Lines
● Divergence Indicators
📖 How to Use
⚙️ Inputs and Settings
🔍 Deconstruction of the Underlying Scientific and Academic Framework
⚠️ Disclaimer
All provided scripts and indicators are strictly for educational exploration and must not be interpreted as financial advice or a recommendation to execute trades. I expressly disclaim all liability for any financial losses or damages that may result, directly or indirectly, from the reliance on or application of these tools. Market participation carries inherent risk where past performance never guarantees future returns, leaving all investment decisions and due diligence solely at your own discretion.
✨ Originality and Utility
- While the traditional RSI is a staple in technical analysis, it often fails to convey the true intra-bar volatility of market momentum. This script solves that fundamental flaw by generating fully formed RSI candles.
- The originality of this script lies heavily in the custom `RsiScaler` type. This mathematical function scales actual price wicks (the highs and lows) down into the restricted 0-100 bounds of the RSI scale. This creates highly accurate high and low shadows for the RSI candles, a feature completely absent in standard momentum oscillators.
- The utility is massively enhanced by the built-in divergence scanner. Traders no longer need to manually draw trendlines comparing price pivots to RSI pivots. The script autonomously identifies Regular Bullish, Regular Bearish, Hidden Bullish, and Hidden Bearish setups.
- For algorithmic and systematic traders, alerts are generated with pre-calculated JSON payloads. These payloads include dynamic Stop Loss (SL) and Take Profit (TP) values automatically calculated using a 1:1.5 risk-to-reward ratio, making it highly useful for direct integration into automated trading systems or execution bots.
🔬 Methodology and Concepts
● The RSI Candlestick Calculation
- The script begins by calculating the raw RSI using the user-defined length (default is set to 14).
- To construct the body of the candle, it calculates a custom RSI Open (`o_rsi`). This is achieved by evaluating the moving average of both gains and losses using a smoothed Running Moving Average (RMA) approach with a specific alpha.
- The current raw RSI serves as the Closing value (`c_rsi`) for the candle.
- The high and low wicks are derived through a complex mapping process. The script compares the actual price high and low against the RSI's historical range using a proportional interpolation factor.
- Finally, these values are mathematically clamped to ensure they never exceed the absolute RSI limits of 0 and 100.
● Divergence Detection Engine
- The script utilizes pivot functions to pinpoint local troughs and peaks on the newly calculated RSI extremes.
- These coordinates are stored in a custom `PivotData` object.
- When a new pivot is confirmed within the maximum lookback window, the script evaluates the current price and RSI values against the historical pivot.
- A Regular Bullish Divergence triggers when the price structure makes a lower low, but the RSI momentum makes a higher low.
- Conversely, a Hidden Bullish Divergence triggers when the price structure makes a higher low, but the RSI plunges to a lower low.
🎨 Visual Guide
● RSI Candlesticks
- • Bullish Candles: Displayed on the oscillator pane when the RSI Close is greater than or equal to the RSI Open. These are colored in a distinct teal (#089981) by default to indicate rising internal momentum.
- • Bearish Candles: Displayed when the RSI Close is strictly lower than the RSI Open. These are colored in a standard red (#f23645) to indicate falling internal momentum.
● Threshold Lines
- • Overbought Line: A horizontal line permanently set at the 80 level, indicating extreme upward momentum and potential overextension.
- • Oversold Line: A horizontal line permanently set at the 20 level, indicating extreme downward momentum and potential capitulation.
- • Midline: A neutral 50-level line used by traders to gauge the broader trend bias (above 50 is bullish, below 50 is bearish).
● Divergence Indicators
- • Solid Lines: Drawn connecting the valid pivot points to highlight Regular Divergences (Green lines for Bullish setups, Red lines for Bearish setups).
- • Dashed Lines: Drawn connecting the valid pivot points to highlight Hidden Divergences, separating them visually from regular reversal setups.
- • Text Labels: Small, precise shapes containing text (such as "Bull", "Bear", "H-Bull", "H-Bear") appear directly above or below the triggering price pivots on the main chart to provide immediate visual confirmation of the detected setup.
📖 How to Use
- • Momentum Confirmation: Closely observe the color and the physical size of the RSI candles. A consecutive series of large, bullish RSI candles decisively breaking above the 50 Midline strongly suggests that buyer strength is accumulating rapidly.
- • Reversal Trading: Look for Regular Divergences occurring near the extreme 20 or 80 boundary levels. For example, if the price is pushing down to a new low, but the RSI candle forms a higher low and subsequently triggers a "Bull" label on the chart, traders can consider this an early warning signal that selling pressure is exhausting.
- • Trend Continuation: Utilize Hidden Divergences to strategically rejoin an already established trend. A "H-Bull" label appearing during a standard uptrend pullback indicates that momentum has reset to a lower level, but the overall price remains structurally bullish, offering a high-probability potential entry point.
- • Alert Automation: Configure TradingView alerts directly on this indicator to receive the structured JSON payloads. These comprehensive data packets can be routed to third-party execution platforms, automatically utilizing the mathematically derived Stop Loss and Take Profit levels provided in the code.
⚙️ Inputs and Settings
- • RSI Length: This is the core lookback period utilized for the relative strength calculation. The default value is 14, but it can be adjusted to suit faster or slower trading styles.
- • Divergence Pivot Left / Right: This setting determines exactly how many bars are required on either side of a potential high or low to officially confirm it as a pivot point. Selecting higher values will inherently result in fewer, but potentially more significant and reliable, divergence signals.
- • Max Divergence Lookback: This controls the maximum number of historical bars allowed between two confirmed pivots for a divergence to be considered valid by the engine. The default parameter is 60.
- • Color Customization: Users have absolute control over the visual aesthetics, with dedicated inputs to change the colors for bullish/bearish candles, overbought/oversold lines, and all four distinct divergence line types.
🔍 Deconstruction of the Underlying Scientific and Academic Framework
- The fundamental foundation of this script rests firmly on J. Welles Wilder Jr.'s Relative Strength Index, a classic momentum oscillator designed to measure the speed and change of directional price movements.
- By converting the standard RSI formula—which traditionally yields only a single scalar value per time period—into an OHLC statistical distribution, the script practically applies the advanced principles of data discretization to market momentum.
- The proprietary `RsiScaler` algorithm utilizes linear interpolation to effectively project the spatial relationship of price wicks onto the confined, normalized vector space of the RSI (which operates strictly from 0 to 100). This mathematical mapping ensures that the proportional variance of the asset's price is accurately and visually represented within the oscillator's finite bounds.
- Furthermore, the divergence detection protocol relies on local extremum mathematics. It actively identifies specific points in time where the first derivative of the price function changes its sign. By calculating and comparing the slope of the secant line connecting two price extrema to the slope connecting the corresponding RSI extrema, the algorithm efficiently identifies structural non-conformities. In academic financial literature, these structural non-conformities (divergences) are widely recognized as phenomena that often precede significant shifts in aggregate market psychology.
⚠️ Disclaimer
All provided scripts and indicators are strictly for educational exploration and must not be interpreted as financial advice or a recommendation to execute trades. I expressly disclaim all liability for any financial losses or damages that may result, directly or indirectly, from the reliance on or application of these tools. Market participation carries inherent risk where past performance never guarantees future returns, leaving all investment decisions and due diligence solely at your own discretion.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
💡 Proprietary indicators. Original research. Built by analysts who trade.
📢 Free Telegram: t.me/MarkitTick_Updates
👑 Premium: TradingView Marketplace
📘 Guides: markittick.com
📢 Free Telegram: t.me/MarkitTick_Updates
👑 Premium: TradingView Marketplace
📘 Guides: markittick.com
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
💡 Proprietary indicators. Original research. Built by analysts who trade.
📢 Free Telegram: t.me/MarkitTick_Updates
👑 Premium: TradingView Marketplace
📘 Guides: markittick.com
📢 Free Telegram: t.me/MarkitTick_Updates
👑 Premium: TradingView Marketplace
📘 Guides: markittick.com
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。