Expand description
§MACD (Moving Average Convergence Divergence) Module
This module implements the MACD indicator using three exponential moving averages:
- A fast EMA (short period)
- A slow EMA (long period)
- A signal EMA (for smoothing the MACD line)
The MACD line is calculated as the difference between the fast and slow EMAs. The signal line is calculated as the EMA of the MACD line, and the histogram is the difference between the MACD line and the signal line. Additionally, a trading signal is generated based on the relationship between the MACD line and the signal line.
§Examples
use indexes_rs::v1::macd::main::MACD;
use indexes_rs::v1::macd::types::MACDResult;
use indexes_rs::v1::types::TradingSignal;
// Create a MACD indicator with fast=12, slow=26, and signal=9 periods
let mut macd = MACD::new(12, 26, 9);
// Simulate feeding prices
let prices = vec![44.0, 44.5, 45.0, 44.8, 45.2, 45.5, 45.3];
let mut result = None;
for price in prices {
result = macd.calculate(price);
}
if let Some(res) = result {
println!("MACD Line: {:.2}", res.macd_line);
println!("Signal Line: {:.2}", res.signal_line);
println!("Histogram: {:.2}", res.histogram);
println!("Trading Signal: {:?}", res.signal);
}Structs§
- MACD
- MACD (Moving Average Convergence Divergence) indicator.