OPEN-SOURCE SCRIPT
Aggiornato Contrarian RSI

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

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:

Plotted on Chart:

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.
Pairs nicely with Contrarian 100 MA (optional hide/unhide buy/sell signals)

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:
Plotted on Chart:
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.
Note di rilascio
Improved entry logicWAS:
// --- 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)
Note di rilascio
Confirming the indicator visual published properly. Note di rilascio
Updated Visual to MCD tickerNote di rilascio
Blue Dot Tracking and Hold Visual AlertThis update enhances the Contrarian RSI with a blue dot tracking system to identify significant bearish trends and provide opportunities for a strategic hold. When three or more consecutive buy signals (blue dots, triggered by qrsi_ma crossing above the oversold level) occur, it indicates a strong bearish trend. In such cases, a "Hold Investment" notice is displayed, advising investors to retain their position until the price exceeds their initial entry price, rather than exiting on the first sell signal (white dot).
A new dynamic table on the right displays the current count of consecutive blue dots and an action recommendation: "Hold Investment" for three or more blue dots (with a yellow background) or "Flip Investment" otherwise (with a green background). This feature is particularly useful for contrarian traders aiming to maximize returns by holding through temporary recoveries in strong bearish trends.
Additionally, the reliability of entry and exit signals has been strengthened by ensuring non-repainting logic, using confirmed ta.crossunder and ta.crossover conditions for qrsi_ma relative to oversold and overbought levels, providing more consistent and trustworthy signals for trading decisions.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.