ux_indicators/
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    type Output;
20    fn next(&mut self, input: T) -> Self::Output;
21}
22
23/// Open price of a particular period.
24pub trait Open {
25    fn open(&self) -> f64;
26}
27
28/// Close price of a particular period.
29pub trait Close {
30    fn close(&self) -> f64;
31}
32
33/// Lowest price of a particular period.
34pub trait Low {
35    fn low(&self) -> f64;
36}
37
38/// Highest price of a particular period.
39pub trait High {
40    fn high(&self) -> f64;
41}
42
43/// Trading volume of a particular trading period.
44pub trait Volume {
45    fn volume(&self) -> f64;
46}
47
48/// Factory trait to create indicator 
49pub trait Factory {
50    fn create() -> Box<dyn Next<f64, Output = Box<[f64]>>>;
51}