Class: RubyTechnicalAnalysis::VolumeOscillator

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

Overview

Instance Attribute Summary collapse

Attributes inherited from Indicator

#series

Instance Method Summary collapse

Methods inherited from Indicator

call

Constructor Details

#initialize(series: [], short_ma_period: 20, long_ma_period: 60) ⇒ VolumeOscillator

Returns a new instance of VolumeOscillator.

Parameters:

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

    An array of volume values

  • short_ma_period (Integer) (defaults to: 20)

    The number of periods to use in the calculation of the short moving average

  • long_ma_period (Integer) (defaults to: 60)

    The number of periods to use in the calculation of the long moving average



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

def initialize(series: [], short_ma_period: 20, long_ma_period: 60)
  @short_ma_period = short_ma_period
  @long_ma_period = long_ma_period

  super(series: series)
end

Instance Attribute Details

#long_ma_periodObject (readonly)

Returns the value of attribute long_ma_period.



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

def long_ma_period
  @long_ma_period
end

#short_ma_periodObject (readonly)

Returns the value of attribute short_ma_period.



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

def short_ma_period
  @short_ma_period
end

Instance Method Details

#callFloat

Returns The current volume oscillator value.

Returns:

  • (Float)

    The current volume oscillator value



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

def call
  calculate_volume_oscillator
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/volume_oscillator.rb', line 24

def valid?
  short_ma_period < long_ma_period && long_ma_period <= series.length
end