OPEN-SOURCE SCRIPT
Telah dikemas kini

Parameter Free RSI [InvestorUnknown]

2 002
The Parameter Free RSI (PF-RSI) is an innovative adaptation of the traditional Relative Strength Index (RSI), a widely used momentum oscillator that measures the speed and change of price movements. Unlike the standard RSI, which relies on a fixed lookback period (typically 14), the PF-RSI dynamically adjusts its calculation length based on real-time market conditions. By incorporating volatility and the RSI's deviation from its midpoint (50), this indicator aims to provide a more responsive and adaptable tool for identifying overbought/oversold conditions, trend shifts, and momentum changes. This adaptability makes it particularly valuable for traders navigating diverse market environments, from trending to ranging conditions.

PF-RSI offers a suite of customizable features, including dynamic length variants, smoothing options, visualization tools, and alert conditions.

Key Features

1. Dynamic RSI Length Calculation
The cornerstone of the PF-RSI is its ability to adjust the RSI calculation period dynamically, eliminating the need for a static parameter. The length is computed using two primary factors:
  • Volatility: Measured via the standard deviation of past RSI values.
  • Distance from Midpoint: The absolute deviation of the RSI from 50, reflecting the strength of bullish or bearish momentum.


The indicator offers three variants for calculating this dynamic length, allowing users to tailor its responsiveness:
  • Variant I (Aggressive): Increases the length dramatically based on volatility and a nonlinear scaling of the distance from 50. Ideal for traders seeking highly sensitive signals in fast-moving markets.
  • Variant II (Moderate): Combines volatility with a scaled distance from 50, using a less aggressive adjustment. Strikes a balance between responsiveness and stability, suitable for most trading scenarios.
  • Variant III (Conservative): Applies a linear combination of volatility and raw distance from 50. Offers a stable, less reactive length adjustment for traders prioritizing consistency.


Pine Script®
// Function that returns a dynamic RSI length based on past RSI values // The idea is to make the RSI length adaptive using volatility (stdev) and distance from the RSI midpoint (50) // Different "variant" options control how aggressively the length changes parameter_free_length(free_rsi, variant) => len = switch variant // Variant I: Most aggressive adaptation // Uses standard deviation scaled by a nonlinear factor of distance from 50 // Also adds another distance-based term to increase length more dramatically "I" => math.ceil( ta.stdev(free_rsi, math.ceil(free_rsi)) * math.pow(1 + (math.ceil(math.abs(50 - (free_rsi[1] - 50))) / 100), 2) ) + ( math.ceil(math.abs(free_rsi[1] - 50)) * (1 + (math.ceil(math.abs(50 - (free_rsi[1] - 50))) / 100)) ) // Variant II: Moderate adaptation // Adds the standard deviation and a distance-based scaling term (less nonlinear) "II" => math.ceil( ta.stdev(free_rsi, math.ceil(free_rsi)) + ( math.ceil(math.abs(free_rsi[1] - 50)) * (1 + (math.ceil(math.abs(50 - (free_rsi[1] - 50))) / 100)) ) ) // Variant III: Least aggressive adaptation // Simply adds standard deviation and raw distance from 50 (linear scaling) "III" => math.ceil( ta.stdev(free_rsi, math.ceil(free_rsi)) + math.ceil(math.abs(free_rsi[1] - 50)) )


2. Smoothing Options
To refine the dynamic RSI and reduce noise, the PF-RSI provides smoothing capabilities:
  • Smoothing Toggle: Enable or disable smoothing of the dynamic length used for RSI.
  • Smoothing MA Type for RSI MA: Choose between SMA and EMA
  • Smoothing Length Options for RSI MA:
  • Full: Uses the entire calculated dynamic length.
  • Half: Applies half of the dynamic length for smoother output.
  • SQRT: Uses the square root of the dynamic length, offering a compromise between responsiveness and smoothness.


The smoothed RSI is complemented by a separate moving average (MA) of the RSI itself, further enhancing signal clarity.

syot kilat
syot kilat

3. Visualization Tools
The PF-RSI includes visualization options to help traders interpret market conditions at a glance.

Plots:
  • Dynamic RSI: Displayed as a white line, showing the adaptive RSI value.
  • RSI Moving Average: Plotted in yellow, providing a smoothed reference for trend and momentum analysis.
  • Dynamic Length: A secondary plot (in faint white) showing how the calculation period evolves over time.
  • Histogram: Represents the RSI’s position relative to 50, with color gradients.
  • Fill Area: The space between the RSI and its MA is filled with a gradient (green for RSI > MA, red for RSI < MA), highlighting momentum shifts.


Customizable bar colors on the price chart reflect trend and momentum:
  • Trend (Raw RSI): Green (RSI > 50), Red (RSI < 50).
  • Trend (RSI MA): Green (MA > 50), Red (MA < 50).
  • Trend (Raw RSI) + Momentum: Adds momentum shading (lighter green/red when RSI and MA diverge).
  • Trend (RSI MA) + Momentum: Similar, but based on the MA’s trend.
  • Momentum: Green (RSI > MA), Red (RSI < MA).
  • Off: Disables bar coloring.


Intrabar Updating: Optional real-time updates within each bar for enhanced responsiveness.

4. Alerts
The PF-RSI supports customizable alerts to keep traders informed of key events.

Trend Alerts:
  • Raw RSI: Triggers when the RSI crosses above (uptrend) or below (downtrend) 50.
  • RSI MA: Triggers when the moving average crosses 50.
  • Off: Disables trend alerts.

Momentum Alerts:
  • Triggers when the RSI crosses its moving average, indicating rising (RSI > MA) or declining (RSI < MA) momentum.


Alerts are fired once per bar close, with descriptive messages including the ticker symbol (e.g., "[PF-RSI] Uptrend on: AAPL").

How It Works
The PF-RSI operates in a multi-step process:

Initialization
  • On the first run, it calculates a standard RSI with a 14-period length to seed the dynamic calculation.

Dynamic Length Computation
  • Once seeded, the indicator switches to a dynamic length based on the selected variant, factoring in volatility and distance from 50.
  • If smoothing is enabled, the length is further refined using an SMA.

RSI Calculation
  • The adaptive RSI is computed using the dynamic length, ensuring it reflects current market conditions.

Moving Average
  • A separate MA (SMA or EMA) is applied to the RSI, with a length derived from the dynamic length (Full, Half, or SQRT).

Visualization and Alerts
  • The results are plotted, and alerts are triggered based on user settings.


This adaptive approach minimizes lag in fast markets and reduces false signals in choppy conditions, offering a significant edge over fixed-period RSI implementations.

Why Use PF-RSI?
The Parameter Free RSI stands out by eliminating the guesswork of selecting an RSI period. Its dynamic length adjusts to market volatility and momentum, providing timely signals without manual tweaking.





Nota Keluaran
Fix: math.abs() was placed at wrong place in dynamic length calculation
Nota Keluaran
Removed "long-bias" in ta.stdev() by reducing RSI by 50

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.