Sha256: 16c4c427c6c53834de5754cf2d15007877c7b5f60918b94bfe804c9cd6202214
Contents?: true
Size: 868 Bytes
Versions: 21
Compression:
Stored size: 868 Bytes
Contents
# lib/sqa/indicator/true_range.rb # See Also: average_true_range class SQA::Indicator; class << self # @param high_prices [Array] # @param low_prices [Array] # @param previous_closes [Array] # # @return [Array] # def true_range( high_prices, # Array of high prices low_prices, # Array of low prices closing_prices # Array of closing prices ) true_ranges = [] high_prices.each_with_index do |high, index| if index > 0 low = low_prices[index] previous_close = closing_prices[index - 1] true_range = [ high - low, (high - previous_close).abs, (low - previous_close).abs ].max true_ranges << true_range end end true_ranges # Array of True Range values end alias_method :tr, :true_range end; end
Version data entries
21 entries across 21 versions & 1 rubygems