Struct ta::indicators::RateOfChange [−][src]
pub struct RateOfChange { /* fields omitted */ }
Expand description
Rate of Change (ROC)
Formula
ROC = (Pricet - Pricet-n) / Pricet-n * 100
Where:
- ROC - current value of Rate of Change indicator
- Pt - price at the moment
- Pt-n - price n periods ago
Parameters
- period - number of periods integer greater than 0
Example
use ta::indicators::RateOfChange; use ta::Next; let mut roc = RateOfChange::new(2).unwrap(); assert_eq!(roc.next(10.0), 0.0); // 0 assert_eq!(roc.next(9.7).round(), -3.0); // (9.7 - 10) / 10 * 100 = -3 assert_eq!(roc.next(20.0).round(), 100.0); // (20 - 10) / 10 * 100 = 100 assert_eq!(roc.next(20.0).round(), 106.0); // (20 - 9.7) / 9.7 * 100 = 106
Links
Implementations
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for RateOfChange
impl Send for RateOfChange
impl Sync for RateOfChange
impl Unpin for RateOfChange
impl UnwindSafe for RateOfChange
Blanket Implementations
Mutably borrows from an owned value. Read more