This function isn’t built into TradeStation so I decided to create it. I am doing some testing with it and will reveal any worthwhile information.
inputs:
BollingerPrice( NumericSeries ), { price to be used in calculation of the moving
average; this is also the price of which the standard deviation will be taken
for calculation of the upper and lower bands }
Length( numericSimple ), { number of bars to be used in the moving average and standard
deviation calculations }
NumDevsUp( numericSimple ), { number of standard deviations to be added to the moving
average to calculate the upper Bollinger band }
NumDevsDn( numericSimple ); { number of standard deviations to be added to the
moving average to calculate the lower Bollinger band; this input should be
negative if it is desired for the lower band to be at a price that is lower
than the moving average }
variables: Avg(0),SDev( 0 ),LowerBand( 0 ),UpperBand( 0 ),PercentB( 0 ),ScaledPercentB( 0 ) ;
Avg = AverageFC( BollingerPrice, Length ) ;
SDev = StandardDev( BollingerPrice, Length, 1 ) ;
UpperBand = Avg + NumDevsUp * SDev ;
LowerBand = Avg + NumDevsDn * SDev ;
if UpperBand <> LowerBand then
BollingerB = ( BollingerPrice - LowerBand ) / ( UpperBand - LowerBand )
else
BollingerB = 0;