Sha256: 9b4acfc7e675f35bd07d741019d76fa7a995451d514feeb023c521016a89d984

Contents?: true

Size: 985 Bytes

Versions: 20

Compression:

Stored size: 985 Bytes

Contents

# lib/sqa/indicator/average_true_range.rb

# See Also: true_range

class SQA::Indicator; class << self

  def average_true_range(
        high_prices,  # Array of the day's high price
        low_prices,   # Array of the day's low price
        close_prices, # Array of the day's closing price
        period        # Integer the number of days to consider
      )
    true_ranges = true_range(high_prices, low_prices, close_prices)
    atr_values  = []

    # debug_me{[ :period, :true_ranges ]}

    window_span = period - 1

    true_ranges.size.times do |inx|
      start_inx = inx - window_span
      end_inx   = start_inx + window_span

      start_inx = 0 if start_inx < 0

      window    = true_ranges[start_inx..end_inx]

      # debug_me{[
      #   :inx,
      #   :start_inx,
      #   :end_inx,
      #   :window,
      #   "window.mean"
      # ]}

      atr_values << window.mean
    end

    atr_values # Array
  end
  alias_method :atr, :average_true_range

end; end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
sqa-0.0.22 lib/sqa/indicator/average_true_range.rb
sqa-0.0.21 lib/sqa/indicator/average_true_range.rb
sqa-0.0.20 lib/sqa/indicator/average_true_range.rb
sqa-0.0.19 lib/sqa/indicator/average_true_range.rb
sqa-0.0.18 lib/sqa/indicator/average_true_range.rb
sqa-0.0.17 lib/sqa/indicator/average_true_range.rb
sqa-0.0.15 lib/sqa/indicator/average_true_range.rb
sqa-0.0.14 lib/sqa/indicator/average_true_range.rb
sqa-0.0.13 lib/sqa/indicator/average_true_range.rb
sqa-0.0.12 lib/sqa/indicator/average_true_range.rb
sqa-0.0.11 lib/sqa/indicator/average_true_range.rb
sqa-0.0.10 lib/sqa/indicator/average_true_range.rb
sqa-0.0.9 lib/sqa/indicator/average_true_range.rb
sqa-0.0.8 lib/sqa/indicator/average_true_range.rb
sqa-0.0.7 lib/sqa/indicator/average_true_range.rb
sqa-0.0.6 lib/sqa/indicator/average_true_range.rb
sqa-0.0.5 lib/sqa/indicator/average_true_range.rb
sqa-0.0.4 lib/sqa/indicator/average_true_range.rb
sqa-0.0.3 lib/sqa/indicator/average_true_range.rb
sqa-0.0.2 lib/sqa/indicator/average_true_range.rb