Volume profile
Volume profile over the last 70 bars with 30 price bins. The shaded zone is the value area, the orange line the point of control.
Volume profile
examples/site_showcase.rsfn volume_profile() -> Chart {
let bars = walk(23, 120);
let lookback = 70;
let mut vp = build_checked(
"volume_profile",
¶ms(&[("lookback", lookback as f64), ("num_bins", 30.0)]),
)?;
let mut last = None;
for bar in &bars {
if let Some(out) = vp.on_bar(bar) {
last = Some(out);
}
}
let out = last.ok_or("volume profile produced no output")?;
let (poc, vah, val) = (out.extra["vpoc"], out.extra["vah"], out.extra["val"]);
let from = bars[bars.len() - lookback].timestamp;
let to = bars[bars.len() - 1].timestamp;
let data = ChartRenderData {
title: "Volume profile, last 70 bars".to_string(),
bars: candles(&bars),
series: vec![line(
"Point of control",
"#ffb74d",
vec![(from, poc), (to, poc)],
)],
zones: vec![ChartZoneData {
name: format!("Value area {val:.2} to {vah:.2}"),
price_top: vah,
price_bottom: val,
color: "#29b6f6".to_string(),
}],
markers: Vec::new(),
};
Ok(render_chart_svg(&data, 800, 400))
}