Skip to main content

Tpo

Struct Tpo 

Source
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

Source

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].

Source

pub fn options(&self) -> &TpoOptions

The options.

Source

pub fn set_colors(&mut self, colors: TpoColors)

Changes the colors.

Source

pub fn price_levels(&self) -> PriceLevels

The price grid.

Source

pub fn sessions(&self) -> &[Timestamp]

Session start times.

Source

pub fn profile(&self, i: usize) -> Option<SessionProfile>

The profile of session i.

Source

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.

Source

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).

Source

pub fn in_session(&self, time: Timestamp) -> bool

Whether time falls in a session.

Source

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

Source§

fn kind(&self) -> &'static str

Kind name, e.g. "orderflow.heatmap"; renderers that draw it natively declare this name.
Source§

fn axis_mode(&self) -> AxisMode

How the points are placed on the time axis; read once, when added.
Source§

fn times(&self) -> &[Timestamp]

Times of the points, strictly increasing.
Source§

fn extremes(&self, from: usize, to: usize) -> Option<(f64, f64)>

Price extremes of points 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>

Value of point point for the crosshair and magnet.
Source§

fn build( &self, ctx: &SeriesCtx<'_>, from: usize, to: usize, out: &mut FrameBuilder<'_>, )

Portable path: writes the primitives of points from..to (the visible ones and one more on each side). Must not allocate once warmed up.
Source§

fn last_value(&self) -> Option<f64>

Value of the last-value label; None hides it.
Source§

fn native_params(&self, ctx: &SeriesCtx<'_>, params: &mut [f32; 8])

Parameters of the native GPU path, e.g. a color-scale range.
Source§

impl Debug for Tpo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Tpo

§

impl !RefUnwindSafe for Tpo

§

impl !Sync for Tpo

§

impl Forget for Tpo

§

impl Move for Tpo

§

impl Send for Tpo

§

impl Unpin for Tpo

§

impl UnsafeUnpin for Tpo

§

impl UnwindSafe for Tpo

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,