Learn R Programming

TTR (version 0.13-1)

bollingerBands: 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

bollingerBands(HLC, ma = list("SMA", n=20), sd = list(FUN="sd", n=2))

Arguments

HLC
High-Low-Close price series to use. If only a univariate series is given, it will be used. See details.
ma
A list whose first component is a string containing the moving average function name; additional parameters may also be specified as named components.
sd
A list of standard deviation input.

Value

  • A matrix containing the columns:
  • dnThe lower Bollinger Band.
  • maThe middle Moving Average (see notes).
  • upThe upper Bollinger Band.
  • pct.bThe %B calculation.

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$n 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.

References

The following site(s) were used to code/document this indicator: http://www.fmlabs.com/reference/Bollinger.htm http://www.fmlabs.com/reference/BollingerWidth.htm http://www.equis.com/Customer/Resources/TAAZ/?c=3&p=36 http://www.linnsoft.com/tour/techind/bb.htm http://stockcharts.com/education/IndicatorAnalysis/indic_Bbands.html http://stockcharts.com/education/IndicatorAnalysis/indic_BBWidth.htm

See Also

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

Examples

Run this code
## 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   <- bollingerBands( ttrc[,c("High","Low","Close")] )
  bbands.close <- bollingerBands( ttrc[,"Close"] )

Run the code above in your browser using DataLab