market_state_chain
Market State Chain: six debounced states
market_state_chain
examples/site_showcase.rs// Market State Chain: six debounced states (up/down trend, up/down weak, compression, chaos) as a first-order Markov chain; over lookback bars the exits of the current (context) state give Laplace-smoothed bull/bear/neutral exit probabilities, persistence, reliability (sample adequacy x predictability) and a hysteresis bias; value = p_bull - p_bear; extra: state_code, context_state, p_bull, p_bear, p_neutral, reliability, bias, exits, bars_in_state, persistence, dwell_ratio, atr_rank, bb_rank, efficiency, adx; alerts bull/bear_breakout (edge out of compression or chaos), bull/bear_reversal, bull/bear_continuation (prefix = expected move), regime_change, state_extended
// Defaults of "market_state_chain" (see the indicator reference)
let params = HashMap::from([
("bias_margin".to_string(), 8.0),
("conf_th".to_string(), 55.0),
("ema_len".to_string(), 55.0),
("lookback".to_string(), 500.0),
("min_dwell".to_string(), 2.0),
("min_samples".to_string(), 20.0),
("rank_len".to_string(), 100.0),
("rel_th".to_string(), 40.0),
]);
let mut indicator = build_checked("market_state_chain", ¶ms)?;
for bar in &bars {
if let Some(output) = indicator.on_bar(bar) {
// output.value, output.extra[...], indicator.alerts()
}
}