pub struct RelativeStrengthIndex { /* private fields */ }
Expand description
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.
§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
Implementations§
Trait Implementations§
Source§impl Clone for RelativeStrengthIndex
impl Clone for RelativeStrengthIndex
Source§fn clone(&self) -> RelativeStrengthIndex
fn clone(&self) -> RelativeStrengthIndex
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for RelativeStrengthIndex
impl Debug for RelativeStrengthIndex
Source§impl Default for RelativeStrengthIndex
impl Default for RelativeStrengthIndex
Source§impl Display for RelativeStrengthIndex
impl Display for RelativeStrengthIndex
Auto Trait Implementations§
impl Freeze for RelativeStrengthIndex
impl RefUnwindSafe for RelativeStrengthIndex
impl Send for RelativeStrengthIndex
impl Sync for RelativeStrengthIndex
impl Unpin for RelativeStrengthIndex
impl UnwindSafe for RelativeStrengthIndex
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