use brk_error::Result;
use brk_types::Indexes;
use vecdb::Exit;
use super::MacdChain;
use crate::{blocks, prices};
#[allow(clippy::too_many_arguments)]
pub(super) fn compute(
chain: &mut MacdChain,
blocks: &blocks::Vecs,
prices: &prices::Vecs,
fast_days: usize,
slow_days: usize,
signal_days: usize,
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
let close = &prices.spot.usd.height;
let ws_fast = blocks.lookback.start_vec(fast_days);
let ws_slow = blocks.lookback.start_vec(slow_days);
let ws_signal = blocks.lookback.start_vec(signal_days);
chain
.ema_fast
.height
.compute_rolling_ema(starting_indexes.height, ws_fast, close, exit)?;
chain
.ema_slow
.height
.compute_rolling_ema(starting_indexes.height, ws_slow, close, exit)?;
chain.line.height.compute_subtract(
starting_indexes.height,
&chain.ema_fast.height,
&chain.ema_slow.height,
exit,
)?;
chain.signal.height.compute_rolling_ema(
starting_indexes.height,
ws_signal,
&chain.line.height,
exit,
)?;
chain.histogram.height.compute_subtract(
starting_indexes.height,
&chain.line.height,
&chain.signal.height,
exit,
)?;
Ok(())
}