RSI and ATR Trend Reversal SL/TP
Apr 18, 2024

The RSI and ATR Trend Reversal SL/TP indicator provides a dynamic trailing stop-loss and take-profit mechanism designed to adapt to rapid market rallies and reversals. By combining Relative Strength Index (RSI) and Average True Range (ATR) metrics, the tool generates a single trend-following line that helps traders identify potential exit points or trend shifts in volatile markets.
Usage
The Usage section focuses on how the dynamic band acts as a threshold for trend direction and risk management.
- Trend Identification: When the price (source) is above the plot, the indicator suggests a bullish trend, and the line functions as a dynamic trailing support. When the price is below the plot, it suggests a bearish trend, acting as trailing resistance.
- Reversal Trading: A crossover of the price through the indicator line signals a potential trend reversal. These points can be used as entry signals or as a signal to close existing positions.
- Risk Management: Because the calculation incorporates RSI speed and ATR volatility, the band tightens during high-velocity moves, allowing traders to capture profits during "blow-off" rallies or exit quickly when momentum stalls.
- Backtesting Calibration: Use the "Delay to prevent idealization" setting to ensure backtest results align with real-world execution, particularly when using sources other than the bar open.
Details
The script utilizes Heikin Ashi values for its internal calculations to smooth out price noise, though it plots relative to the user-selected source. The core logic involves a custom RSI level calculation (rsiLev) which mirrors upper and lower bands.
A unique aspect of this tool is its responsiveness to RSI changes; as RSI increases rapidly, the band adjusts proportionally to capture quick moves. It also integrates a volatility component by calculating the ATR-to-price ratio. To handle the dynamic nature of these calculations within Pine Script, the tool uses custom-built highestCustom and lowestCustom functions that allow for variable lookback lengths based on the time elapsed since the last trend crossover.
Settings
Main Settings
- Length: Determines the lookback period for both the RSI and ATR calculations.
- Multiplier: A scaling factor applied to the RSI and ATR components to widen or tighten the sensitivity of the trend line.
- Delay to prevent idealization: Adjusts the strategy entry offset. Set to 0 if the source is "Open"; set to 1 for other sources to avoid look-ahead bias in backtests.
- Minimum Difference: Acts as a safety floor/ceiling. It ensures the SL/TP band is at least a fixed percentage away from the source price (e.g., a setting of 10 ensures a 10% minimum buffer).
- Source Input: The price data point used for calculations (Close, Open, HL2, etc.).
FAQ
How do I use this as a Stop Loss?
You can treat the plotted line as your trailing stop. If you are in a long position, you would exit once the price crosses below the green line.
What markets is this optimized for?
While it can be used on any ticker, it was specifically tested on volatile equities like TSLA, AAPL, and NVDA on the 15-minute timeframe.
How can I access the RSI and ATR Trend Reversal SL/TP?
You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
Free indicator
Get free access to this indicator on the platforms below.
Unlock the entire LuxAlgo Library
Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.