PROTECTED SOURCE SCRIPT

Dynamic RSI

67
Below is a step‐by‐step breakdown of how the script works, what each section does, and some commentary on its effectiveness and time frame adaptability.

1. Indicator Setup
pinescript
Copy
Edit
//version=5
indicator("Dynamic RSI", overlay=false)
What it does:
Specifies that the script uses Pine Script version 5.
Declares an indicator named “Dynamic RSI.”
overlay=false means it will appear in a separate panel (like a typical oscillator) rather than on the price chart.
2. Time Frame Determination
pinescript
Copy
Edit
// Check for long-term resolutions (daily, weekly, or monthly)
isLongTerm = (timeframe.isdaily or timeframe.isweekly or timeframe.ismonthly)
// Check for short-term (intraday) resolutions using the resolution string
isShortTerm = (timeframe.period == "15" or timeframe.period == "60" or timeframe.period == "240")
What it does:
isLongTerm: Checks if the current chart is using a daily, weekly, or monthly time frame.
isShortTerm: Checks if the chart’s period is exactly 15, 60, or 240 minutes.
Why it matters:
The script will adjust its parameters based on the chart’s time frame—making the RSI more sensitive on intraday charts and less reactive on longer-term charts.
3. Dynamic RSI Calculation
pinescript
Copy
Edit
// Adjust RSI Length Dynamically with explicit parentheses
rsiLength = isLongTerm ? 14 : (isShortTerm ? 7 : 10)
rsiValue = ta.rsi(close, rsiLength)
signalLineRSI = ta.sma(rsiValue, 9)
What it does:
RSI Period (rsiLength):
Uses 14 periods for long-term charts.
Uses 7 periods for short-term charts.
Uses 10 periods as a default for other time frames.
RSI Value (rsiValue): Calculates the RSI on the close prices using the chosen length.
Signal Line (signalLineRSI): Computes a 9-period simple moving average of the RSI. This can help smooth out the RSI’s fluctuations.
Why it matters:
Adjusting the RSI period helps adapt the indicator’s sensitivity:
Short-term (7-period): More reactive, capturing quick moves.
Long-term (14-period): Smoother, reducing noise.
Default (10-period): A middle ground for other resolutions.
4. Dynamic Overbought/Oversold Levels
pinescript
Copy
Edit
// Dynamic RSI Levels Based on Time Frame with parentheses for clarity
rsiOverbought = isLongTerm ? 75 : (isShortTerm ? 70 : 72)
rsiOversold = isLongTerm ? 25 : (isShortTerm ? 30 : 28)
What it does:
Sets overbought and oversold thresholds differently depending on the time frame:
Long-Term: Overbought at 75 and oversold at 25.
Short-Term: Overbought at 70 and oversold at 30.
Default: Overbought at 72 and oversold at 28.
Why it matters:
These dynamic levels can help adjust the sensitivity of the RSI signals to match the expected market behavior on different time frames.
5. Defining Consolidation and Continuation Levels
pinescript
Copy
Edit
// Consolidation Ranges
rsiBearishConsolidationLow = isLongTerm ? 40 : (isShortTerm ? 38 : 39)
rsiBearishConsolidationHigh = isLongTerm ? 50 : (isShortTerm ? 48 : 49)
rsiBullishConsolidationLow = isLongTerm ? 50 : (isShortTerm ? 52 : 51)
rsiBullishConsolidationHigh = isLongTerm ? 60 : (isShortTerm ? 58 : 59)

// Bullish and Bearish Continuation Levels
rsiBullishContinuation = isLongTerm ? 55 : (isShortTerm ? 57 : 56)
rsiBearishContinuation = isLongTerm ? 45 : (isShortTerm ? 43 : 44)
What it does:
Consolidation Levels:
Defines ranges where the RSI might be consolidating (moving sideways).
There are separate ranges for potential bearish (40–50 on long-term) and bullish (50–60 on long-term) consolidation.
Continuation Levels:
Provides additional reference levels to identify the potential continuation of bullish or bearish trends.
Why it matters:
These extra levels can give traders more context about the RSI’s position beyond just overbought/oversold. They help in identifying areas of potential support/resistance in RSI space.
6. Plotting the RSI and Reference Lines
pinescript
Copy
Edit
// Plot RSI and associated levels using continuous lines
plot(rsiValue, title="RSI", color=color.blue, linewidth=2)
plot(signalLineRSI, title="RSI Signal Line", color=color.orange, linewidth=2)
plot(rsiOverbought, title="Overbought", color=color.red, linewidth=1, style=plot.style_line)
plot(rsiOversold, title="Oversold", color=color.green, linewidth=1, style=plot.style_line)
plot(rsiBearishConsolidationLow, title="Bearish Consolidation Low", color=color.gray, linewidth=1, style=plot.style_line)
plot(rsiBearishConsolidationHigh, title="Bearish Consolidation High", color=color.gray, linewidth=1, style=plot.style_line)
plot(rsiBullishConsolidationLow, title="Bullish Consolidation Low", color=color.gray, linewidth=1, style=plot.style_line)
plot(rsiBullishConsolidationHigh, title="Bullish Consolidation High", color=color.gray, linewidth=1, style=plot.style_line)
What it does:
Plots the calculated RSI (blue) and its signal line (orange) with a thicker line for better visibility.
Draws horizontal lines for each of the key levels:
Overbought (red) and oversold (green).
Consolidation ranges (gray).
Why it matters:
Visual reference lines allow traders to quickly see when the RSI crosses important thresholds, aiding in decision-making.
7. Background Color Alerts
pinescript
Copy
Edit
bgcolor(rsiValue > rsiOverbought ? color.new(color.red, 90) : na)
bgcolor(rsiValue < rsiOversold ? color.new(color.green, 90) : na)
What it does:
Changes the background color of the RSI panel:
Red Background: When the RSI is above the overbought level (suggesting a potential sell or reversal zone).
Green Background: When the RSI is below the oversold level (suggesting a potential buy or reversal zone).
The color is made semi-transparent (90 out of 255 opacity) so it’s noticeable but not overwhelming.
Why it matters:
These visual cues help the trader quickly identify when the RSI is in an extreme zone, without having to inspect the numerical values closely.
8. Effectiveness and Time Frame Compatibility
Effectiveness:

Dynamic Adaptation: By adjusting both the period and the threshold levels based on the time frame, the indicator tailors its sensitivity to the market context.
Short-Term (Intraday): Uses a shorter period (RSI period 7) which is more sensitive to price changes.
Long-Term: Uses a longer period (RSI period 14) for a smoother signal.
Multiple Reference Levels: In addition to the classic overbought/oversold levels, the script includes consolidation and continuation levels. These can provide deeper insight into the momentum and potential reversals or continuations.
Visual Cues: The background color changes add an extra layer of immediate visual feedback.
Time Frame Compatibility:

Works on All Time Frames:
The script checks for specific conditions (daily, weekly, monthly, and specific intraday periods).
For time frames that don’t match these specific conditions, it defaults to a middle setting (RSI period 10, thresholds at 72/28, etc.).
Adaptive Nature: This makes it flexible for various types of traders—from day traders to swing traders to long-term investors—ensuring that the RSI indicator is tuned to the volatility and noise level typical of the chosen resolution.
Summary
Functionality:

Calculates an RSI whose parameters (length and threshold levels) dynamically adjust based on whether the chart is a long-term, short-term, or other time frame.
Provides additional plotted levels (consolidation and continuation) to help identify market conditions.
Uses background color changes as visual alerts when RSI reaches extreme conditions.
Effectiveness:

The dynamic adjustments can make the RSI more responsive to the particular market environment of different time frames.
Its effectiveness ultimately depends on the trading strategy and market conditions, but it offers a more tailored approach than a static RSI.
Time Frame Use:

Yes, it works in all time frames. Specific settings are applied for defined resolutions (daily, weekly, monthly, and 15, 60, 240 minutes). Other time frames use default parameters, making it broadly adaptable.
This detailed breakdown should help you understand how the script operates step by step, its intended functionality, and its adaptability across different time frames.

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.