1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Close price passthrough indicator.
//!
//! Simply returns close prices with timestamps. Useful for signal generators
//! that don't need technical indicators but still need access to timestamps.
use quant_primitives::Candle;
use crate::error::IndicatorError;
use crate::indicator::Indicator;
use crate::series::Series;
/// Passthrough indicator that returns close prices.
///
/// This is useful for signal generators that don't use technical indicators
/// but still need timestamps (like BuyAndHoldSignal).
#[derive(Debug, Clone, Default)]
pub struct Close;
impl Close {
/// Create a new Close indicator.
pub fn new() -> Self {
Self
}
}
impl Indicator for Close {
fn name(&self) -> &str {
"Close"
}
fn warmup_period(&self) -> usize {
1 // Just need one candle
}
fn compute(&self, candles: &[Candle]) -> Result<Series, IndicatorError> {
if candles.is_empty() {
return Err(IndicatorError::InsufficientData {
required: 1,
actual: 0,
});
}
let values: Vec<_> = candles.iter().map(|c| (c.timestamp(), c.close())).collect();
Ok(Series::new(values))
}
}
#[cfg(test)]
#[path = "close_tests.rs"]
mod tests;