pub struct Tpo { /* private fields */ }Expand description
A TPO series: add it with
Chart::add_custom_series
and feed it with crate::append_bars.
Each session takes one slot (AxisMode::Slots, at the session start).
A profile needs a wide slot: raise ChartOptions::max_bar_spacing (50
CSS px by default). When the letters of the drawn sessions do not all
fit, the profiles are drawn as histograms of TPO counts.
§Examples
use ferrochart_core::chart::SeriesOptions;
use ferrochart_core::data::OhlcColumns;
use ferrochart_core::theme::Theme;
use ferrochart_core::{Chart, ChartOptions};
use ferrochart_orderflow::{Tpo, TpoOptions, append_bars};
let mut chart = Chart::new(ChartOptions::default());
let tpo = Tpo::new(TpoOptions::new(1.0, &Theme::light()))?;
let id = chart.add_custom_series(chart.main_pane(), Box::new(tpo), SeriesOptions::default())?;
// Three 30 min bars: periods A, B and C of the first UTC day.
let bars = OhlcColumns {
time: vec![0, 1_800_000, 3_600_000],
open: vec![10.0, 12.0, 11.0],
high: vec![12.0, 13.0, 12.0],
low: vec![10.0, 11.0, 11.0],
close: vec![12.0, 11.0, 12.0],
volume: None,
};
append_bars(&mut chart, id, &bars)?;
let p = chart.custom_series::<Tpo>(id).unwrap().profile(0).unwrap();
// 11 and 12 have 3 TPOs each, equally near the middle: the lower wins.
assert_eq!((p.low, p.high, p.poc, p.max_count, p.tpos), (10, 13, 11, 3, 8));
assert_eq!(p.initial_balance, Some((10, 13)));Implementations§
Source§impl Tpo
impl Tpo
Sourcepub fn new(opts: TpoOptions) -> Result<Self>
pub fn new(opts: TpoOptions) -> Result<Self>
An empty TPO series.
§Errors
Error::InvalidArgument for a bad price grid, a non-positive
period, a session shorter than a period, longer than a day or than
65 535 periods, or a value area outside (0, 1].
Sourcepub fn options(&self) -> &TpoOptions
pub fn options(&self) -> &TpoOptions
The options.
Sourcepub fn set_colors(&mut self, colors: TpoColors)
pub fn set_colors(&mut self, colors: TpoColors)
Changes the colors.
Sourcepub fn price_levels(&self) -> PriceLevels
pub fn price_levels(&self) -> PriceLevels
The price grid.
Sourcepub fn profile(&self, i: usize) -> Option<SessionProfile>
pub fn profile(&self, i: usize) -> Option<SessionProfile>
The profile of session i.
Sourcepub fn periods(&self, i: usize) -> Option<(&[u16], &[i32], &[i32])>
pub fn periods(&self, i: usize) -> Option<(&[u16], &[i32], &[i32])>
The traded periods of session i: period numbers (ascending) and
their lowest and highest levels.
Sourcepub fn session_start(&self, time: Timestamp) -> Timestamp
pub fn session_start(&self, time: Timestamp) -> Timestamp
Start of the last session starting at or before time (it contains
time if Self::in_session).
Sourcepub fn in_session(&self, time: Timestamp) -> bool
pub fn in_session(&self, time: Timestamp) -> bool
Whether time falls in a session.
Sourcepub fn push_bar(&mut self, time: Timestamp, high: f64, low: f64) -> Result<bool>
pub fn push_bar(&mut self, time: Timestamp, high: f64, low: f64) -> Result<bool>
Adds a bar (its period is the one containing time; bars must be no
longer than a period); returns whether it opened a session. A bar
again at a time already seen (an update of a live bar) widens its
period’s range. A bar outside the sessions is skipped.
§Errors
Error::InvalidArgument for non-finite prices, high < low or
prices outside the level range; Error::TimeNotIncreasing if its
session is before the last one; Error::OutOfMemory.
Trait Implementations§
Source§impl CustomSeries for Tpo
impl CustomSeries for Tpo
Source§fn kind(&self) -> &'static str
fn kind(&self) -> &'static str
"orderflow.heatmap"; renderers that draw it natively
declare this name.Source§fn axis_mode(&self) -> AxisMode
fn axis_mode(&self) -> AxisMode
Source§fn extremes(&self, from: usize, to: usize) -> Option<(f64, f64)>
fn extremes(&self, from: usize, to: usize) -> Option<(f64, f64)>
from..to, for auto scaling. Called every
frame, so it must be O(log n) (see crate::plugin::MinMaxIndex).Source§fn crosshair_value(&self, point: usize) -> Option<f64>
fn crosshair_value(&self, point: usize) -> Option<f64>
point for the crosshair and magnet.Source§fn build(
&self,
ctx: &SeriesCtx<'_>,
from: usize,
to: usize,
out: &mut FrameBuilder<'_>,
)
fn build( &self, ctx: &SeriesCtx<'_>, from: usize, to: usize, out: &mut FrameBuilder<'_>, )
from..to (the
visible ones and one more on each side). Must not allocate once
warmed up.Source§fn last_value(&self) -> Option<f64>
fn last_value(&self) -> Option<f64>
None hides it.