Log in to see Cloud of Tags

Wealth-Lab Wiki

Syntax

public Divergence(DataSeries source, WealthLab.Indicators.MAType maType, int period, string description)
public static DivergenceSeries(DataSeries source, WealthLab.Indicators.MAType maType, int period)

Parameter Description

source The source DataSeries. For example, pass MACD.Series(Close), or simply drag and drop the Divergence indicator onto a previously plotted MACD.
maType 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.
period The period of the maType.

Description

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.

Interpretation

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.

Calculation

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 and maType parameters using a signal period of 9, as shown in the Example.

MACD Histogram by Drag and Drop
  1. Drag and drop a MACD indicator on the chart.
  2. Drag and drop Divergence on top of the MACD indicator.
  3. In the Divergence Properties page, select MAType = EMAModern and Period = 9 (traditional settings).
  4. If desired, check the "Use Divergence Pane" option to plot the histogram in its own pane.

Example

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { /* Buy when Divergence crosses above zero, sell when going below. Educational only! */ 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" ); } } } }

Important Disclaimer: The information provided by Wealth-Lab is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.  The owner of Wealth-Lab.com assumes no liability resulting from the use of the material contained herein for investment purposes. By using this web site, you agree to the terms of this disclaimer and our Terms of Use.


ScrewTurn Wiki. Some of the icons created by FamFamFam.