Class: Quant::Indicators::Adx
- Defined in:
- lib/quant/indicators/adx.rb
Constant Summary
Constants inherited from Indicator
Constants included from Mixins::UniversalFilters
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
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 Method Details
#alpha ⇒ Object
30 31 32 |
# File 'lib/quant/indicators/adx.rb', line 30 def alpha (dc_period) end |
#atr_point ⇒ Object
42 43 44 |
# File 'lib/quant/indicators/adx.rb', line 42 def atr_point series.indicators[source].atr.points[t0] end |
#compute ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/quant/indicators/adx.rb', line 46 def compute # To calculate the ADX, first determine the + and - directional movement, or DM. # The +DM and -DM are found by calculating the "up-move," or current high minus # the previous high, and "down-move," or current low minus the previous low. # If the up-move is greater than the down-move and greater than zero, the +DM equals the up-move; # otherwise, it equals zero. If the down-move is greater than the up-move and greater than zero, # the -DM equals the down-move; otherwise, it equals zero. dm_highs = [t0.high_price - t1.high_price, 0.0].max dm_lows = [t0.low_price - t1.low_price, 0.0].max p0.dmu = dm_highs > dm_lows ? 0.0 : dm_highs p0.dmd = dm_lows > dm_highs ? 0.0 : dm_lows p0.dmu_ema = three_pole_super_smooth :dmu, period:, previous: :dmu_ema p0.dmd_ema = three_pole_super_smooth :dmd, period:, previous: :dmd_ema atr_value = atr_point.fast * scale return if atr_value == 0.0 || @points.size < period # The positive directional indicator, or +DI, equals 100 times the EMA of +DM divided by the ATR # over a given number of time periods. Welles usually used 14 periods. # The negative directional indicator, or -DI, equals 100 times the EMA of -DM divided by the ATR. p0.diu = (100.0 * p0.dmu_ema) / atr_value p0.did = (100.0 * p0.dmd_ema) / atr_value # The ADX indicator itself equals 100 times the EMA of the absolute value of (+DI minus -DI) # divided by (+DI plus -DI). delta = p0.diu + p0.did p0.di = (p0.diu - p1.did).abs / delta p0.di_ema = three_pole_super_smooth(:di, period:, previous: :di_ema).clamp(-10.0, 10.0) p0.value = p0.di_ema p0.inst_stoch = stochastic :di, period: dc_period p0.stoch = three_pole_super_smooth :inst_stoch, period:, previous: :stoch end |
#period ⇒ Object
38 39 40 |
# File 'lib/quant/indicators/adx.rb', line 38 def period dc_period end |
#scale ⇒ Object
34 35 36 |
# File 'lib/quant/indicators/adx.rb', line 34 def scale 1.0 end |