[][src]Struct cxmr_ta_core::indicators::RelativeStrengthIndex

pub struct RelativeStrengthIndex { /* fields omitted */ }

The relative strength index (RSI).

It is a momentum oscillator, that compares the magnitude of recent gains and losses over a specified time period to measure speed and change of price movements of a security. It is primarily used to attempt to identify overbought or oversold conditions in the trading of an asset.

The oscillator returns output in the range of 0..100.

RSI

Formula

RSIt = EMAUt * 100 / (EMAUt + EMADt)

Where:

  • RSIt - value of RSI indicator in a moment of time t
  • EMAUt - value of EMA of up periods in a moment of time t
  • EMADt - value of EMA of down periods in a moment of time t

If current period has value higher than previous period, than:

U = pt - pt-1

D = 0

Otherwise:

U = 0

D = pt-1 - pt

Where:

  • U = up period value
  • D = down period value
  • pt - input value in a moment of time t
  • pt-1 - input value in a moment of time t-1

Parameters

  • n - number of periods (integer greater than 0). Default value is 14.

Example

use ta::indicators::RelativeStrengthIndex;
use ta::{Calculate, Next};

let mut rsi = RelativeStrengthIndex::new(3).unwrap();
assert_eq!(rsi.calc(10.0), 50.0);
assert_eq!(rsi.calc(10.5).round(), 86.0);
assert_eq!(rsi.calc(10.0).round(), 35.0);
assert_eq!(rsi.calc(9.5).round(), 16.0);

Links

Methods

impl RelativeStrengthIndex[src]

pub fn new(n: u32) -> Result<Self>[src]

Trait Implementations

impl Calculate for RelativeStrengthIndex[src]

impl Clone for RelativeStrengthIndex[src]

impl Debug for RelativeStrengthIndex[src]

impl Default for RelativeStrengthIndex[src]

impl Display for RelativeStrengthIndex[src]

impl<T: Close> Next<T> for RelativeStrengthIndex[src]

impl Reset for RelativeStrengthIndex[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.