use crate::math;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Candle {
pub open: f64,
pub high: f64,
pub low: f64,
pub close: f64,
pub volume: f64,
pub timestamp: i64,
}
impl Candle {
#[must_use]
pub const fn new(
open: f64,
high: f64,
low: f64,
close: f64,
volume: f64,
timestamp: i64,
) -> Self {
Self {
open,
high,
low,
close,
volume,
timestamp,
}
}
#[must_use]
pub fn true_range(&self, prev_close: Option<f64>) -> f64 {
let hl = self.high - self.low;
match prev_close {
Some(prev) => {
let hp = math::abs(self.high - prev);
let lp = math::abs(self.low - prev);
math::max(math::max(hl, hp), lp)
}
None => hl,
}
}
}