How can I programmatically detect bullish and bearish RSI divergences?

A bullish divergence occurs when the underlying security makes a lower low and RSI forms a higher low. RSI does not confirm the lower low and this shows strengthening momentum.

A bearish divergence forms when the security records a higher high and RSI forms a lower high. RSI does not confirm the new high and this shows weakening momentum.

enter image description here


I was searching for answers to the same question and came across your question.

After some thought and research, here is the plan I have developed. I will be working in Python.

  1. Calculate relative maxima and minima with SciPy.
  2. Calculate RSI at those points using lib-ta.
  3. For each pair of lows and highs, compare the change in price with the difference in RSI.

I'm completely new to technical analysis, so in case I have made any oversights, feedback would be greatly appreciated. I wanted to ask about your programming language and data format, but don't have enough reputation to comment.

  • $\begingroup$ I asked this question on reddit too and got some answers. Check out that too. $\endgroup$ – DeveScie Aug 20 '18 at 0:27
  • $\begingroup$ Cool, thanks. If my answer was helpful for you, I'd appreciate an upvote and/or accept. IMHO my answer is more specific and complete than any of the answers on Reddit so far. $\endgroup$ – Casey Jones Aug 20 '18 at 2:13
  • $\begingroup$ Byw, if you are after crypto trading tools, I created a telegram channel to where my bot sends detected RSI divergences. I will open source it soon. $\endgroup$ – DeveScie Aug 20 '18 at 2:59
  • $\begingroup$ Awesome, thanks. :) I actually just started developing my own bot a couple of days ago. So far it just does trailing stop losses for the sell strategy. I'm planning to use RSI divergences at first for the buy strategy, so I'll be curious to compare my algorithm with yours later. $\endgroup$ – Casey Jones Aug 20 '18 at 6:08
  • $\begingroup$ I am attempting to do the same thing with finding divergences and was able to complete steps 1 and 2 before hitting a roadblock and stumbling upon this. Could you explain how you computed step 3? I have the index points of these highs and lows and all the RSI/close info. Just trying to figure out a way to automate the checking, using those specific index points. $\endgroup$ – hkml Mar 12 at 2:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.