class SignalTools::Technicals::MACD

Attributes

data[R]
fast[R]
signal[R]
slow[R]

Public Class Methods

new(data, fast, slow, signal) click to toggle source
# File lib/signal_tools/technicals/macd.rb, line 6
def initialize(data, fast, slow, signal)
  @data = data
  @fast = fast
  @slow = slow
  @signal = signal
end

Public Instance Methods

calculate() click to toggle source
# File lib/signal_tools/technicals/macd.rb, line 13
def calculate
  # trim_data_to_range!(macd_points)
  macd_points
end
differences_between_arrays(first_points, second_points) click to toggle source

Returns an array with the differences between the first_points and second_points

# File lib/signal_tools/technicals/macd.rb, line 33
def differences_between_arrays(first_points, second_points)
  SignalTools.truncate_to_shortest!(first_points, second_points)
  differences = []
  first_points.each_with_index { |fp, index| differences << fp - second_points[index] }
  differences
end
macd_and_divergence_points(fast_ema_points, slow_ema_points) click to toggle source
# File lib/signal_tools/technicals/macd.rb, line 25
def macd_and_divergence_points(fast_ema_points, slow_ema_points)
  macds = differences_between_arrays(fast_ema_points, slow_ema_points)
  signal_points = SignalTools::Technicals::EMA.new(macds, signal).calculate
  divergences = differences_between_arrays(macds, signal_points)
  {:signal_points => signal_points, :divergences => divergences}
end
macd_points() click to toggle source

Takes a period of days for fast, slow, signal, and time period (eg 8,17,9).

# File lib/signal_tools/technicals/macd.rb, line 19
def macd_points
  fast_ema_points = SignalTools::Technicals::EMA.new(data, fast).calculate
  slow_ema_points = SignalTools::Technicals::EMA.new(data, slow).calculate
  macd_and_divergence_points(fast_ema_points, slow_ema_points)
end