Module: BollingerBands
- Included in:
- Array
- Defined in:
- lib/ruby-technical-analysis/indicators/bollinger_bands.rb
Overview
Bollinger Bands indicator Returns an array containing the current upper, middle, and lower bands of the series
Instance Method Summary collapse
Instance Method Details
#bollinger_bands(period) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ruby-technical-analysis/indicators/bollinger_bands.rb', line 9 def bollinger_bands(period) if size < period raise ArgumentError, "Array passed to Bollinger Bands cannot be less than the period argument." end closes = last(period) middle = closes.sma(period) twice_sd = (2 * closes.standard_deviation).truncate(4) upper = twice_sd + middle lower = middle - twice_sd [upper, middle, lower] end |