CryptoRygel

[Rygel] RSI with divergences and alerts

CryptoRygel מעודכן   
This indicator is a reliable, exhaustive, instant, simple divergence detector for the RSI oscillator.

I've struggled for months to find a RSI divergence indicator I can rely on, I've tinkered with the ones I found and never was satisfied by the final result. For all of them important divergences were not shown, for some divergences was shown too late, for others divergence lines was not drawn, some even shown some strange exotic divergences... I played will all the parameters and something was always wrong or missing at the end.

So I finally decided to write my own divergence algorithm and to create my own indicator. After a few attempts, here's the result.

At first. Please find below a quick comparison of this indicator with some of the most popular RSI divergence indicators on TradingView. I've hidden their names as it's not my intention to show them in a bad light. These indicators are great and some of you may even find them better than this one, they were just not what I was looking for.


You will most likely notice all of them are missing divergences but not always the same. You'll have to combine all of them to get (almost) all the divergences.

When I built this indicator, my objectives were to create one that is :

  • Reliable. I didn't want to have to double-check an indicator to make sure it's doing what I expect it to do. I want to be able to look at it for one second and know I can rely on it.
  • Exhaustive. I didn't want to have to rely on multiple indicators to be sure I'm not missing a divergence.
  • Instant. I wanted the divergences to be shown as soon as soon as they form and not after a pivot is confirmed. For some indicator, when the divergence is displayed, it's already too late to act on it.
  • Simple. I wanted my indicator to be clean, readable and not visually aggressive. The main objective of this indicator is to show divergences and I didn't want to visually overload it with unrequired information.
I wanted my indicator to be a simple as possible, nonetheless you'll find a few parameters to tinker with. Many of them will need no explanation but here's the list.

  • Show regular divergences: enabled by default.
  • Show hidden divergences: disabled by default for readability. I try to keep the indicator as clean as possible by default.
  • Bullish regular divergence color: no explanation needed I suppose.
  • Bullish hidden divergence color: same.
  • Bearish regular divergence color: ditto.
  • Bearish hidden divergence color: uhh.
  • Show overbought and oversell backgrounds: when RSI is oversold or overbought, the background color changes to red or green. The indicator uses two levels of oversold/overbought. When the RSI is strongly oversold/overbought the background color gets brighter. You can configure these levels in the advanced parameters.
Advanced parameters:

  • RSI source: "close" by default.
  • RSI length: 14 by default.
  • Show divergences before pivot confirmation: enabled by default. Divergences will appear as soon as possible, before the pivot is confirmed by another candlestick. Unconfirmed divergences will appear as dashed lines then disappear if not confirmed or turn to solid lines if confirmed. This may create false positives with alerts as the divergence may disappear.
  • Minimum bars to check: 5 by default. As this indicator detects absolutely all the divergences, some may be insignificant and it may become unreadable without some filtering. If you want to see absolutely all the divergences, you may lower this value. Please note TradingView limits to 50 how many lines are displayed at the same time on an indicator. So when you display more divergences, some in the past disappear. It's not usually an issue but if you scroll back in time, divergences will stop to show at one point in the past.
  • Maximum bars to check: 50 by default. Divergences may go far in the past, this parameters limit how old a divergence may be. You can higher it to show more divergences.
  • Use limits for divergences: enabled by default. Don't show divergences when they are above or below a threshold. Another filtering options to make sure only relevant divergences are shown.
  • Minimum value for bearish divergence: 40 by default.
  • Maximum value for bullish divergence: 60 by default.
  • Show pivots: disabled by default. Show the pivot points used for divergence detections.
  • Oversold level: 30 by default. A red background is shown when the indicator goes below this level.
  • Overbought level: 70 by default. A green background is shown when the indicator goes above this level.
  • Strongly oversold level: 20 by default. A brighter red background is shown when the indicator goes below this level.
  • Strongly overbought level: 80 by default. A brighter green background is shown when the indicator goes above this level.
  • Show moving average: disabled by default. Add a moving average to the indicator.
  • Moving average type: SMA by default. You may choose between Bollinger Bands, EMA, SMA, SMMA (RMA), VWMA and WMA.
  • Moving average length: 14 by default.
  • Bollinger Band standard deviation 2 by default.
This indicator has the following alerts:

  • Any divergence
  • Bearish divergence
  • Bullish divergence
  • Regular bearish divergence
  • Regular bullish divergence
  • Hidden bearish divergence
  • Hidden bullish divergence
Please note TradingView limits for performance reason to 50 the number of lines you can display on an indicator at the same time. So when you scroll back in time, at one point divergences will stop to show. If you want to see divergences far in the past, you may need to use the replay feature or to configure stronger filtering settings.

I hope you'll enjoy this indicator as much as I do! :)
Feel free to comment if you experience a bug or if an important feature is missing for you. (Please note the core of this indicator is divergence detection, I want to keep it simple so I will probably not add many unrelated features to it.)
הערות שחרור:
Increased default maximum bars to check to 75.

A few significant divergences where missing with the previous default (50) in the comparison picture and I want the default configuration to be as reliable as possible.

Here's the updated comparison with the new default.

הערות שחרור:
Increased maximum visible divergence lines from 50 to 500.
I've just discovered you can increase the maximum visible line count up to 500. By default TradingView limits it to 50. This solves almost all the issues caused by the 50 lines limitation I talked about in this indicator description. Hurray! :)
הערות שחרור:
Final V1 release. Please upgrade to Rygel RSI V2 to get the latest updates and improvements.
הערות שחרור:
I'm still learning the TradingView publication process. I've tried to create a V2 release of this script to update its description but it's not allowed, so I'm merging the changes here.

Added "hypothetical divergences" option to show divergences before a pivot is forming, added new alerts for confirmed, confirming and unconfirmed divergences, decreased "minimum bars to check" to 3 and increased "maximum bars to check" to 100.

Please find below the latest updated algorithm comparison:


And the updated option user guide:

  • Show regular divergences: enabled by default.
  • Show hidden divergences: disabled by default for readability. I try to keep the indicator as clean as possible by default.
  • Bullish regular divergence color: no explanation needed I suppose.
  • Bullish hidden divergence color: same.
  • Bearish regular divergence color: ditto.
  • Bearish hidden divergence color: uhh.
  • Show overbought and oversell backgrounds: when RSI is oversold or overbought, the background color changes to red or green. The indicator uses two levels of oversold/overbought. When the RSI is strongly oversold/overbought the background color gets brighter. You can configure these levels in the advanced parameters.

Advanced parameters:

  • RSI source: "close" by default.
  • RSI length: 14 by default.
  • Show forming divergences, before pivot confirmation: enabled by default. Divergences will appear as soon as possible, before the pivot is confirmed by another candlestick. Unconfirmed divergences will appear as dashed lines then disappear if not confirmed or turn to solid lines if confirmed. This may create false positives with alerts as the divergence may disappear.
  • Show hypothetical divergences, before pivot creation disabled by default. Divergences will appear even before a pivot is forming. Lot of false positives. Only for educational purposes. Don't take trading decisions based on hypothetical divergences. Hypothetical divergences appears as white dashed lines.
  • Minimum bars to check: 3 by default. As this indicator detects absolutely all the divergences, some may be insignificant and it may become unreadable without some filtering. If you want to see less divergences, you may increase this value.
  • Maximum bars to check: 100 by default. Divergences may go far in the past, this parameters limit how old a divergence may be. You can decrease it to show less divergences.
  • Use limits for divergences: enabled by default. Don't show divergences when they are above or below a threshold. Another filtering options to make sure only relevant divergences are shown. Mostly useful for hidden divergences.
  • Minimum value for bearish divergence: 40 by default.
  • Maximum value for bullish divergence: 60 by default.
  • Show pivots: disabled by default. Show the pivot points used for divergence detections.
  • Oversold level: 30 by default. A red background is shown when the indicator goes below this level.
  • Overbought level: 70 by default. A green background is shown when the indicator goes above this level.
  • Strongly oversold level: 20 by default. A brighter red background is shown when the indicator goes below this level.
  • Strongly overbought level: 80 by default. A brighter green background is shown when the indicator goes above this level.
  • Show moving average: disabled by default. Add a moving average to the indicator.
  • Moving average type: SMA by default. You may choose between Bollinger Bands , EMA , SMA , SMMA (RMA), VWMA and WMA .
  • Moving average length: 14 by default.
  • Bollinger Band standard deviation: 2 by default.

This indicator now offers the following alerts:

Confirmed divergences: pivot is confirmed, bar is closed, divergence is real and final.

  • Confirmed divergence
  • Confirmed regular divergence
  • Confirmed hidden divergence
  • Confirmed bullish divergence
  • Confirmed bearish divergence
  • Confirmed regular bullish divergence
  • Confirmed regular bearish divergence
  • Confirmed hidden bullish divergence
  • Confirmed hidden bearish divergence

Confirming divergences: pivot is formed but the bar is not yet closed, divergence may disappear until it is. You will received false positive alerts.

  • Confirming divergence
  • Confirming regular divergence
  • Confirming hidden divergence
  • Confirming bullish divergence
  • Confirming bearish divergence
  • Confirming regular bullish divergence
  • Confirming regular bearish divergence
  • Confirming hidden bullish divergence
  • Confirming hidden bearish divergence

Unconfirmed divergences: pivot doesn't fully exist yet, divergence may never be confirmed and disappear. Two bars have yet to close for the divergence to become real and final. You will receive many false positive alerts.

  • Unconfirmed divergence
  • Unconfirmed regular divergence
  • Unconfirmed hidden divergence
  • Unconfirmed bullish divergence
  • Unconfirmed bearish divergence
  • Unconfirmed regular bullish divergence
  • Unconfirmed regular bearish divergence
  • Unconfirmed hidden bullish divergence
  • Unconfirmed hidden bearish divergence
הערות שחרור:
  • Added a new setting option: "When divergences are similar, only keep the longest one".
    By default, when multiple divergences end at the same point, only the longest one is displayed. When you disable this setting, all the divergences ending at the same point become visible.
    This setting is enabled by default for readability. If you disable it, divergences may clutter the graph. It will also reduce how far in the past divergences are shown because of the TradingView 500 lines limitation.
    Use this option only if you want to see absolutely all of the divergences.
  • Increased maximum allowed value for "Divergence maximum bars" from 100 to 200. 100 is still the default "maximum bars" setting but you can now increase it up to 200.
  • When a regular and a hidden divergence end at the same point, only the regular one was displayed. Both are now visible.
  • Pivot colors were inverted. It is now fixed.
הערות שחרור:
Improved pivot price detection. Price and RSI pivots are not always on the exact same bar, sometimes there is a 1 bar offset. Price is now selected to always be the lowest/highest rather than the one exactly on the RSI pivot bar.
הערות שחרור:
Improved divergence detection. (I found a few edge cases where my divergence algorithm couldn't detect some divergences because of malformed pivots. Though these divergences were real, their pivot couldn't be validated and so the divergence didn't appear. So I wrote a new pivot detection algorithm that can handle these pivots.)
הערות שחרור:
Increased default maximum bars to check from 100 to 150 and increased absolute maximum to 250. Previous default setting was missing a major daily divergence on Bitcoin.
הערות שחרור:
Finally increased it to 180. Just to be safe.
הערות שחרור:
Fixed a condition where alert for unconfirmed bearish divergences would not be sent.
הערות שחרור:
Fixed a rare issue with hypothetical divergences hiding confirmed ones.
הערות שחרור:
Fixed a condition where some alerts were not sent when hypothetical divergences were enabled
הערות שחרור:
  • Added a "Show internal divergences" option. When enabled the divergences starting at an intermediate pivot (i.e. a pivot between two other pivots inside a single impulsive move) are displayed. This was the default behavior before the introduction of this feature. This is now disabled by default, to only show the most significant divergences.

    With internal divergences disabled:

    With internal divergences enabled:

  • Added overbought and oversold alerts, for entering and exiting the areas.

  • To improve readability, hidden bullish divergences are now blue and hidden bearish divergences orange. Hidden and regular divergences should be easier and faster to identify.


  • Added a fill RSI display option under the Style tab.


  • Fixed a condition where a divergence could be missing when too many pivots were detected.
הערות שחרור:
Improved reliability. A divergence won't show anymore if a price pivot breaks the divergence line. For instance, when you draw a bullish regular divergence line from price A to price B, if an intermediate price pivot breaks the divergence line (i.e. if the price of the pivot is below the divergence line), the divergence won't show anymore.
הערות שחרור:
Improved pivot detection. Some pivots are now better positioned.

Before / after

סקריפט מוגן
סקריפט זה פורסם במקור סגור ותוכל להשתמש בו באופן חופשי. אתה יכול להגדירו כמועדף כדי להשתמש בו בגרף. אינך יכול להציג או לשנות את קוד המקור שלו.
כתב ויתור

המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.

רוצה להשתמש בסקריפ זה בגרף?