Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

A useful article from Investopedia defining divergence and what the indicator tells you


The study works by detecting divergence between swings on the chart and swings on an oscillator. Swings in this context are synonymous to peaks or pivots.

The image to the right highlights different types of swings

A few definitions:

  1. The 1st peak refers to the swing that is on the left hand side of the chart.
  2. The 2nd peak refers to the swing that is on the right.
  3. A divergence is when the peaks of the price go in a different direction from the oscillator. Price increasing Vs. oscillator decreasing, or vice versa.
  4. A bearish divergence (shown in red) looks for a series of diverging "swing high"s.
  5. A bullish divergence (shown in green) looks for a series of diverging "swing low"s.

A line is drawn between the two swings once a divergence is confirmed.

Image Modified

Sensitivity Settings
Anchor

Image Removed

2nd Peak and Early Detection

The 2nd peak actually has 2 sensitivity values: 2nd peak left and 2nd peak right. The reason for that is to allow for a mix of detecting peaks that have advanced enough in one direction but to get an early alert without having to wait for the full pattern to form (see the images below for an example.

Image Removed

Image Removed

senssettings
senssettings

Swings are defined as bars that peak higher/lower than all their neighbors. The more bars beside the peak that make a lower high/higher low, the more significant the swing.

The Swing Sensitivity input dictates how many bars need to make a lower high/higher low than the peak for it to be considered for divergence. An example with Swing Sensitivity = 3 is shown in blue on the image to the right.

Sensitivity also has an impact on the responsiveness of the study. A lower sensitivity value means that swings will be detected faster, as there needs to be less bars on the right of the 2nd peak until a swing is registered. The colored arrow indicated on what bar a divergence was detected.



Image Added

Early Detection 
Anchor
earlydetect
earlydetect

The Trigger Sensitivity input controls the 2nd peak's right side sensitivity and by extension how quickly a peak is detected. Lower values means sooner detection of divergence, but more false positives on short swings.


Image Added

Image Added


Divergence Lookback
Anchor
lookback
lookback

Divergence is detected between two swings. The study is limited in how many peaks it can look back through for divergence through the Divergence Lookback Number of Peaks input. If there are multiple peaks that divert in the lookback it selects one according to the Divergence Lookback Use Nearest/Furthest Peak input.

Filters

Bars/Oscillator Crossing Divergence Line
Anchor
crossdiverge
crossdiverge

The study can filter out bars or oscillator values that cross the divergence line. Examples are shown in images to the right.

Image Added


Inputs


Input nameDescription
Bullish Divergence Price ReferenceReference to the input data for detecting Swing Lows
Bearish Divergence Price ReferenceReference to the input data for detecting Swing Highs
Oscillator ReferenceReference to the subgraph we want to detect divergence with
Draw Divergence Lines
On
Select whether to draw the actual divergence lines on the main price panel and/or the oscillator region
Oscillator Graph RegionThe graph region of the oscillator
Swing Sensitivity
1st Peak
Number of bars sensitivity for
the left side swing
detecting swings (see
more below
Sensitivity Settings)
Trigger Sensitivity
2nd Peak Left
Number of bars sensitivity on the
left hand
right side of the
right peakSensitivity
2nd
Peak RightNumber of bars sensitivity on the right hand side of the right peak
peak (see Early Detection)
On Bar
Close
closeShould the divergence be detected on bar close or intrabar
Arrow OffsetVisual offset in ticks of the arrow from the barModeSelect between Regular and Hidden Divergence

Subgraphs

SubgraphDescriptionBullish Divergence DetectedAn up arrow by default, below the barBearish Divergence DetectedA down arrow by default, above the barNote that the detection uses swing points. That means that the right side swing must form in order for the divergence to be drawn. Depending the "Sensitivity 2nd Peak Right" setting, there will be that much delay in detection because we have to wait for the swing to form (Its a classic trade off between waiting for a full price pattern to form vs. earlier detection with patterns that have not fully formed). The arrows will appear on the bar where the divergence was detected. If you look at a historical chart, the arrow shows you when you would have been alerted to the divergence
Divergence Signal Visual Offset (in Ticks)Visual offset in ticks from the bar of the arrow marking divergence detection
Divergence Types to DetectSelect whether Regular and/or Hidden Divergence types are detected
Oscillator Pivot Alignment EnabledWhen enabled and a price swing is detected, the study will look back for a swing in the oscillator to use for divergence detection. If no swing is found then the study will not look for divergence.
Oscillator Pivot Alignment LookbackAmount of bars to look back in the oscillator for a swing.
Bullish Divergence Line ColorColor for lines drawn for Bullish Divergence
Bearish Divergence Line ColorColor for lines drawn for Bearish Divergence
Divergence Line WidthWidth of lines drawn for Divergence

Filter For Price Bars Breaching Divergence Line

Select to filter out price bars that breach the divergence line either with their closing value or any value in-between high and low (see Bars/Oscillator Crossing Divergence Line)
Filter For Oscillator Breaching Divergence LineSelect to filter out oscillator values that breach the divergence line (see Bars/Oscillator Crossing Divergence Line)
Allow Divergence Line to Span Multiple Trading SessionsShould divergences be allowed to span multiple trading sessions
Divergence Lookback Number of PeaksNumber of peaks to look through for divergence (see Divergence Lookback)
Divergence Lookback Use Nearest/Furthest PeakSelect whether to prefer the furthest or nearest diverting peak found in the lookback
Divergence Line Slope Filter Minimum Price Difference UnitsSelect whether to use difference in points or percentage when filtering out divergences that are too small
Divergence Line Slope Filter Minimum Price DifferenceMinimum difference between two peaks to be considered for divergence
Divergence Line Filter Minimum Oscillator DifferenceMinimum difference in points between two oscillator values to be considered for divergence

Subgraphs


SubgraphDescription
Regular Bullish DivergenceIs plotted on bars where a Regular Bullish Divergence is detected. Up arrow by default.
Hidden Bullish DivergenceIs plotted on bars where a Hidden Bullish Divergence is detected. Up arrow by default.
Regular Bearish DivergenceIs plotted on bars where a Regular Bearish Divergence is detected. Down arrow by default.
Hidden Bearish DivergenceIs plotted on bars where a Hidden Bearish Divergence is detected. Down arrow by default.


Performance and Tuning

To deal with long load times and sluggishness

  • Reduce the number of days loaded
  • Turn the drawings off

Setting up Alerts


Using the SC built-in alerts, add the alert condition below to the study Alerts Tab

Alert condition: or(SG1<>0, SG2<>0)

Widget Connector
urlhttp://youtube.com/watch?v=EEuKv_drO2U

More

Widget Connectorurlhttps://www.youtube.com/watch?v=vBx8OA2Asvs&feature=youtu.be