All indicators

RSI Divergence Indicator strategy

Apr 27, 2020

Static chart image
SignalsOscillatorsDivergencesTrailing-StopVolatility

The RSI Divergence Indicator strategy tool automates the detection of regular and hidden divergences between price and the Relative Strength Index (RSI) to identify potential market reversals and trend continuations.

Usage

The Usage section describes how the script can be used, examples should be provided in this section. This tool functions as both a visual indicator and a backtesting strategy.

  • Long Entries: The strategy initiates a long position when a regular bullish divergence (lower low in price, higher low in RSI) or a hidden bullish divergence (higher low in price, lower low in RSI) is detected.
  • Exit Conditions: Users can exit positions based on a specific RSI overbought threshold (e.g., RSI crossing above 80) or when a bearish divergence occurs.
  • Risk Management: The script includes optional trailing stop-loss mechanisms based on ATR or percentage-based calculations to protect capital during trending moves.

Details

The script utilizes pivot point detection (Lookback Left and Right) to identify peaks and troughs in both price action and the RSI oscillator. By comparing the relationship between these pivots, the script identifies four distinct types of divergence:

  1. Regular Bullish: Indicates a potential reversal from a downtrend to an uptrend.
  2. Hidden Bullish: Indicates trend continuation during an uptrend.
  3. Regular Bearish: Indicates a potential reversal from an uptrend to a downtrend.
  4. Hidden Bearish: Indicates trend continuation during a downtrend.

The script uses a "Lookback Range" to ensure that the divergence is identified within a specific historical window, preventing the detection of outdated or irrelevant price patterns.

Settings

RSI Settings

  • RSI Period: Sets the number of bars used to calculate the RSI (default is 9).
  • RSI Source: Determines the price data used for the RSI calculation (e.g., Close).

Pivot Settings

  • Pivot Lookback Right: The number of bars to the right of a pivot point required for confirmation.
  • Pivot Lookback Left: The number of bars to the left of a pivot point required for confirmation.
  • Max/Min of Lookback Range: Defines the window of bars within which the two pivots must appear to qualify as a divergence.

Strategy Settings

  • Take Profit at RSI Level: The RSI value at which the strategy will automatically close a long position.
  • Trailing StopLoss Type: Choose between ATR, Percentage-based, or None.
  • Stop Loss%: The percentage distance for the trailing stop loss.
  • ATR Length/Multiplier: Parameters used to calculate the volatility-based trailing stop.

Visibility Settings

  • Plot Bullish/Hidden Bullish/Bearish/Hidden Bearish: Toggle checkboxes to show or hide specific divergence types on the chart.

FAQ

How do I interpret the "H Bull" and "H Bear" labels? "H Bull" stands for Hidden Bullish divergence, suggesting a continuation of the current uptrend, while "H Bear" stands for Hidden Bearish divergence, suggesting a continuation of the current downtrend.

Why does the indicator wait a few bars before showing a divergence label? The script uses pivot lookback settings; a label will only appear once the "Lookback Right" number of bars has passed to confirm that a high or low point has actually been formed.

How can I access this tool? 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.

TradingView
NinjaTrader
MetaTrader 4/5

Unlock the entire LuxAlgo Library

Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.