Class: RubyTechnicalAnalysis::EnvelopesEma

Inherits:
Indicator
  • Object
show all
Defined in:
lib/ruby_technical_analysis/indicators/envelopes_ema.rb

Overview

Envelopes EMA

Find more information at: www.fidelity.com/learning-center/trading-investing/technical-analysis/technical-indicator-guide/mae

Note that this indicator is similar but not the exact same as the one in the link above. This indicator is based on the EMA, not the SMA.

Instance Attribute Summary collapse

Attributes inherited from Indicator

#series

Instance Method Summary collapse

Methods inherited from Indicator

call

Constructor Details

#initialize(series: [], period: 20, percent: 5) ⇒ EnvelopesEma

Returns a new instance of EnvelopesEma.

Parameters:

  • series (Array) (defaults to: [])

    An array of prices, typically closing prices

  • period (Integer) (defaults to: 20)

    The number of periods to use in the calculation

  • percent (Integer) (defaults to: 5)

    The percent to use in the calculation



13
14
15
16
17
18
# File 'lib/ruby_technical_analysis/indicators/envelopes_ema.rb', line 13

def initialize(series: [], period: 20, percent: 5)
  @period = period
  @percent = percent

  super(series: series)
end

Instance Attribute Details

#percentObject (readonly)

Returns the value of attribute percent.



8
9
10
# File 'lib/ruby_technical_analysis/indicators/envelopes_ema.rb', line 8

def percent
  @percent
end

#periodObject (readonly)

Returns the value of attribute period.



8
9
10
# File 'lib/ruby_technical_analysis/indicators/envelopes_ema.rb', line 8

def period
  @period
end

Instance Method Details

#callArray

Returns An array containing the current upper, middle, and lower bands of the series.

Returns:

  • (Array)

    An array containing the current upper, middle, and lower bands of the series



21
22
23
# File 'lib/ruby_technical_analysis/indicators/envelopes_ema.rb', line 21

def call
  caluculate_envelopes_ema
end

#valid?Boolean

Returns Whether or not the object is valid.

Returns:

  • (Boolean)

    Whether or not the object is valid



26
27
28
# File 'lib/ruby_technical_analysis/indicators/envelopes_ema.rb', line 26

def valid?
  period <= series.length && percent <= 100
end