indexes_rs/v2/atr/
types.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
4pub struct ATRResult {
5 pub atr: f64,
6 pub true_range: f64,
7}
8
9#[derive(Debug, Clone, Copy, PartialEq)]
10pub struct OHLCData {
11 pub high: f64,
12 pub low: f64,
13 pub close: f64,
14}
15
16impl OHLCData {
17 pub fn new(high: f64, low: f64, close: f64) -> Self {
18 Self { high, low, close }
19 }
20}
21
22#[derive(Debug, Clone, PartialEq)]
23pub enum ATRError {
24 InvalidPeriod,
25 InsufficientData,
26 InvalidPrice,
27}
28
29impl std::fmt::Display for ATRError {
30 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31 match self {
32 ATRError::InvalidPeriod => write!(f, "Period must be greater than 0"),
33 ATRError::InsufficientData => write!(f, "Not enough data to calculate ATR"),
34 ATRError::InvalidPrice => write!(f, "Invalid price data (NaN or Infinite)"),
35 }
36 }
37}
38
39impl std::error::Error for ATRError {}