Module: WildersSmoothing
- Included in:
- Array
- Defined in:
- lib/ruby-technical-analysis/indicators/wilders_smoothing.rb
Overview
Wilders Smoothing indicator Returns a singular current value
Instance Method Summary collapse
Instance Method Details
#wilders_smoothing(period) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ruby-technical-analysis/indicators/wilders_smoothing.rb', line 8 def wilders_smoothing(period) if size < period raise ArgumentError, "Closes array passed to Wilders Smoothing cannot be less than the period argument." end ws = [] ws << first(period).sma(period) (0..(size - period - 1)).each do |i| ws << ((at(i + period) - ws[i]) * (1.0 / period)) + ws[i] end ws[-1] end |