Class: RubyTechnicalAnalysis::Macd

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

Overview

Moving Average Convergence Divergence (MACD)

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

Instance Attribute Summary collapse

Attributes inherited from Indicator

#series

Instance Method Summary collapse

Methods inherited from Indicator

call

Constructor Details

#initialize(series: [], fast_period: 12, slow_period: 26, signal_period: 9) ⇒ Macd

Returns a new instance of Macd.

Parameters:

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

    An array of prices, typically closing prices

  • fast_period (Integer) (defaults to: 12)

    The number of periods to use in the fast calculation

  • slow_period (Integer) (defaults to: 26)

    The number of periods to use in the slow calculation

  • signal_period (Integer) (defaults to: 9)

    The number of periods to use in the signal calculation



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

def initialize(series: [], fast_period: 12, slow_period: 26, signal_period: 9)
  @fast_period = fast_period
  @slow_period = slow_period
  @signal_period = signal_period

  super(series: series)
end

Instance Attribute Details

#fast_periodObject (readonly)

Returns the value of attribute fast_period.



6
7
8
# File 'lib/ruby_technical_analysis/indicators/macd.rb', line 6

def fast_period
  @fast_period
end

#signal_periodObject (readonly)

Returns the value of attribute signal_period.



6
7
8
# File 'lib/ruby_technical_analysis/indicators/macd.rb', line 6

def signal_period
  @signal_period
end

#slow_periodObject (readonly)

Returns the value of attribute slow_period.



6
7
8
# File 'lib/ruby_technical_analysis/indicators/macd.rb', line 6

def slow_period
  @slow_period
end

Instance Method Details

#callArray

Returns An array containing the current MACD line, signal line, and histogram values.

Returns:

  • (Array)

    An array containing the current MACD line, signal line, and histogram values



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

def call
  calculate_macd
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/macd.rb', line 26

def valid?
  series.length >= slow_period + signal_period
end