Module: Qstick
- Included in:
- Array
- Defined in:
- lib/ruby-technical-analysis/indicators/qstick.rb
Overview
Qstick indicator Returns a single value
Instance Method Summary collapse
Instance Method Details
#qstick(period) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ruby-technical-analysis/indicators/qstick.rb', line 6 def qstick(period) opens = [] closes = [] each do |i| opens << i[0] closes << i[1] end if opens.size < period raise ArgumentError, "Opens array passed to Qstick cannot be less than the period argument." end if closes.size < period raise ArgumentError, "Closes array passed to Qstick cannot be less than the period argument." end opens = opens.last(period) closes = closes.last(period) cmo_sum = 0.0 (0..(period - 1)).each do |i| cmo_sum += closes[i] - opens[i] end (cmo_sum.to_f / period).round(4) end |