TASC 2012-12 | Using VIX To Forecast The S&P 500 (Gardner)

Modified on 2012/11/08 10:09 by Eugene — Categorized as: TASC Traders Tips

Traders' Tip text

Counting how many times a DataSeries was above/below another DataSeries (e.g. a moving average) can be performed using the SeriesIsAbove/SeriesIsBelow indicators available in our "Community Indicators" library. Considering this, when building Wealth-Lab 6 code for this month's trading strategy we decided to concentrate on the pure charting side of things. Situations when the VIX's Low price was staying above or below its moving average for 11 trading sessions straight were highlighted in bluish and reddish color (see Figure 1).

Image

Figure 1. Daily chart of SPY (SPDR S&P 500) with VIX overlay illustrating Trent Gardner’s approach.

The additional library is available for download to Wealth-Lab customers from our site www.wealth-lab.com ("Extensions" section). To avoid copy/paste, we suggest that Wealth-Lab users would download the code of the trading strategy (see below) by simply clicking the "Download" button in Wealth-Lab's "Open Strategy" dialog (Figure 2).

Image

Figure 2. How to download trading strategies in Wealth-Lab 6.

WealthScript Code (C#)


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using Community.Indicators;

namespace WealthLab.Strategies { public class Gardner12_2012 : WealthScript { protected override void Execute() { Bars vix = GetExternalSymbol( "^VIX", true ); SMA vixSma = SMA.Series( vix.Low, 50 ); SeriesIsAbove sa = SeriesIsAbove.Series( vix.Low, vixSma, 1); SeriesIsBelow sb = SeriesIsBelow.Series( vix.Low, vixSma, 1);

for (int bar = GetTradingLoopStartBar(vixSma.FirstValidValue); bar < Bars.Count; bar++) { if (IsLastPositionActive) { if( sa[bar] >= 11 ) { for( int i = bar; i > bar-11; i-- ) SetBackgroundColor( i, Color.FromArgb( 30, Color.Blue ) ); SellAtMarket( bar+1, LastPosition ); } } else { if( sb[bar] >= 11 ) { for( int i = bar; i > bar-11; i-- ) SetBackgroundColor( i, Color.FromArgb( 30, Color.Red ) ); BuyAtMarket( bar+1 ); } } } HideVolume(); ChartPane psb = CreatePane( 30, false, true ); ChartPane vixPane = CreatePane( 50, false, true); PlotSymbol( vixPane, vix, Color.Silver, Color.Silver); PlotSeries( vixPane, vixSma, Color.Red, LineStyle.Solid, 1 ); PlotSeries( psb, sa, Color.Blue, LineStyle.Histogram, 2 ); PlotSeries( psb, sb, Color.Red, LineStyle.Histogram, 2 ); DrawHorzLine( psb, 11, Color.Blue, LineStyle.Dashed, 1 ); } } }