egui_charts/model/
price_source.rs1#[derive(
7 Clone, Copy, Debug, PartialEq, Eq, Hash, Default, serde::Serialize, serde::Deserialize,
8)]
9pub enum PriceSource {
10 Open,
12 High,
14 Low,
16 #[default]
18 Close,
19 HL2,
21 HLC3,
23 OHLC4,
25}
26
27impl PriceSource {
28 pub fn label(&self) -> &'static str {
30 match self {
31 Self::Open => "Open",
32 Self::High => "High",
33 Self::Low => "Low",
34 Self::Close => "Close",
35 Self::HL2 => "HL/2",
36 Self::HLC3 => "HLC/3",
37 Self::OHLC4 => "OHLC/4",
38 }
39 }
40
41 pub fn all() -> [Self; 7] {
43 [
44 Self::Open,
45 Self::High,
46 Self::Low,
47 Self::Close,
48 Self::HL2,
49 Self::HLC3,
50 Self::OHLC4,
51 ]
52 }
53
54 pub fn compute(&self, open: f64, high: f64, low: f64, close: f64) -> f64 {
56 match self {
57 Self::Open => open,
58 Self::High => high,
59 Self::Low => low,
60 Self::Close => close,
61 Self::HL2 => (high + low) / 2.0,
62 Self::HLC3 => (high + low + close) / 3.0,
63 Self::OHLC4 => (open + high + low + close) / 4.0,
64 }
65 }
66}