Divergence

Modified on 2009/08/27 22:54 by Administrator — Categorized as: Standard Indicators

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:


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" ); } } } }