Struct MACD

Source
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

Source

pub fn new(fast_period: usize, slow_period: usize, signal_period: usize) -> Self

Creates a new MACD indicator.

§Arguments
  • fast_period - The period for the fast EMA.
  • slow_period - The period for the slow EMA.
  • signal_period - The period for the signal EMA.
§Example
use indexes_rs::v1::macd::main::MACD;

let macd = MACD::new(12, 26, 9);
Source

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.
  • None if any of the EMA calculations are not yet available.
Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.