Relative Strength Index - Divergences - Libertus

Hello all,

To ease everyone's trading experience I made this script which colors RSI overbought and oversold conditions and as a bonus displays bullish or bearish divergences in last 50 candles (by default, you can change it).
Script is open source, part of code is from Trading View examples. If you have suggestions or you already made some improvements, please report in comment.

Happy trading and good luck!
Release Notes: New version 2.0 of script. Most of logic is updated and upgraded.
Now divergences are shown for whole history.

Be warned that I increased lookback period to 90 bars by default. This is good for time frames up to 4H, even 4H in on the edge here.
Higher time frames then 4H probably need lower lookback period.

Please report any problems you encounter.
Release Notes: TD bugged out when publishing, repeating update.
Release Notes: Minor update: Added ability to set alerts per user request.
Release Notes: Minor update: fixed bug where divergences in some rare cases didn't show, usually on very low time frames

If you find this useful and want to revard me:
BTC TIP JAR: 1i7nojAjxFuyFwvnZx6hbXBTLkWaUjZ8C

Or visit my friends at CryptoCurrently community:
Release Notes: Update:
  • ability to remove pivots
  • ability to display smaller/shorter labels
Release Notes: What new:
  • adapted script to new pine language version (v4)
  • removed 8 n/a value that were cluttering indicator interface next to RSI value (only possible with v4 pine language)
  • added option to have colored indicator background instead of BULL/BEAR labels

If you don't want separate indicator for RSI divergences, you can use my RSI Divergences - Candle edition:

If you want OBV divergences script, check out:
Release Notes: Small fix: Pivots didn't hide if you checked both "Hide pivot" and "Color background".
Ta bort från favoritskript Lägg till som favoritskript


why i dint see bull and bear show, only have pivot.
Hello Libertus, Thanks for the great code. I want lines to be drawn on RSI connecting pivot and Bull or bear points. Can you help me as I am poor at coding.
Thanks for sharing.What does Pivot represents in RSI ?
Libertus mithun1888
@mithun1888, Pivot is highest or lowest RSI in lookback period.
Would be nice if you added "realtime" checkbox, so, it wouldnt displace labels (people think that pivots would have been triggered on those same tops where labels are shown). However, labels are shown after 2 bars (using negative displace). So, "realtime" checkbox should be used not to mislead and see the labels on same bar when they were detected.
please update.
t_todua t_todua
Similarly, instead of negative displace for plots, use barstate.iscompleted variable to plot on same bar.
Libertus t_todua
@t_todua, That's why it's open source. If someone wants, he/she can just remove -2 from "bar_index-2" and it will plot on current bar.
hey bud, is there a way to add an alert for the pivots? I cannot find it. Im implementing this in part of my strat. If anything good comes out of it your getting a slice of the pie. FOR REAL!!!
Please add an option to choose to show the labels on current bar, instead of displaced index (which is misleading practice in general).
so, if we get confirmation for pivots at this bar, we should have labels at this bar, not in past bars displaced.
Libertus t_todua
@t_todua hello,
What would that accomplish? It would certainly confuse users since markers wouldn't be on bars that are actually diverging.
Hem Aktie-screener Forex-screener Krypto-screener Ekonomisk kalender Hur det fungerar Diagramfunktioner Priser Tipsa en vän Ordningsregler Hjälpcenter Webbsidor och mäklarlösningar Widgets Diagramlösningar Lightweight Charting Library Blogg och nyheter Twitter
Profil Profilinställningar Konto och fakturering Tipsa en vän Mina kölappar Hjälpcenter Publicerade idéer Följare Följer Privata meddelanden Chatt Logga ut