Indicators

Bollinger Bands


Description

A Bollinger Band® is a technical analysis tool defined by a set of trendlines plotted two standard deviations (positively and negatively) away from a simple moving average (SMA) of a security's price, but which can be adjusted to user preferences.

For more information, please visit Investopedia.


Params & Instance Methods

#initialze
@param series [Array] An array of prices, typically closing prices 
@param period [Integer] The number of periods to use in the calculation - default 20
@param standard_deviations [Integer] The number of standard deviations to use in the calculation - default 2

#call
@return [Array] An array containing the current upper, middle, and lower bands of the series

#valid?
@return [Boolean] Whether or not the object is valid

Example

require 'ruby-technical-analysis'

series = [31.875, 32.125, 32.3125, 32.125, 31.875]
period = 5

bollinger_bands = 
  RubyTechnicalAnalysis::BollingerBands.new(
    series: series,
    period: period
  )

p bollinger_bands.valid? # true

p bollinger_bands.call # [32.397, 32.062, 31.727]
Previous
Weighted