Module main

Source
Expand description

§Bollinger Bands Module

This module implements Bollinger Bands using a Simple Moving Average (SMA) for the middle band and the standard deviation of prices for the band width. The upper band is defined as the middle band plus a specified multiplier times the standard deviation, and the lower band is defined as the middle band minus that value.

§Examples

use indexes_rs::v1::bollinger::main::BollingerBands;
use indexes_rs::v1::bollinger::types::BBResult;

// Create a BollingerBands indicator with a period of 20 and multiplier of 2.0
let mut bb = BollingerBands::new(20, 2.0).unwrap();

// Feed in prices (e.g., closing prices)
let prices = vec![
    100.0, 101.0, 102.0, 101.5, 100.5, 102.0, 103.0, 102.5, 104.0, 105.0,
    104.5, 105.5, 106.0, 107.0, 106.5, 108.0, 107.5, 108.5, 109.0, 110.0,
];

if let Some(result) = prices.into_iter().fold(None, |_, price| bb.calculate(price)) {
    println!("Upper Band: {:.2}", result.upper);
    println!("Middle Band: {:.2}", result.middle);
    println!("Lower Band: {:.2}", result.lower);
}

Structs§

BollingerBands
Bollinger Bands indicator.