Fri12062013

Last update09:42:00 AM

In “Within The Volatility Band” in this issue, author Sylvain Vervoort provides a method to calculate the SVE volatility band indicator, which may be used as a tool to help make buy & sell decisions within the context of a trading system.

To use the SVE bands in Trading Blox, we’ve created a block that defines them as indicators. This block may be dropped into a Trading Blox system along with other Blox that determine entry & exit rules, trade sizing, and so on, to provide a complete trading method.

To recreate the band indicators, we first set up a new block called “SVE Volatility Band Indicator.” Vervoort’s article instructs us to create four parameters that act as inputs to our calculations along with several expressions that apply some mathematical transformations to various data inputs. See Figure 13 for a list of the indicators and parameters we used.

FIGURE 13: TRADING BLOX, SVE VOLATILITY BANDS INDICATOR BLOCK. The SVE band indicator block is made up of four parameters and 12 indicators.

FIGURE 14: TRADING BLOX, DEVIATION FACTOR. Several of the expressions needed to calculate the bands are coded in Trading Blox as calculated indicators, as deviation is here.

No code needs to be written in the main scripting editor for this block, but some expressions are coded in the indicator value expression editor (Figure 14). They include:

• typicalPrice = High + Low + Close / 3
• priorTypicalPrice = typicalPrice[1]
• priorLow = instrument.low[1]
• typical = ifthenelse( typicalPrice >= priorTypicalPrice, typicalPrice - priorLow, priorTypicalPrice - instrument.low)
• deviation = sum(typical, summingPeriod ) / summingPeriod * deviationFactor
• devHigh = EMA( devHigh[1], bandAverage, deviation )
• devLow = EMA( devLow[1], bandAverage, deviation ) * lowerBandAdjust
• medianAverage = EMA( medianAverage[1], bandAverage, typicalPrice )
• emaOfMedAvg = EMA( emaOfMedAvg[1], bandAverage, medianAverage )
• smaofMedAvg = average( medianAverage, bandAverage )
• upperBand = emaOfMedAvg + devHigh
• lowerBand = emaOfMedAvg - devLow

Once they have been defined in this block, the bands may be plotted on a chart (Figure 15).

FIGURE 15: TRADING BLOX, SVE VOLATILITY BANDS. The upper band is shown in green, with the lower band in red, while the moving average of median average plots in between in blue.

A simple entry/exit block (see the “SVE Band Entry Exit” block in our code archive) consisting of the following code may be used to generate trading signals to go long when price closes above the upper band and short when price closes below the lower band.

```-----------------------------------------------------------------------------------
SCRIPT: Entry Orders
-----------------------------------------------------------------------------------
if instrument.position != LONG then
if instrument.close > upperBand then broker.enterLongOnOpen( lowerBand )
endif
if instrument.position != SHORT then
if instrument.close < lowerBand then broker.enterShortOnOpen( upperBand )
endif
-----------------------------------------------------------------------------------
SCRIPT: Exit Orders
-----------------------------------------------------------------------------------
if instrument.position == LONG then
if instrument.close < lowerBand then broker.exitAllUnitsOnOpen
endif
if instrument.position == SHORT then
if instrument.close > upperBand then broker.exitAllUnitsOnOpen
endif
```

Combined with our built-in fixed fractional money manager block to provide the quantity to purchase or sell on each trade, we have a complete trading system that buys and sells a specific quantity on each signal (Figure 16).

FIGURE 16: TRADING BLOX, SAMPLE TRADE. The system goes long when price closes above the green band and reverses to short when price closes below the red band. The entry price, the initial stop at the opposite volatility band, and the exit price are shown for the last trade on the chart.

More advanced entry/exit rules might be used to filter trade signals, trail a stop, or otherwise augment this basic timing mechanism.