Sat12072013

Last update09:42:00 AM

In “Within The Volatility Band” in this issue, author Sylvain Vervoort describes the construction of volatility bands and a simple trading idea based on the bands. Provided here is a multiple-output function that returns the band values (midline, upper band, and lower band), an indicator that plots the bands, and a sample strategy. The strategy enters long when price closes above the upper band, and sells short when the price closes below the lower band. The strategy is provided for illustrative purposes only.

To download the EasyLanguage code, first navigate to the EasyLanguage FAQs and Reference Posts Topic in the EasyLanguage support forum (http://www.tradestation.com/EL-FAQ), scroll down, and click on the link labeled “Traders’ Tips, TASC.” Then select the appropriate link for the month and year. The ELD filename is “_SVEVolatilityBands.ELD.” The code is also shown below.

```_SVEVolatilityBand_Func (Series Function)
{ TASC - August, 2013 }
{ Within The Volatility Band }
{ Sylvain Vervoort }
inputs:
int AverageLen( numericsimple ), { band average
length }
int VolPeriod ( numericsimple ), { volatility
summing period }
double DevFact( numericsimple ), { deviation
factor }
double LowBandAdjust( numericsimple ), { lower
double oMidLine( numericref ),
double oUpperBand( numericref ),
double oLowerBand( Numericref ) ;
variables:
double devhigh( 0 ),
double devlow( 0 ),
double BarTypicalPrice( 0 ),
double typical( 0 ),
double deviation( 0 ),
double MedianAverage( 0 ) ;
BarTypicalPrice = TypicalPrice ;
if BarTypicalPrice >= BarTypicalPrice[1] then
typical = BarTypicalPrice - Low[1]
else
typical = BarTypicalPrice[1] - Low ;
{ basic deviation based on "typical" over a period and
a factor }
deviation = Summation( typical, VolPeriod ) /
VolPeriod * DevFact ;
devhigh = XAverage( deviation, AverageLen ) ;
devlow = XAverage( deviation, AverageLen ) *
MedianAverage = XAverage( BarTypicalPrice,
AverageLen ) ; { the middle average reference }
oMidLine = Average( MedianAverage, AverageLen ) ;
oUpperBand = XAverage( MedianAverage, AverageLen ) +
devhigh ;
oLowerBand = XAverage( MedianAverage, AverageLen ) -
devlow ;
_SVEVolatilityBand_Func = 1 ;
{
MULTIPLE-OUTPUT FUNCTIONS
A multiple-output function has two types of parameters
or "inputs" - input parameters and input/output
parameters.  The values of the input parameters are
passed into the multiple-output function, but not
modified by the function.  The values of the input/
output parameters are passed into the multiple-output
function, modified by it, and the modified values are
then inherited by - or output to - the calling routine.
The input/output parameters are often used for output
purposes only, i.e., the incoming values are ignored.
The outputs are in addition to the function return.
In multiple-output functions, the function return is
generally used to return an error code, though
sometimes the return may simply be a dummy value.
The input/output parameters are declared with a "ref"
suffix (such as "numericref") in the multiple-output
function's declaration statements.  For further
clarity, the names of the input/output parameters are
generally prefixed with an "o" in the function as
well as in all the routines that call the function.
The built-in single-return WRAPPER FUNCTIONS that call
the multiple-output functions are specialized calling
routines designed to offer simplified, alternate
pathways to the functionality of the underlying
multiple-output functions.  In the wrapper functions,
the input/output parameters are declared as local
variables and generally initialized to zero.  They are
passed through to the multiple-output function without
further modification.  After the call, the wrapper
function picks out the single output of interest and
assigns it as the return of the wrapper function.
}
_ SVEVolatilityBand_Ind (Indicator)
{ TASC - August, 2013 }
{ Within The Volatility Band }
{ Sylvain Vervoort }
inputs:
int AverageLen( 8 ), { band average length }
int VolPeriod (13 ), { volatility summing period }
double DevFact( 3.55 ), { deviation factor }
double LowBandAdjust( 0.9 ) ; { lower band
variables:
double MidLine( 0 ),
double UpperBand( 0 ),
double LowerBand( 0 ) ;
Value1 = _SVEVolatilityBand_Func( AverageLen,
UpperBand, LowerBand ) ;
{ plots - show only after calculations are stable }
if CurrentBar > AverageLen * 3 + 2 * VolPeriod  then
begin
Plot1( MidLine, "Median" ) ;
Plot2( UpperBand, "Upper" ) ;
Plot3( LowerBand, "Lower" ) ;
end ;
_ SVEVolatilityBand _Strat (Strategy)
{ TASC - August, 2013 }
{ Within The Volatility Band }
{ Sylvain Vervoort }
inputs:
int AverageLen( 8 ), { band average length }
int VolPeriod (13 ), { volatility summing period }
double DevFact( 1 ), { deviation factor }
double LowBandAdjust( 0.9 ) ; { lower band
variables:
double MidLine( 0 ),
double UpperBand( 0 ),
double LowerBand( 0 ) ;
Value1 = _SVEVolatilityBand_Func( AverageLen,
UpperBand, LowerBand ) ;
{ allow trading after calculations are stable }
OkToTrade = CurrentBar > AverageLen * 3 +
2 * VolPeriod ;
begin
if Close crosses over UpperBand then
Buy ( "SVE Vol LE" ) next bar market ;
if Close crosses under LowerBand then
SellShort ( "SVE Vol SE" ) next bar market ;
end ; ```

A sample chart is shown in Figure 1.

FIGURE 1: TRADESTATION. Shown here is a daily chart of STX with the indicator and strategy based on Sylvain Vervoort’s article in this issue applied. To align the strategy and indicator, “DevFact” inputs were both set to 1.

—Chris Imhof