Market regime
Synthetic 4-hour candles of a fictitious CASOON share in four legs: up, sideways, down, sideways. classify_regime runs on every bar with ADX(14) and ATR(14); the band below the candles shows the regime, the lowest pane the ADX with the trend threshold of 20. The first bars have no regime yet: ADX and ATR are still warming up.
Market regime
examples/site_showcase.rslet mut adx = build_checked("adx", &HashMap::new())?;
let mut atr = build_checked("atr", &HashMap::new())?;
for (i, bar) in bars.iter().enumerate() {
let (Some(a), Some(t)) = (adx.on_bar(bar), atr.on_bar(bar)) else { continue };
// The ATR indicator reports 100 * ATR / close; classify_regime expects the fraction.
let regime = classify_regime(&bars[..=i], a.value, t.value / 100.0);
}