Class: RubyTechnicalAnalysis::ChaikinMoneyFlow

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

Overview

Instance Attribute Summary collapse

Attributes inherited from Indicator

#series

Instance Method Summary collapse

Methods inherited from Indicator

call

Constructor Details

#initialize(series: [], period: 21) ⇒ ChaikinMoneyFlow

Returns a new instance of ChaikinMoneyFlow.

Parameters:

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

    An array of arrays containing high, low, close, and volume information, e.g. [[high, low, close, volume], [high, low, close, volume]]

  • period (Integer) (defaults to: 21)

    The number of periods to use in the calculation



10
11
12
13
14
15
16
# File 'lib/ruby_technical_analysis/indicators/chaikin_money_flow.rb', line 10

def initialize(series: [], period: 21)
  @period = period
  @cmf_sum = 0
  @vol_sum = 0

  super(series: series)
end

Instance Attribute Details

#periodObject (readonly)

Returns the value of attribute period.



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

def period
  @period
end

Instance Method Details

#callFloat

Returns The current Chaikin Money Flow value.

Returns:

  • (Float)

    The current Chaikin Money Flow value



19
20
21
# File 'lib/ruby_technical_analysis/indicators/chaikin_money_flow.rb', line 19

def call
  calculate_cmf
end

#valid?Boolean

Returns Whether or not the object is valid.

Returns:

  • (Boolean)

    Whether or not the object is valid



24
25
26
# File 'lib/ruby_technical_analysis/indicators/chaikin_money_flow.rb', line 24

def valid?
  period <= series.length
end