cxmr_ta_core/traits.rs
1// Indicator traits
2//
3
4/// Resets an indicator to the initial state.
5pub trait Reset {
6 fn reset(&mut self);
7}
8
9/// Consumes a data item of type `T` and returns `Output`.
10///
11/// Typically `T` can be `f64` or a struct similar to [DataItem](struct.DataItem.html), that implements
12/// traits necessary to calculate value of a particular indicator.
13///
14/// In most cases `Output` is `f64`, but sometimes it can be different. For example for
15/// [MACD](indicators/struct.MovingAverageConvergenceDivergence.html) it is `(f64, f64, f64)` since
16/// MACD returns 3 values.
17///
18pub trait Next<T> {
19 fn next(&mut self, input: &T) -> f64;
20}
21
22pub trait Calculate {
23 fn calc(&mut self, input: f64) -> f64;
24}
25
26/// Open price of a particular period.
27pub trait Open {
28 fn open(&self) -> f64;
29}
30
31/// Close price of a particular period.
32pub trait Close {
33 fn close(&self) -> f64;
34}
35
36/// Lowest price of a particular period.
37pub trait Low {
38 fn low(&self) -> f64;
39}
40
41/// Highest price of a particular period.
42pub trait High {
43 fn high(&self) -> f64;
44}
45
46/// Trading volume of a particular trading period.
47pub trait Volume {
48 fn volume(&self) -> f64;
49}