public Divergence(DataSeries source, WealthLab.Indicators.MAType maType, int period, string description)
public static DivergenceSeries(DataSeries source, WealthLab.Indicators.MAType maType, int period)
||The source DataSeries. For example, pass MACD.Series(Close), or simply drag and drop the Divergence indicator onto a previously plotted MACD.
||WealthLab.Indicators.MAType enum: (EMALegacy, EMAModern, SMA, VMA, and WMA). Represents the moving average indicator type to apply to source to create the signal line.
||The period of the maType.
Divergence is oscillator formed by subtracting the moving average of a DataSeries from the same DataSeries. The Divergence indicator is designed to be a shortcut to access the MACD Histogram, which is the difference between the MACD
indicator and its 9-period EMA, or signal line. Nonetheless, the Divergence indicator is more versatile and provides the ability to select different types of moving averages and periods.
Divergence is generally used in one of three ways:
- Zero crossings can predict or confirm a change in trend.
- For swing trading, relative peaks (troughs) of Divergence can be used to identify divergence with the corresponding price peaks (troughs) to predict changes in trend.
- For short-term trading at price extremes, Divergence turning up or down may predict or indicate a price reversal to soon occur.
Divergence is calculated from the difference between the source
DataSeries and its moving average specified by the maType parameter.MACD Histogram
The MACD Histogram is the difference between the MACD indicator and its 9-period EMA, also called the signal line. The Divergence indicator assists in this construction. Just pass MACD.Series(Close) and MAType.EMAModern as the source
parameters using a signal period of 9, as shown in the Example. MACD Histogram by Drag and Drop
- Drag and drop a MACD indicator on the chart.
- Drag and drop Divergence on top of the MACD indicator.
- In the Divergence Properties page, select MAType = EMAModern and Period = 9 (traditional settings).
- If desired, check the "Use Divergence Pane" option to plot the histogram in its own pane.
public class MyStrategy : WealthScript
protected override void Execute()
Buy when Divergence crosses above zero, sell when going below.
DataSeries hist = Divergence.Series( MACD.Series(Close), MAType.EMAModern, 9 );
ChartPane MACDPane = CreatePane( 50, true, true );
PlotSeries( MACDPane, hist, Color.Maroon, LineStyle.Histogram, 2 );
for(int bar = 26 * 3; bar < Bars.Count; bar++)
if( CrossOver( bar, hist, 0 ) )
BuyAtMarket( bar+1 );
if( CrossUnder( bar, hist, 0 ) )
SellAtMarket( bar+1, Position.AllPositions, "MACD" );