pub struct StochasticOscillator { /* private fields */ }Expand description
Stochastic Oscillator Calculator
The Stochastic Oscillator is a momentum indicator that shows the location of the close relative to the high-low range over a set number of periods.
%K = (Current Close - Lowest Low) / (Highest High - Lowest Low) * 100 %D = SMA of %K over smoothing period
Typical settings: (14, 3, 3) or (5, 3, 3) for faster signals
Implementations§
Source§impl StochasticOscillator
impl StochasticOscillator
Sourcepub fn new(
period: usize,
k_smooth: usize,
d_period: usize,
) -> Result<Self, StochasticError>
pub fn new( period: usize, k_smooth: usize, d_period: usize, ) -> Result<Self, StochasticError>
Creates a new Stochastic Oscillator with specified parameters
§Arguments
period- Lookback period for high/low (typically 14)k_smooth- Smoothing period for %K (typically 3)d_period- Period for %D calculation (typically 3)
Sourcepub fn default() -> Self
pub fn default() -> Self
Creates a new Stochastic Oscillator with default parameters (14, 3, 3)
Sourcepub fn update(&mut self, data: OHLCData) -> Option<StochasticResult>
pub fn update(&mut self, data: OHLCData) -> Option<StochasticResult>
Updates the oscillator with OHLC data
Sourcepub fn update_hlc(
&mut self,
high: f64,
low: f64,
close: f64,
) -> Option<StochasticResult>
pub fn update_hlc( &mut self, high: f64, low: f64, close: f64, ) -> Option<StochasticResult>
Updates with separate high, low, close values
Sourcepub fn value(&self) -> Option<StochasticResult>
pub fn value(&self) -> Option<StochasticResult>
Returns the current Stochastic values
Sourcepub fn calculate_batch(
period: usize,
k_smooth: usize,
d_period: usize,
data: &[OHLCData],
) -> Result<Vec<Option<StochasticResult>>, StochasticError>
pub fn calculate_batch( period: usize, k_smooth: usize, d_period: usize, data: &[OHLCData], ) -> Result<Vec<Option<StochasticResult>>, StochasticError>
Batch calculation for historical data
Sourcepub fn fast(period: usize) -> Result<Self, StochasticError>
pub fn fast(period: usize) -> Result<Self, StochasticError>
Fast Stochastic (no smoothing)
Sourcepub fn slow(period: usize) -> Result<Self, StochasticError>
pub fn slow(period: usize) -> Result<Self, StochasticError>
Slow Stochastic (standard smoothing)
Sourcepub fn full(
period: usize,
k_smooth: usize,
d_period: usize,
) -> Result<Self, StochasticError>
pub fn full( period: usize, k_smooth: usize, d_period: usize, ) -> Result<Self, StochasticError>
Full Stochastic (customizable smoothing)
Sourcepub fn signal(&self) -> Option<StochasticSignal>
pub fn signal(&self) -> Option<StochasticSignal>
Get crossover signal