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.
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.
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.
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.
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.
To do this, click the Greater Than then click the Copy icon from the toolbar. The Copy icon is two blank sheets.
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.
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.
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.
Finally, to save the indicator click the disk icon in the toolbar and provide a name.