use crate::strategy_engine::Strategy;
#[derive(Debug, Clone)]
pub struct TargetPrice {
target_price: f64,
}
impl TargetPrice {
pub fn new(target_price: f64) -> Self {
Self { target_price }
}
}
impl Strategy for TargetPrice {
fn evaluate(&self, price: &f64) -> f64 {
if *price < self.target_price {
1.0 } else if *price > self.target_price {
-1.0 } else {
0.0 }
}
fn calculate_indicator(&self, prices: &Vec<f64>) -> f64 {
let mut hits = 0;
for price in prices {
if *price == self.target_price {
hits += 1;
}
}
hits as f64
}
}