OPEN-SOURCE SCRIPT
SuperTrend Recovery [LuxAlgo]

The SuperTrend Recovery indicator provides a modified version of the classic SuperTrend algorithm that incorporates a dynamic "recovery" mechanism designed to adjust the trailing stop when price action moves significantly against the current trend. This script aims to help traders manage volatile environments by tightening the trend band when the market experiences deep pullbacks without triggering a full trend reversal.
🔶 USAGE
The indicator can be used similarly to a standard SuperTrend to identify market direction and potential trailing stop-loss levels. However, the unique recovery logic allows for a more adaptive response to price deviations.
🔹 Trend Detection
🔹 Recovery Mechanism
In a standard SuperTrend, the band stays flat if price moves against the trend (but doesn't break it). In the SuperTrend Recovery version, if the price drops significantly below the "Switch Price" (for a bull trend) or rises above it (for a bear trend), the band begins to move toward the price based on the Recovery Alpha. This allows the trailing stop to "catch up" during high-volatility pullbacks, potentially securing a faster exit if the recovery fails.
🔶 DETAILS
The core of this indicator lies in its two-stage calculation: the Base SuperTrend and the Recovery Logic.
🔹 Base Logic
The indicator calculates a base upper and lower band using the Average True Range (ATR) multiplied by a user-defined factor. Under normal conditions, the band follows the classic rules: it can only move up during a bull trend and only down during a bear trend.
🔹 Recovery Logic
When price enters a "loss" state relative to the price where the trend initially started (the Switch Price), the script checks if the deviation exceeds the Recovery Threshold.
If the threshold is met, the band is calculated as an exponential moving average (EMA) of the current price and the previous band value, weighted by the Recovery Alpha:
Pine Script®
This creates a "tapering" effect where the band aggressively tightens toward the price during deep retracements, helping to mitigate drawdown by providing an earlier exit signal compared to the standard static band.
🔶 SETTINGS
🔹 Supertrend Settings
🔹 Recovery Logic
🔹 Visualization
🔶 USAGE
The indicator can be used similarly to a standard SuperTrend to identify market direction and potential trailing stop-loss levels. However, the unique recovery logic allows for a more adaptive response to price deviations.
🔹 Trend Detection
- When the price is above the band, the indicator signals a BULL trend.
- When the price is below the band, the indicator signals a BEAR trend.
- Trend switches are marked with "BULL" or "BEAR" labels and a colored circle at the switch point.
🔹 Recovery Mechanism
In a standard SuperTrend, the band stays flat if price moves against the trend (but doesn't break it). In the SuperTrend Recovery version, if the price drops significantly below the "Switch Price" (for a bull trend) or rises above it (for a bear trend), the band begins to move toward the price based on the Recovery Alpha. This allows the trailing stop to "catch up" during high-volatility pullbacks, potentially securing a faster exit if the recovery fails.
🔶 DETAILS
The core of this indicator lies in its two-stage calculation: the Base SuperTrend and the Recovery Logic.
🔹 Base Logic
The indicator calculates a base upper and lower band using the Average True Range (ATR) multiplied by a user-defined factor. Under normal conditions, the band follows the classic rules: it can only move up during a bull trend and only down during a bear trend.
🔹 Recovery Logic
When price enters a "loss" state relative to the price where the trend initially started (the Switch Price), the script checks if the deviation exceeds the Recovery Threshold.
If the threshold is met, the band is calculated as an exponential moving average (EMA) of the current price and the previous band value, weighted by the Recovery Alpha:
targetBand = alpha * close + (1.0 - alpha) * prevBand
This creates a "tapering" effect where the band aggressively tightens toward the price during deep retracements, helping to mitigate drawdown by providing an earlier exit signal compared to the standard static band.
🔶 SETTINGS
🔹 Supertrend Settings
- ATR Length: The lookback period used to calculate market volatility.
- Base Multiplier: The factor applied to the ATR to determine the distance of the band from the price.
🔹 Recovery Logic
- Recovery Alpha (%): Determines how quickly the band adjusts toward the price when the recovery logic is active. Higher values make the band more reactive.
- Recovery Threshold (xATR): The distance (in ATR units) the price must deviate from the switch price before the recovery mechanism activates.
🔹 Visualization
- Show Gradient Fills: Toggles the background gradient between the price (source) and the SuperTrend band.
- Show Signal Labels: Toggles the "BULL" and "BEAR" labels at trend reversal points.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que la republicación del código está sujeta a nuestras Normas internas.
Build your own edge with AI: luxalgo.com
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como asesoramiento o recomendaciones financieras, de inversión, de trading o de otro tipo proporcionadas o respaldadas por TradingView. Más información en Condiciones de uso.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que la republicación del código está sujeta a nuestras Normas internas.
Build your own edge with AI: luxalgo.com
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como asesoramiento o recomendaciones financieras, de inversión, de trading o de otro tipo proporcionadas o respaldadas por TradingView. Más información en Condiciones de uso.