BBands {TTR}R Documentation

Bollinger Bands

Description

Bollinger Bands are a way to compare a security's volatility and price levels over a period of time. Developed by John Bollinger.

Usage

BBands(HLC, n = 20, maType, sd = 2, ...)

Arguments

HLC

Object that is coercible to xts or matrix and contains High-Low-Close prices. If only a univariate series is given, it will be used. See details.

n

Number of periods for moving average.

maType

A function or a string naming the function to be called.

sd

The number of standard deviations to use.

...

Other arguments to be passed to the maType function.

Details

Bollinger Bands consist of three lines:

The middle band is generally a 20-period SMA of the typical price ([high + low + close]/3). The upper and lower bands are sd standard deviations (generally 2) above and below the MA.

The middle band is usually calculated using the typical price, but if a univariate series (e.g. Close, Weighted Close, Median Price, etc.) is provided, it will be used instead.

Value

A object of the same class as HLC or a matrix (if try.xts fails) containing the columns:

dn

The lower Bollinger Band.

mavg

The middle Moving Average (see notes).

up

The upper Bollinger Band.

pctB

The %B calculation.

Note

Using any moving average other than SMA will result in inconsistencies between the moving average calculation and the standard deviation calculation. Since, by definition, a rolling standard deviation uses a simple moving average.

Author(s)

Joshua Ulrich

References

The following site(s) were used to code/document this indicator:
https://www.fmlabs.com/reference/Bollinger.htm
https://www.fmlabs.com/reference/BollingerWidth.htm
https://www.metastock.com/Customer/Resources/TAAZ/?p=36
https://www.linnsoft.com/techind/bollinger-bands
https://school.stockcharts.com/doku.php?id=technical_indicators:bollinger_bands
https://school.stockcharts.com/doku.php?id=technical_indicators:bollinger_band_width

See Also

See EMA, SMA, etc. for moving average options; and note Warning section.

Examples


 ## The examples below show the differences between using a
 ## High-Low-Close series, and just a close series when
 ## calculating Bollinger Bands.
 data(ttrc)
 bbands.HLC <- BBands( ttrc[,c("High","Low","Close")] )
 bbands.close <- BBands( ttrc[,"Close"] )

[Package TTR version 0.24.4 Index]