Traders' Tip text
Don’t be confused by the
SveVolatilityBands name: the new bands by author Sylvain Vervoort are different from the synonymous indicator from his
August 2013 article in Traders’ Tips.
We decided that a good illustration of its application may be through the concept of volatility contraction and expansion. Price breakout following a volatility contraction implies an expansion in volatility of the price range which acts as catalyst to longer term trends. The opposite phase, i.e. when the bands volatility reaches its long-term high, signifies considerable price changes and a potential end of the trend. The width percentage of the Smoothed Volatility Bands is measured over desired lookback (here: 200 days).
System rules:- Buy at stop at the highest 20-day high when the percent width of the SveVolatilityBands contracts to its lowest 200-day value, and there’s a bullish trend (close price above 200-day SMA)
- Sell at market when the percent width of the SveVolatilityBands widens to its highest 200-day value, and today’s low drops below the 20-day lowest low
The system may be risky enough to apply in its current barebone state so motivated traders might want to use a stop loss and/or a trend filter to liquidate position if the trend has changed from bullish.
Figure 1. demonstrates the characteristic volatility expansion trade in AAPL (Apple Inc).
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using TASCIndicators;
namespace WealthLab.Strategies
{
public class SVESmoothedVolatilityBands : WealthScript
{
private StrategyParameter paramBandAvg;
private StrategyParameter paramMiddleLine;
private StrategyParameter paramDevFact;
private StrategyParameter paramLowBAdj;
private StrategyParameter paramSqueezeLookback;
public SVESmoothedVolatilityBands()
{
paramBandAvg = CreateParameter("Band average", 20, 2, 100, 1);
paramMiddleLine = CreateParameter("Middle line period", 20, 2, 100, 1);
paramDevFact = CreateParameter("Deviation factor", 2.4, 0.2, 5.0, 0.2);
paramLowBAdj = CreateParameter("Low Band Adj.", 0.9, 0.1, 3.0, 0.1);
paramSqueezeLookback = CreateParameter("Squeeze lookback", 200, 5, 150, 1 );
}
protected override void Execute()
{
int average = paramBandAvg.ValueInt;
int middleperiod = paramMiddleLine.ValueInt;
double devfact = paramDevFact.Value;
double lowbandadjust = paramLowBAdj.Value;
int squeezelen = paramSqueezeLookback.ValueInt;
// Smoothed Volatility Bands
var TypicalPrice = AveragePriceC.Series( Bars );
var MedianAverage = WMA.Series(TypicalPrice, middleperiod);
var HighChannel = SVESmoothedVolatilityBandUpper.Series( Bars, average, middleperiod, devfact, lowbandadjust );
var LowChannel = SVESmoothedVolatilityBandLower.Series( Bars, average, middleperiod, devfact, lowbandadjust );
SolidBrush shadowBrush = new SolidBrush(Color.FromArgb(50, Color.Violet));
PlotSeriesFillBand(PricePane, HighChannel, LowChannel, Color.Blue, shadowBrush, LineStyle.Solid, 2);
PlotSeries(PricePane, MedianAverage, Color.Blue, LineStyle.Solid, 1);
HideVolume();
// Squeeze and expansion in SveVolatilityBands
var PctWidth = ( ( HighChannel - LowChannel ) / MedianAverage ) * 100; PctWidth.Description = "% Width";
var PctWidthMax = Highest.Series( PctWidth, squeezelen );
var PctWidthMin = Lowest.Series( PctWidth, squeezelen );
ChartPane PctWPane = CreatePane( 20, true, true );
PlotSeries( PctWPane, PctWidth, Color.Blue, WealthLab.LineStyle.Solid, 2 );
PlotSeries( PctWPane, Lowest.Series( PctWidth, squeezelen ), Color.DarkGreen, LineStyle.Dashed, 2 );
PlotSeries( PctWPane, Highest.Series( PctWidth, squeezelen ), Color.DarkRed, LineStyle.Dashed, 2 );
for(int bar = GetTradingLoopStartBar(average); bar < Bars.Count; bar++)
{
if (IsLastPositionActive)
{
if( PctWidthbar >= PctWidthMaxbar )
{
SetBackgroundColor( bar, Color.FromArgb(30, Color.Red) );
if( Lowbar <= Lowest.Series(Low, average)bar )
SellAtMarket(bar+1, LastPosition, "Vola expansion");
}
}
else
{
if( PctWidthbar <= PctWidthMinbar )
{
SetBackgroundColor( bar, Color.FromArgb(30, Color.Green) );
if( Closebar >= SMA.Series(Close, squeezelen)bar )
BuyAtStop( bar+1, Highest.Series(High, average)bar, "Vola contraction" );
}
}
}
}
}
}
Eugene (Gene Geren)
Wealth-Lab team
www.wealth-lab.com