Modified on 2008/05/03 16:41 by Administrator — Categorized as: Standard Indicators


public static WMA Series(DataSeries ds, int period)
public static double Value(int bar, DataSeries ds, int period)
public WMA(DataSeries ds, int period, string description)

Parameter Description

ds The source DataSeries to smooth
period Indicator calculation period


WMA returns a linearly-Weighted Moving Average of the Price Series over the specified Period.

Whereas a SMA calculates a straight average of the data, WMA 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, WMA will follow prices more closely than a corresponding SMA.



WMA is a linearly-weighted moving average that is calculated by multiplying the first data point (oldest in time) by 1, the second by 2, the third by 3, etc. The final result is then divided by the sum of the weights. More recent data is thus more heavily weighted, and contributes more to the final WMA value. WMA excludes price data outside the length of the moving average, Period.

WMA = ( P0 * n + P1 * (n-1) + P2 * (n-2) + ... ) / ( n + (n-1) + (n-2) + ... )


P0 = Current Price
P1 = price one bar ago, etc....
n = number of periods


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() { // This sample system acts on crossovers of 60 and 80 period WMAs

DataSeries WMASlow = WMA.Series( Close, 80 ); DataSeries WMAFast = WMA.Series( Close, 60 ); PlotSeries( PricePane, WMAFast, Color.Blue, LineStyle.Solid, 1 ); PlotSeries( PricePane, WMASlow, Color.Red, WealthLab.LineStyle.Solid, 1 );

for(int bar = 80; bar < Bars.Count; bar++) { if (IsLastPositionActive) { if( CrossUnder( bar, WMAFast, WMASlow ) ) SellAtMarket( bar+1, LastPosition ); else SellAtLimit( bar+1, LastPosition, LastPosition.EntryPrice*1.2 ); } else { if( CrossOver( bar, WMAFast, WMASlow ) ) BuyAtMarket( bar+1 ); } } } } }