Module main

Source
Expand description

§Stochastic Oscillator Module

This module implements a Stochastic Oscillator indicator. It computes %K and %D values based on a sliding window of prices. The oscillator can be smoothed using a %K smoothing parameter.

The indicator also generates a trading signal, a condition, a crossover type, and a strength value.

§Example

use indexes_rs::v1::stochastic::main::StochasticOscillator;
use indexes_rs::v1::stochastic::types::{StochResult, StochSignal, StochCondition, StochCrossover};

let mut stoch = StochasticOscillator::new(
    StochasticOscillator::DEFAULT_PERIOD,
    StochasticOscillator::DEFAULT_K_SMOOTH,
    StochasticOscillator::DEFAULT_D_PERIOD
);

// Feed in a series of prices (for example, closing prices).
let prices = vec![100.0, 102.0, 101.5, 103.0, 104.0, 102.5, 101.0, 100.5, 99.5, 98.0, 97.5, 98.5];
let mut result: Option<StochResult> = None;
for price in prices {
    result = stoch.calculate(price);
}

if let Some(res) = result {
    println!("K value: {:.2}", res.k_value);
    println!("D value: {:.2}", res.d_value);
    println!("Signal: {:?}", res.signal);
    println!("Condition: {:?}", res.condition);
    println!("Crossover: {:?}", res.crossover);
    println!("Strength: {:.2}%", res.strength);
}

Structs§

StochasticOscillator
A Stochastic Oscillator indicator.