Traders' Tip text
The Volume-Weighted Moving Average (
VWMA) offers an additional dimension by using volume in addition to price. Typically, the VWMA is used in conjunction with an SMA of the same or different period.
Among the possible use cases of including the
VWMA can be named:
- avoiding false breakouts on no volume support;
- trend direction confirmation;
- indication of a weakening trend when it moves below the SMA;
- a profit taking or exit signal when the distance between the VWMA and the SMA tightens, and more.
Another example is the swing-trading setup from Ken Calhoun's article: the
VWMA crossing above the SMA may signal a potential bullish trend change, and the opposite crossunder is used to close the position. Please see below for WealthScript Strategy code.
Figure 1. highlights a successful trade in FAS.After updating the
TASCIndicators library to v2017.03 or later, the VWMA indicator can be found under the TASC Magazine Indicators group. You can plot it on a chart or use it as an entry or exit condition in a Rule-based Strategy without having to program a line of code yourself.
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using TASCIndicators;
namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
private StrategyParameter paramPeriodVWMA;
private StrategyParameter paramPeriodSMA;
public MyStrategy()
{
paramPeriodVWMA = CreateParameter("VWMA Period",50,2,300,1);
paramPeriodSMA = CreateParameter("SMA Period",70,2,300,1);
}
protected override void Execute()
{
var sma = SMA.Series(Close,paramPeriodSMA.ValueInt);
var vwma = VWMA.Series(Bars,paramPeriodVWMA.ValueInt);
for(int bar = GetTradingLoopStartBar(1); bar < Bars.Count; bar++)
{
if (IsLastPositionActive)
{
if( CrossUnder(bar,vwma,sma))
SellAtMarket(bar+1, LastPosition);
}
else
{
if( CrossOver(bar,vwma,sma))
BuyAtMarket(bar+1);
}
}
PlotSeries(PricePane,vwma,Color.Red,LineStyle.Solid,1);
PlotSeries(PricePane,sma,Color.Blue,LineStyle.Solid,1);
}
}
}
Eugene
Wealth-Lab team
www.wealth-lab.com