stratBBands: Bollinger Bands Strategy

Description Usage Indicators Signals Rules Notes References


Strategy object implementing a Bollinger Bands strategy.




This strategy uses only a single indicator, comprised of the TTR function BBands. Parameters for this indicator include number of MA periods, and the size of the bands in standard deviations.

If constructed from scratch, the indicators would consist of:

moving average

a moving average parameterized by MA type (simple, exponential, Kalman, etc.) and MA periods to smooth over

upper band

the upper band constructed classically by standard deviations from the moving average, or alternately by some other upper band generating function, and parameterized chiefly by the amplitude of the band, typically number of standard deviations from the midpoint or moving average indicator

lower band

the lower band traditionally constructed to be symmetrical and opposite the upper band, but potentially constructed via a different function or parameterized differently than the upper band function


The classic Bollinger Bands strategy depends on crossover events (signals) for the upper and lower band and the midpoint.

type sigCrossover, if the Close price is greater than the upper band value.

type sigCrossover, if the Close price is less than the lower band value.


type sigCrossover, if the price at any point crossed the midpoint moving average.


In this strategy, each signal has a corresponding entry or exit rule.

  • type ruleSignal, enter a sell order at market on signal.

  • type ruleSignal, enter a buy order at market on signal.

  • type ruleSignal, enter a market order to close any open position at market on Cross.mid signal.


This strategy may be improved in practice by:


quantstrat documentation built on May 31, 2017, 2:35 a.m.