pub struct MACD {
pub fast_ema: ExponentialMovingAverage,
pub slow_ema: ExponentialMovingAverage,
pub signal_ema: ExponentialMovingAverage,
pub histogram: Vec<f64>,
}Expand description
MACD (Moving Average Convergence Divergence) indicator.
Fields§
§fast_ema: ExponentialMovingAverage§slow_ema: ExponentialMovingAverage§signal_ema: ExponentialMovingAverage§histogram: Vec<f64>Implementations§
Source§impl MACD
impl MACD
Sourcepub fn calculate(&mut self, price: f64) -> Option<MACDResult>
pub fn calculate(&mut self, price: f64) -> Option<MACDResult>
Updates the MACD calculation with a new price and returns the current MACD result.
The method updates the fast and slow EMAs with the new price, calculates the MACD line as the difference between the fast and slow EMAs, and then updates the signal EMA using the MACD line. The histogram is computed as the difference between the MACD line and the signal line.
§Arguments
price- The latest price.
§Returns
Some(MACDResult)containing the MACD line, signal line, histogram, and trading signal, if the EMAs have been sufficiently initialized.Noneif any of the EMA calculations are not yet available.
Sourcepub fn determine_signal(&self, macd: f64, signal: f64) -> TradingSignal
pub fn determine_signal(&self, macd: f64, signal: f64) -> TradingSignal
Determines the trading signal based on the MACD line and the signal line.
If the MACD line is above the signal line, returns Buy.
If the MACD line is below the signal line, returns Sell.
Otherwise, returns Hold.
§Arguments
macd- The current MACD line value.signal- The current signal line value.
§Returns
A TradingSignal representing the trading recommendation.
Auto Trait Implementations§
impl Freeze for MACD
impl RefUnwindSafe for MACD
impl Send for MACD
impl Sync for MACD
impl Unpin for MACD
impl UnwindSafe for MACD
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more