Expand description
§MACD (Moving Average Convergence Divergence)
MACD = EMA(fast) − EMA(slow) // default 12 and 26
Signal = EMA(signal) of MACD line // default 9
Hist = MACD − Signal§Word problem
Using classic (12, 26, 9) settings on daily closes, when is the histogram first defined?
After the slow EMA seeds (26 bars) and then the signal EMA seeds on 9 MACD points —
teaching tables show n/a until then. Live code: hold [MacdState] and read
[MacdState::last] after warm-up.
§Variations (same core)
| Pack | Typical use |
|---|---|
MacdParams::standard() → (12,26,9) | Default charting |
MacdParams::new(8, 17, 9) | Faster reaction |
MacdParams::new(5, 35, 5) | Custom desk setting |
§Quant pattern
use finance_solution::stocks::ta::{MacdParams, ValidatedMacd, MacdState};
const STD: MacdParams = MacdParams::standard();
let eng = ValidatedMacd::new(STD).unwrap();
let s = eng.compute(&closes).unwrap();
let mut live = MacdState::new(STD).unwrap();
let _ = live.push_bars(&closes).unwrap();
assert_eq!(s.macd.len(), closes.len());§Sample solution table
period close macd signal hist
------ ------ ---- ------ ----
25 102.50 n/a n/a n/a
26 102.60 0.12 n/a n/a
34 103.40 0.18 0.15 0.03Structs§
- Macd
Params - MACD parameter pack:
fast < slow, all periods ≥ 1. - Macd
Series - Aligned MACD / signal / histogram series.
- Macd
Solution - Teaching wrapper with formula strings and a printable table.
- Validated
Macd - Validated MACD config for reuse across many close series.
Functions§
- macd
- Free function: validate params then compute.
- macd_
solution - Solution with formulas + table for teaching / audit.