Class: Quant::Indicators::Ma

Inherits:
Indicator show all
Includes:
Mixins::Filters
Defined in:
lib/quant/indicators/ma.rb

Overview

Moving Averages

Instance Attribute Summary

Attributes inherited from Indicator

#p0, #p1, #p2, #p3, #series, #source, #t0, #t1, #t2, #t3

Instance Method Summary collapse

Methods included from Mixins::Filters

#band_pass, #bars_to_alpha, #ema, #period_to_alpha, #three_pole_butterworth, #two_pole_butterworth

Methods included from Mixins::Trig

#angle, #deg2rad, #rad2deg

Methods inherited from Indicator

#<<, #each, #indicator_name, #initialize, #input, #inspect, #p, #points_class, #size, #t, #ticks, #values

Constructor Details

This class inherits a constructor from Quant::Indicators::Indicator

Instance Method Details

#alpha(period) ⇒ Object



19
20
21
# File 'lib/quant/indicators/ma.rb', line 19

def alpha(period)
  bars_to_alpha(period)
end

#computeObject



31
32
33
34
35
# File 'lib/quant/indicators/ma.rb', line 31

def compute
  # p0.ss = super_smoother input, :ss, min_period
  p0.ema = alpha(max_period) * input + (1 - alpha(max_period)) * p1.ema
  p0.osc = p0.ss - p0.ema
end

#max_periodObject



27
28
29
# File 'lib/quant/indicators/ma.rb', line 27

def max_period
  48 # Quant.config.indicators.max_period
end

#min_periodObject



23
24
25
# File 'lib/quant/indicators/ma.rb', line 23

def min_period
  8 # Quant.config.indicators.min_period
end