Detecting RSI Divergence

A divergence happens when there’s a difference between the direction of the chart’s price line and its indicator line. For example, when the price is rising temporarily but the RSI indicator line is falling, this is called a divergence. A divergence can trigger a buy or a sell signal depending on the context.

This tutorial explains how to create an indicator that detects divergence between the RSI and the price.

To detect a divergence we need to compare the slope of the RSI line and the slope of the price line. In this example, we’ll trigger a sell signal whenever the price is rising but the RSI is falling.

Firstly, go to the Indicator page then select the builder tab.

Card image cap

Add a gradient operator

Add a Gradient operator, and set the input to Moving Average. Click the cogs icon to set the gradient parameters. For the purpose of this example, we’ll use a setting of 3 but you can use any setting. This will give us the slope over a range of 3 bars. We’ll set the moving average to 7 bars.

Card image cap

Add moving average

Click the Gradient row to select it. Then click the plus symbol in the toolbar to add a new row. Set the new row to Greater than. We are interested in places where the price is rising. For this, the gradient needs to be greater than zero. The Greater than has a default value of zero, so no changes are needed.

Card image cap

Check sign of slope

Now click the spyglass icon in the top row to preview the output so far. You can change the format of the output, as shown here, from the settings tab.

Card image cap

Slope is positive

Add a new row at the top again by selecting the top row and clicking the plus icon. Set this to an And operator. To save time we can copy the Greater Than stub and paste it into the second input to the And.

Card image cap

Add a new top row

To do this, click the Greater Than then click the Copy icon from the toolbar. The Copy icon is two blank sheets.

Card image cap

Copy and paste the Greater Than stub

Now click on the bottom row, which should be the second input to the And operator. Click the Paste icon from the toolbar. The Paste icon is two dark sheets. Change the Greater Than to a Less Than operator.

Card image cap

Set the other input to RSI

Now change the Moving Average operator in the lower stub to RSI. For the sake of demonstration, we’ll leave the settings at the defaults.

Card image cap

Add a Sell signal

Add a new row at the top and set it to a Sell operator. On clicking preview in the top row, we can see that the indicator creates a sell signal whenever the RSI is falling and the price is rising, as required.

Card image cap

Preview result

Finally, to save the indicator click the disk icon in the toolbar and provide a name.

Use this Indicator

Risk Disclosure: Information given on this website is for general purposes only and should not be construed as investment advice. Certain instruments shown here are complex and may come with a high risk of losing money rapidly due to leverage. You should consider whether you understand how these instruments work and whether you can afford to take the high risk of losing your money. Market data displayed is indicative and is not a solicitation to buy or sell.