pub struct VolumeProfileEngine { /* private fields */ }Expand description
Volume Profile over the last lookback bars: volume by price, Point of Control and a 70 %
value area.
The window’s own range [min low, max high] is split into num_bins equal bins of width
step. Each bar’s volume — its range when it carries no volume — is spread evenly over the
bins from floor((low - min) / step) to floor((high - min) / step), both clamped to the last
bin. The POC is the first bin with the largest volume, priced at its centre. The value
area grows from the POC one bin at a time towards the larger neighbour (upwards on a tie)
until it holds 70 % of the window’s volume; VAH is the upper edge of its top bin, VAL
the lower edge of its bottom bin.
value and extra["vpoc"]: the POC; further extra["vah"], extra["val"],
extra["total_volume"], extra["vpoc_density"] (POC volume over total),
extra["current_density"] (the close’s bin over total) and extra["lvn_width"] (2 * step).
A window without range publishes the close.
First output: with the lookback-th bar. Indicator::reset clears the window.
Implementations§
Source§impl VolumeProfileEngine
impl VolumeProfileEngine
Sourcepub fn new(lookback: usize, num_bins: usize) -> Self
pub fn new(lookback: usize, num_bins: usize) -> Self
Constructs a profile engine, clamping lookback and num_bins to a minimum of 1 each
(matching ExtendedVolumeProfileEngine’s
and PersistentVolumeProfileEngine’s
existing contract). 0 would otherwise leave on_bar with an empty bin vector (panicking
on the first non-flat window) or a warmup that can never complete. Prefer
VolumeProfileEngine::try_new for configuration-driven construction, where silently
substituting 1 would compute a different profile than requested.
Sourcepub fn try_new(
lookback: usize,
num_bins: usize,
) -> Result<Self, VolumeProfileConfigError>
pub fn try_new( lookback: usize, num_bins: usize, ) -> Result<Self, VolumeProfileConfigError>
Like VolumeProfileEngine::new, but rejects a zero lookback/num_bins with
VolumeProfileConfigError instead of silently clamping it to 1.
Sourcepub fn on_bar_with_boundary(
&mut self,
bar: &Bar,
is_contract_boundary: bool,
) -> Option<IndicatorOutput>
pub fn on_bar_with_boundary( &mut self, bar: &Bar, is_contract_boundary: bool, ) -> Option<IndicatorOutput>
Feeds a bar into the volume profile engine, resetting internal state if is_contract_boundary is true.
This prevents volume and distribution bins from previous contracts or expirations from distorting the profile across commodity or futures roll boundaries.
Trait Implementations§
Source§impl Indicator for VolumeProfileEngine
impl Indicator for VolumeProfileEngine
fn name(&self) -> &str
fn warmup_period(&self) -> usize
fn reset(&mut self)
fn on_bar(&mut self, bar: &Bar) -> Option<IndicatorOutput>
fn alerts(&self) -> Vec<IndicatorAlert>
Source§fn on_checked_bar(
&mut self,
bar: &Bar,
) -> Result<Option<IndicatorOutput>, BarValidationError>
fn on_checked_bar( &mut self, bar: &Bar, ) -> Result<Option<IndicatorOutput>, BarValidationError>
Indicator::on_bar.