3
$\begingroup$

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

$\endgroup$
4
$\begingroup$

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.

$\endgroup$
  • $\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$ 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
  • $\begingroup$ I'm not sure if I understand your question. As explained in the original question: "A bullish divergence occurs when the underlying security makes a lower low and RSI forms a higher low... A bearish divergence forms when the security records a higher high and RSI forms a lower high." If you have identified a pair of lower lows in price (priceA and price B), then priceA - priceB should be positive, right? If RSIa - RSIb (RSI at the same times) is then negative, that means the RSI has risen, which signals a bullish divergence. Does that help? $\endgroup$ – Casey Jones Mar 18 at 2:48

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.