Class: Quant::Indicators::Mesa

Inherits:
Indicator show all
Defined in:
lib/quant/indicators/mesa.rb

Overview

www.mesasoftware.com/papers/MAMA.pdf MESA Adaptive Moving Average (MAMA) adapts to price movement in an entirely new and unique way. The adapation is based on the rate change of phase as measured by the Hilbert Transform Discriminator.

This version of Ehler’s MAMA indicator ties into the homodyne dominant cycle indicator to provide a more efficient computation for this indicator. If you’re using the homodyne in all your indicators for the dominant cycle, then this version is useful as it avoids extra computational steps.

Constant Summary collapse

FAMA =
0.500
GAMA =
0.950
DAMA =
0.125
LAMA =
0.100
FAGA =
0.050

Constants inherited from Indicator

Indicator::PRIORITIES

Constants included from Mixins::UniversalFilters

Mixins::UniversalFilters::K

Instance Attribute Summary

Attributes inherited from Indicator

#p0, #p1, #p2, #p3, #series, #source, #t0, #t1, #t2, #t3

Instance Method Summary collapse

Methods inherited from Indicator

#<<, #[], #dc_period, dependent_indicator_classes, depends_on, #dominant_cycle, #dominant_cycle_indicator_class, #dominant_cycle_kind, #each, #half_period, #indicator_name, #initialize, #input, #inspect, #max_period, #micro_period, #min_period, #p, #period_points, #pivot_kind, #points_class, #priority, #size, #t, #ticks, #values

Methods included from Mixins::FisherTransform

#fisher_transform, #inverse_fisher_transform, #relative_fisher_transform

Methods included from Mixins::Stochastic

#stochastic

Methods included from Mixins::SuperSmoother

#three_pole_super_smooth, #two_pole_super_smooth

Methods included from Mixins::HilbertTransform

#hilbert_transform

Methods included from Mixins::ExponentialMovingAverage

#exponential_moving_average

Methods included from Mixins::SimpleMovingAverage

#simple_moving_average

Methods included from Mixins::WeightedMovingAverage

#extended_weighted_moving_average, #weighted_moving_average

Methods included from Mixins::UniversalFilters

#universal_band_pass, #universal_ema, #universal_filter, #universal_one_pole_high_pass, #universal_one_pole_low_pass, #universal_two_pole_high_pass, #universal_two_pole_low_pass

Methods included from Mixins::ButterworthFilters

#three_pole_butterworth, #two_pole_butterworth

Methods included from Mixins::HighPassFilters

#high_pass_filter, #hpf2, #two_pole_high_pass_filter

Methods included from Mixins::Functions

#angle, #bars_to_alpha, #deg2rad, #period_to_alpha, #rad2deg

Constructor Details

This class inherits a constructor from Quant::Indicators::Indicator

Instance Method Details

#computeObject



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/quant/indicators/mesa.rb', line 66

def compute
  alpha = [fast_limit / delta_phase, slow_limit].max

  p0.mama = (alpha * p0.input) + ((1.0 - alpha) * p1.mama)
  p0.fama = (FAMA * alpha * p0.mama) + ((1.0 - (FAMA * alpha)) * p1.fama)
  p0.gama = (GAMA * alpha * p0.mama) + ((1.0 - (GAMA * alpha)) * p1.gama)
  p0.dama = (DAMA * alpha * p0.mama) + ((1.0 - (DAMA * alpha)) * p1.dama)
  p0.lama = (LAMA * alpha * p0.mama) + ((1.0 - (LAMA * alpha)) * p1.lama)
  p0.faga = (FAGA * alpha * p0.fama) + ((1.0 - (FAGA * alpha)) * p1.faga)

  compute_oscillator
end

#compute_oscillatorObject



79
80
81
82
83
# File 'lib/quant/indicators/mesa.rb', line 79

def compute_oscillator
  p0.osc = p0.mama - p0.fama
  p0.crossed = :up if p0.osc >= 0 && p1.osc < 0
  p0.crossed = :down if p0.osc <= 0 && p1.osc > 0
end

#current_dominant_cycleObject



52
53
54
# File 'lib/quant/indicators/mesa.rb', line 52

def current_dominant_cycle
  homodyne_dominant_cycle.points[t0]
end

#delta_phaseObject



56
57
58
# File 'lib/quant/indicators/mesa.rb', line 56

def delta_phase
  current_dominant_cycle.delta_phase
end

#fast_limitObject



40
41
42
# File 'lib/quant/indicators/mesa.rb', line 40

def fast_limit
  @fast_limit ||= bars_to_alpha(min_period / 2)
end

#homodyne_dominant_cycleObject



48
49
50
# File 'lib/quant/indicators/mesa.rb', line 48

def homodyne_dominant_cycle
  series.indicators[source].dominant_cycles.homodyne
end

#periodObject



36
37
38
# File 'lib/quant/indicators/mesa.rb', line 36

def period
  dc_period
end

#slow_limitObject



44
45
46
# File 'lib/quant/indicators/mesa.rb', line 44

def slow_limit
  @slow_limit ||= bars_to_alpha(max_period)
end