Indicators
Stochastic Oscillator
Description
A stochastic oscillator is a momentum indicator comparing a particular closing price of a security to a range of its prices over a certain period of time. The sensitivity of the oscillator to market movements is reducible by adjusting that time period or by taking a moving average of the result. It is used to generate overbought and oversold trading signals, utilizing a 0–100 bounded range of values.
For more information, please visit Investopedia.
Params & Instance Methods
#initialize @param series [Array] An array of arrays containing high, low, close prices, e.g. [[high, low, close], [high, low, close]] @param k_periods [Integer] The number of periods to use in the calculation - default is 14 @param k_slow_periods [Integer] The number of periods to use in the calculation - default is 3 @param d_periods [Integer] The number of periods to use in the calculation - default is 3 #call @return [Float] The current Stochastic Oscillator value #valid? @return [Boolean] Whether or not the object is valid
Example
require 'ruby-technical-analysis' series = [[34.375, 33.5312, 34.3125], [34.75, 33.9062, 34.125], [34.2188, 33.6875, 33.75], [33.8281, 33.25, 33.6406], [33.4375, 33, 33.0156], [33.4688, 32.9375, 33.0469], [34.375, 33.25, 34.2969], [34.7188, 34.0469, 34.1406], [34.625, 33.9375, 34.5469]] k_periods = 5 k_slow_periods = 3 d_periods = 3 stochastic_oscillator = RubyTechnicalAnalysis::StochasticOscillator.new( series: series, k_periods: k_periods, k_slow_periods: k_slow_periods, d_periods: d_periods ) p stochastic_oscillator.valid? # true p stochastic_oscillator.call # 55.41