OPEN-SOURCE SCRIPT
Telah dikemas kini

Contrarian RSI

168
Contrarian RSI Indicator

Pairs nicely with Contrarian 100 MA (optional hide/unhide buy/sell signals)
Contrarian 100 MA


Description
The Contrarian RSI is a momentum-based technical indicator designed to identify potential reversal points in price action by combining a unique RSI calculation with a predictive range model inspired by the "Contrarian 5 Levels" logic. Unlike traditional RSI, which measures price momentum based solely on price changes, this indicator integrates a smoothed, weighted momentum calculation and predictive price ranges to generate contrarian signals. It is particularly suited for traders looking to capture reversals in trending or range-bound markets.
This indicator is versatile and can be used across various timeframes, though it performs best on higher timeframes (e.g., 1H, 4H, or Daily) due to reduced noise and more reliable signals. Lower timeframes may require additional testing and careful parameter tuning to optimize performance.

How It Works
The Contrarian RSI combines two primary components:
Predictive Ranges (5 Levels Logic): This calculates a smoothed price average that adapts to market volatility using an ATR-based mechanism. It helps identify significant price levels that act as potential support or resistance zones.

Contrarian RSI Calculation: A modified RSI calculation that uses weighted momentum from the predictive ranges to measure buying and selling pressure. The result is smoothed and paired with a user-defined moving average to generate clear signals.

The indicator generates buy (long) and sell (exit) signals based on crossovers and crossunders of user-defined overbought and oversold levels, making it ideal for contrarian trading strategies.
Calculation Overview
Predictive Ranges (5 Levels Logic):
Uses a custom function (pred_ranges) to calculate a dynamic price average (avg) based on the ATR (Average True Range) multiplied by a user-defined factor (mult).

The average adjusts only when the price moves beyond the ATR threshold, ensuring responsiveness to significant price changes while filtering out noise.

This calculation is performed on a user-specified timeframe (tf5Levels) for multi-timeframe analysis.

Contrarian RSI:
Compares consecutive predictive range values to calculate gains (g) and losses (l) over a user-defined period (crsiLength).

Applies a Gaussian weighting function (weight = math.exp(-math.pow(i / crsiLength, 2))) to prioritize recent price movements.

Computes a "wave ratio" (net_momentum / total_energy) to normalize momentum, which is then scaled to a 0–100 range (qrsi = 50 + 50 * wave_ratio).

Smooths the result with a 2-period EMA (qrsi_smoothed) for stability.

Moving Average:
Applies a user-selected moving average (SMA, EMA, WMA, SMMA, or VWMA) with a customizable length (maLength) to the smoothed RSI (qrsi_smoothed) to generate the final indicator value (qrsi_ma).

Signal Generation:
Long Entry: Triggered when qrsi_ma crosses above the oversold level (oversoldLevel, default: 1).

Long Exit: Triggered when qrsi_ma crosses below the overbought level (overboughtLevel, default: 99).

Entry and Exit Rules
Long Entry: Enter a long position when the Contrarian RSI (qrsi_ma) crosses above the oversold level (default: 1). This suggests the asset is potentially oversold and due for a reversal.

Long Exit: Exit the long position when the Contrarian RSI (qrsi_ma) crosses below the overbought level (default: 99), indicating a potential overbought condition and a reversal to the downside.

Customization: Adjust overboughtLevel and oversoldLevel to fine-tune sensitivity. Lower timeframes may benefit from tighter levels (e.g., 20 for oversold, 80 for overbought), while higher timeframes can use extreme levels (e.g., 1 and 99) for stronger reversals.

Timeframe Considerations
Higher Timeframes (Recommended): The indicator is optimized for higher timeframes (e.g., 1H, 4H, Daily) due to its reliance on predictive ranges and smoothed momentum, which perform best with less market noise. These timeframes typically yield more reliable reversal signals.

Lower Timeframes: The indicator can be used on lower timeframes (e.g., 5M, 15M), but signals may be noisier and require additional confirmation (e.g., from price action or other indicators). Extensive backtesting and parameter optimization (e.g., adjusting crsiLength, maLength, or mult) are recommended for lower timeframes.

Inputs
Contrarian RSI Length (crsiLength): Length for RSI momentum calculation (default: 5).

RSI MA Length (maLength): Length of the moving average applied to the RSI (default: 1, effectively no MA).

MA Type (maType): Choose from SMA, EMA, WMA, SMMA, or VWMA (default: SMA).

Overbought Level (overboughtLevel): Upper threshold for exit signals (default: 99).

Oversold Level (oversoldLevel): Lower threshold for entry signals (default: 1).

Plot Signals on Main Chart (plotOnChart): Toggle to display signals on the price chart or the indicator panel (default: false).

Plotted on Lower:
syot kilat

Plotted on Chart:
syot kilat

5 Levels Length (length5Levels): Length for predictive range calculation (default: 200).

Factor (mult): ATR multiplier for predictive ranges (default: 6.0).

5 Levels Timeframe (tf5Levels): Timeframe for predictive range calculation (default: chart timeframe).

Visuals
Contrarian RSI MA: Plotted as a yellow line, representing the smoothed Contrarian RSI with the applied moving average.

Overbought/Oversold Lines: Red line for overbought (default: 99) and green line for oversold (default: 1).

Signals: Blue circles for long entries, white circles for long exits. Signals can be plotted on the main chart (plotOnChart = true) or the indicator panel (plotOnChart = false).

Usage Notes
Use the indicator in conjunction with other tools (e.g., support/resistance, trendlines, or volume) to confirm signals.

Test extensively on your chosen timeframe and asset to optimize parameters like crsiLength, maLength, and mult.

Be cautious with lower timeframes, as false signals may occur due to market noise.

The indicator is designed for contrarian strategies, so it works best in markets with clear reversal patterns.

Disclaimer
This indicator is provided for educational and informational purposes only. Always conduct thorough backtesting and risk management before using any indicator in live trading. The author is not responsible for any financial losses incurred.

Nota Keluaran
Improved entry logic
WAS:
// --- Signal Logic ---
long_entry = ta.crossover(qrsi_ma, oversoldLevel)
long_exit = ta.crossunder(qrsi_ma, overboughtLevel)

IS NOW:
// --- Signal Logic ---
long_entry = ta.crossunder(qrsi_ma, oversoldLevel)
long_exit = ta.crossover(qrsi_ma, overboughtLevel)
Nota Keluaran
Confirming the indicator visual published properly.
Nota Keluaran
Updated Visual to MCD ticker

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.