Documentation
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
    }
}