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