EMA

Modified on 2008/04/14 11:05 by Administrator — Categorized as: Standard Indicators

Syntax

public EMA(DataSeries source, int period, EMACalculation calcType, string description)
public static EMA Series(DataSeries source, int period, EMACalculation calcType)

Parameter Description

source Price series
int Indicator calculation period
calcType EMACalculation enum: (EMACalculation.Legacy, EMACalculation.Modern)

Description

EMA returns the Exponential Moving Average of the specified period. EMA is similar to Simple Moving Average (SMA), in that it averages the data over a period of time. However, whereas SMA just calculates a straight average of the data, EMA applies more weight to the data that is more current. The most weight is placed on the most recent data point. Because of the way it's calculated, EMA will follow prices more closely than a corresponding SMA.

Interpretation


Calculation

You should notice how the EMA use the previous value of the EMA in its calculation, this means the EMA includes all the price data within its current value. The newest price data has the most impact on the average and the oldest prices data has only a minimal impact.

EMA = ( K x ( C - EMA1 ) ) + EMA1

where,
C = Current Price
EMA1 = Previous bar's EMA value (A SMA is used for the first period's calculation)
K = Exponential smoothing constant

The smoothing constant K, applies appropriate weight to the most recent price. It uses the number of periods specified in the moving average. With Wealth-Lab you have a choice of two methods for calculating the smoothing constant.

Two similar but not equivalent formulas are available for calculating the exponent; Wealth-Lab's original method (from Pring's Technical Analysis Explained), which is selected by passing EMACalculation.Legacy as the calcType parameter.

K = ( 1 / period ) * 2


and perhaps a more common method, which is referred to as the "Modern method", selected by passing EMACalculation.Modern as the calcType parameter.

K = 2 / ( 1 + period )


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() { // Dual EMA CrossOver System } DataSeries ema60 = EMA.Series( Close, 60, WealthLab.Indicators.EMACalculation.Modern ); DataSeries ema120 = EMA.Series( Close, 120, EMACalculation.Modern ); PlotSeries( PricePane, ema60, Color.Black, WealthLab.LineStyle.Solid, 3 ); PlotSeries( PricePane, ema120, Color.DarkGray, LineStyle.Solid, 1 ); // EMA is one of unstable indicators, initialize the loop accordingly for(int bar = 120*3; bar < Bars.Count; bar++) { if (!IsLastPositionActive) { if( CrossOver( bar, ema60, ema120 ) ) BuyAtMarket( bar+1 ); } else { if( CrossUnder( bar, ema60, ema120 ) ) SellAtMarket( bar+1, LastPosition ); } } } } }