Class: Quant::Indicators::Atr
- Defined in:
- lib/quant/indicators/atr.rb
Constant Summary
Constants inherited from Indicator
Constants included from Mixins::UniversalFilters
Instance Attribute Summary collapse
-
#points ⇒ Object
readonly
Returns the value of attribute points.
Attributes inherited from Indicator
#p0, #p1, #p2, #p3, #series, #source, #t0, #t1, #t2, #t3
Instance Method Summary collapse
-
#compute ⇒ Object
-
Multiply the previous 14-day ATR by 13.
-
- #compute_oscillator ⇒ Object
- #fast_alpha ⇒ Object
- #period ⇒ Object
- #slow_alpha ⇒ Object
Methods inherited from Indicator
#<<, #[], #adaptive_half_period, #adaptive_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, register, #size, #t, #ticks, #values, #warmed_up?
Methods included from Mixins::FisherTransform
#fisher_transform, #inverse_fisher_transform, #relative_fisher_transform
Methods included from Mixins::Stochastic
Methods included from Mixins::SuperSmoother
#three_pole_super_smooth, #two_pole_super_smooth
Methods included from Mixins::HilbertTransform
Methods included from Mixins::ExponentialMovingAverage
Methods included from Mixins::SimpleMovingAverage
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 Attribute Details
#points ⇒ Object (readonly)
Returns the value of attribute points.
30 31 32 |
# File 'lib/quant/indicators/atr.rb', line 30 def points @points end |
Instance Method Details
#compute ⇒ Object
-
Multiply the previous 14-day ATR by 13.
-
Add the most recent day’s TR value.
-
Divide the total by 14
-
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/quant/indicators/atr.rb', line 55 def compute p0.period = period p0.tr = (t1.high_price - t0.close_price).abs p0.value = three_pole_super_smooth :tr, period:, previous: :value p0.slow = (slow_alpha * p0.value) + ((1.0 - slow_alpha) * p1.slow) p0.fast = (fast_alpha * p0.value) + ((1.0 - fast_alpha) * p1.fast) p0.inst_stoch = stochastic :value, period: p0.stoch = three_pole_super_smooth(:inst_stoch, previous: :stoch, period:).clamp(0, 100) p0.stoch_up = p0.stoch >= 70 p0.stoch_turned = p0.stoch_up && !p1.stoch_up compute_oscillator end |
#compute_oscillator ⇒ Object
71 72 73 74 75 |
# File 'lib/quant/indicators/atr.rb', line 71 def compute_oscillator p0.osc = p0.value - wma(:value) p0.crossed = :up if p0.osc >= 0 && p1.osc < 0 p0.crossed = :down if p0.osc <= 0 && p1.osc > 0 end |
#fast_alpha ⇒ Object
36 37 38 |
# File 'lib/quant/indicators/atr.rb', line 36 def fast_alpha period_to_alpha(period) end |
#period ⇒ Object
32 33 34 |
# File 'lib/quant/indicators/atr.rb', line 32 def period dc_period / 2 end |
#slow_alpha ⇒ Object
40 41 42 |
# File 'lib/quant/indicators/atr.rb', line 40 def slow_alpha period_to_alpha(2 * period) end |