Technical Studies Reference


Divergence Detector

This study detects a divergence in slope between the regression line of the Main Price Graph of a chart and that of a Study Subgraph (which corresponds to the Study Subgraph Reference Input) on the same chart.

A divergence occurs when there is a significant difference in slope. The conditions for a divergence are discussed below.

Positive Divergences are indicated with an Up Arrow below a chart bar where they occur. Negative Divergences are indicated with a Down Arrow above the bar where they occur. A Positive Divergence is when the Study Subgraph angle is greater than the Main Price Graph angle by the specified amount of degrees with the Divergence Threshold in Degrees Input. There is also the Opposite Slope Divergence Threshold in Degrees Input which controls the required threshold in degrees when the angle calculations have opposite signs. A negative divergence occurs when the Study Subgraph angle is less than the Main Price Graph angle. This behavior as documented in this paragraph is effective with version 1576 and higher.

For both the Main Price Graph (MG) and the Study Subgraph (SS), regression lines are calculated for Input Data from time index (chart bar) \(t-L+1\) to time index \(t\), where \(L\) is the Divergence Length. The default value of \(L\) is \(10\). The regression line for the Main Price Graph has an equation of the form \(y=m_{MG} x+b_{MG}\). The regression line for the Study Subgraph has an equation of the form \(y=m_{SS} x+b_{SS}\) . In these equations, the \(m\)'s are slopes, and the \(b\)'s are the \(y\)-coordinates of the \(y\)-intercepts.

Before the regression line calculation, the Input Data values of the Main Price Graph are divided by Value Increment per Bar in Ticks * Tick Size. Before the regression line calculation for the Study Subgraph, the values are divided by the Value Per Point for Study Reference Input value.

Rather than compare the slopes directly for divergence, we compare the angles of inclination of the two regression lines. The angles of inclination for the regression line of the Main Price Graph and that of the Study Subgraph are denoted \(\theta_{MG}\) and \(\theta_{SS}\), respectively, and they are computed in degrees as follows.

$$\theta_G=\tan^{-1}\left(m_{MG}\right)\cdot\frac{180^{\circ}}{\pi}$$ $$\theta_S=\tan^{-1}\left(m_{SS}\right)\cdot\frac{180^{\circ}}{\pi}$$

These angles are in the interval \((-90^{\circ},90^{\circ})\). If the two angles have the same sign, then the study will indicate a divergence if \(\left|\theta_{MG}-\theta_{SS}\right|\) exceeds the Divergence Threshold in Degrees. The default value of this threshold is \(45^{\circ}\). If the two angles have opposite signs, then the study will indicate a divergence if \(\left|\theta_{MG}-\theta_{SS}\right|\) exceeds the Opposite Slope Divergence Threshold in Degrees. The default value of this threshold is \(10^{\circ}\).

The Tool Values Window displays the calculated angles by the Divergence Detector study and those angles can be viewed for any chart bar by using the Chart Values Tool. This is very helpful in order to determine the proper Divergence Threshold in Degrees Input settings.

The Subgraph >> Draw Style setting for the Positive Divergence and Negative Divergence Subgraphs in the Study Settings window can be changed from the default arrows to any other Draw Style that you require. Refer to Draw Style.

When there is a positive divergence, this generally would indicate that based upon the Study Subgraph being referenced by the Divergence Detector study that the main price graph may change direction from its downward trend if there has been a downward trend. When there is a negative divergence, this generally would indicate that based upon the Study Subgraph being referenced by the Divergence Detector study that the main price graph may change direction from its upward trend if there has been a upward trend.

Inputs

  • Input Data
  • Study Subgraph Reference: This Input is for specifying the Study Subgraph to which a corresponding Main Price Graph is to be compared for the Divergence Detector Study.
  • Divergence Length: This Input is for setting the number of chart bars for which linear regression statistics are to be calculated for both the Main Price Graph and the selected Study Subgraph.
  • Divergence Threshold in Degrees: This Input is for setting the number of degrees by which the angles of inclination of the regression lines for a Main Price Graph and a Study Subgraph may differ before a divergence is detected. The absolute value of the angle difference must be equal to or exceed Divergence Threshold in Degrees for a divergence to exist.
  • Opposite Slope Divergence Threshold in Degrees: This Input is for setting the number of degrees by which the angles of inclination of the regression lines for a Main Price Graph and a Study Subgraph may differ before a divergence is detected. This threshold is used only when the lines have angles of inclination that are of opposite signs. The absolute value of the angle difference must be equal to or exceed Opposite Slope Divergence Threshold in Degrees for a divergence to exist.
  • Value Per Point for Study Reference: Before the regression line is calculated for the study Subgraph referenced through the Study Subgraph Reference Input, the values of the study Subgraph are divided by this Input setting. For more information about this Value Per Point Input, refer to the explanation in the Drawing a Line with a Specific Angle or Slope section on the Drawing Tools page.

*Last modified Tuesday, 27th June, 2017.