Quickstart
Build an indicator from the registry by name, stream bars through it, and read the output as each bar closes.
Stream a first indicator
This is examples/basic_indicator.rs from the repository:
use kestrel_chartkit::{build_checked, Bar, Indicator};
use std::collections::HashMap;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut params = HashMap::new();
params.insert("rsi_len".to_string(), 14.0);
let mut rsi = build_checked("rsi", ¶ms)?;
let closes = [
44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10, 45.42, 45.84, 46.08, 45.89, 46.03, 45.61,
46.28, 46.28, 46.00,
];
for (i, &close) in closes.iter().enumerate() {
let bar = Bar::try_new(
1_700_000_000 + i as i64 * 60,
close,
close + 0.5,
close - 0.5,
close,
1_000.0,
)?;
match rsi.on_bar(&bar) {
Some(output) => println!("bar {i:>2}: close={close:.2} RSI(14)={:.2}", output.value),
None => println!("bar {i:>2}: close={close:.2} RSI(14)=<warming up>"),
}
}
Ok(())
}
cargo run --example basic_indicator prints:
bar 0: close=44.34 RSI(14)=<warming up>
bar 1: close=44.09 RSI(14)=<warming up>
…
bar 13: close=46.28 RSI(14)=<warming up>
bar 14: close=46.28 RSI(14)=70.46
bar 15: close=46.00 RSI(14)=68.36
Three things to note:
build_checkedvalidates the parameters against the registry and returns a boxedIndicator. An unknown name, an unknown parameter key or an out-of-range period is aRegistryError, not a panic.Bar::try_newrejects non-finite or non-positive prices and a high/low range that does not contain open and close. Use it wherever bars enter your program.on_barreturnsNoneuntil the warmup is complete, thenSomeon every bar. The first value arrives on barwarmup_period().
Draw it
kestrel-chartkit computes and draws nothing. Hand the values to a renderer — chartlet for a static chart, as on this site, or kestrel-loom for an interactive one in the browser. The visualising guide shows how the site turns indicator output into a chartlet specification.
Next steps
- Indicators: the trait, the registry and the output fields.
- Market regime and Composite scoring.
- Visualising results: chartlet, kestrel-loom and the quick-look renderers.