Exploring Different Ways to Calculate and Analyze Slope Divergence: A Deeper Look

Trying to objectify Price and Indicator Divergence through Slope Divergence

5/16/20233 min read

Title: Exploring Different Ways to Calculate and Analyze Slope Divergence: A Deeper Look

Introduction

Most of you know or even heard of the Divergence between price and momentum, where when the prices go in one direction and the momentum in another direction, this can be a sign of market reversal. For us Algorithmic Traders, the problem is that price divergence is usually detected through subjective observation. But to implement divergence in our automated trading strategies we need to objectify it. One way is simply to apply the fractal logic to connect the highs and lows and return a Boolean value that says if you have a divergence or not, I’ve applied this to my Indicator “Divergence Hero” with very good success, and you can check it out HERE.

Method 1: Raw Slope Difference

In this method, we directly compare the raw slope values of the price and the RSI. The slope is calculated using the linear regression formula:

Slope = (N Σ(xy) - Σx Σy) / (N * Σ(x^2) - (Σx)^2)

where x represents the time variable, y represents the price or RSI values, and N is the number of data points. While this approach is simple, it has the drawback of producing very different slope values for price and RSI, making them difficult to compare directly.

The problem here, is the Differences between the two slopes are very big, so comparing them is complicated. to Solve this problem, I tried normalizing their values.

Method 2: Normalized Slope Difference

To address the limitations of the raw slope difference, we can normalize the slopes by dividing them by their respective current values:

Normalized Slope = Slope / Current Value

This helps bring the price and RSI slopes onto a more comparable scale. However, this method still suffers from difficulties in comparing the slopes directly, as they can still vary significantly.

Method 3: Ratio of Slopes

In this method, we calculate the ratio between the price slope and the RSI slope:

Ratio = Price Slope / RSI Slope

This can provide a more meaningful comparison between the two slopes, as it directly shows how the price slope relates to the RSI slope. Nonetheless, the ratio can still produce very different values for bullish and bearish divergences, which can be challenging to analyze

Method 4: Angle Difference

Another approach is to calculate the angle between the price and RSI slopes. This method involves converting the slopes into angles using the arctangent function:

Angle = atan(Slope) * (180 / π)

The angle difference between the two slopes can then be computed:

Angle Difference = |Price Angle - RSI Angle|

This method can provide more consistent values, typically ranging between 0 and 30 degrees. However, interpreting the resulting angles can still be challenging, as it is unclear how to distinguish between bullish and bearish divergences.

Conclusion

We have explored various methods for calculating and analyzing slope divergence, each with its unique advantages and limitations. In practice, we found that analyzing the curve of the indicator was challenging, and interpreting the values was not straightforward. As a result, we recommend using visual divergence analysis instead, as it provides a more intuitive and user-friendly way to identify divergences.

The problem stays, that this doesn’t tell you anything about the “Strength” of Divergence. To try to solve this I explored the concept of Slope Divergence.

Slope divergence is an intriguing concept in technical analysis, where the slope of a price series and the slope of a momentum indicator (e.g., RSI) are compared to identify potential divergences. In this blog post, we will explore different methods of calculating slope divergence and discuss their advantages and limitations, along with some mathematical explanations.

As you see in the picture above, we are not trying to connect the highs and the lows, we are trying to fit a trendline between the values of the RSI and the price series