Struct MovingAverages

Source
pub struct MovingAverages {
    pub sma: SMAPeriods,
    pub ema: EMAPeriods,
    pub macd: MACD,
}
Expand description

A container for the different moving average indicators.

Fields§

§sma: SMAPeriods§ema: EMAPeriods§macd: MACD

Implementations§

Source§

impl MovingAverages

Source

pub fn with_params( sma_short: Option<usize>, sma_medium: Option<usize>, sma_long: Option<usize>, ema_short: Option<usize>, ema_medium: Option<usize>, ema_long: Option<usize>, macd_fast: Option<usize>, macd_slow: Option<usize>, macd_signal: Option<usize>, ) -> Result<Self, SMAError>

Creates a new MovingAverages instance with custom parameters.

§Arguments
  • sma_short - Optional SMA short period (default: 20).
  • sma_medium - Optional SMA medium period (default: 50).
  • sma_long - Optional SMA long period (default: 200).
  • ema_short - Optional EMA short period (default: 20).
  • ema_medium - Optional EMA medium period (default: 50).
  • ema_long - Optional EMA long period (default: 200).
  • macd_fast - Optional MACD fast period (default: 12).
  • macd_slow - Optional MACD slow period (default: 26).
  • macd_signal - Optional MACD signal period (default: 9).
Source

pub fn calculate(&mut self, price: f64) -> MovingAverageResults

Updates all moving averages with the new price and returns the consolidated results.

§Arguments
  • price - The latest price value.

Trait Implementations§

Source§

impl Default for MovingAverages

Source§

fn default() -> Self

Creates a new MovingAverages instance using default parameters.

  • SMA periods: short = 20, medium = 50, long = 200
  • EMA periods: short = 20, medium = 50, long = 200
  • MACD parameters: fast = 12, slow = 26, signal = 9

Auto Trait Implementations§

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.