Class: RubyTechnicalAnalysis::WilliamsPercentR

Inherits:
Indicator
  • Object
show all
Defined in:
lib/ruby_technical_analysis/indicators/williams_percent_r.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: 14) ⇒ WilliamsPercentR

Returns a new instance of WilliamsPercentR.

Parameters:

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

    An array of arrays containing high, low, close prices, e.g. [[high, low, close], [high, low, close]]

  • period (Integer) (defaults to: 14)

    The number of periods to use in the calculation



10
11
12
13
14
15
16
17
18
19
# File 'lib/ruby_technical_analysis/indicators/williams_percent_r.rb', line 10

def initialize(series: [], period: 14)
  @period = period
  @highest_highs = []
  @lowest_lows = []
  @highest_highs_minus_close = []
  @highest_highs_minus_lowest_lows = []
  @pct_r = []

  super(series: series)
end

Instance Attribute Details

#periodObject (readonly)

Returns the value of attribute period.



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

def period
  @period
end

Instance Method Details

#callFloat

Returns The current Williams %R value.

Returns:

  • (Float)

    The current Williams %R value



22
23
24
# File 'lib/ruby_technical_analysis/indicators/williams_percent_r.rb', line 22

def call
  calculate_williams_percent_r
end

#valid?Boolean

Returns Whether or not the object is valid.

Returns:

  • (Boolean)

    Whether or not the object is valid



27
28
29
# File 'lib/ruby_technical_analysis/indicators/williams_percent_r.rb', line 27

def valid?
  period < series.length
end