pub struct Bar {
pub time: DateTime<Utc>,
pub open: f64,
pub high: f64,
pub low: f64,
pub close: f64,
pub volume: f64,
pub colors: Option<Box<BarColors>>,
pub payload: Option<Arc<Value>>,
}Expand description
Represents a single OHLCV (Open, High, Low, Close, Volume) bar
Each bar represents a discrete time period of trading activity. A bar can also carry
colors of its own and a host payload, stand for a single
value (from_value), or hold a slot of the time axis without a value
(whitespace).
§Example
use chrono::Utc;
use egui_charts::model::Bar;
let bar = Bar::new(
Utc::now(),
100.0, // open
105.0, // high
98.0, // low
103.0, // close
1000.0 // volume
);
assert!(bar.is_bullish()); // close > openFields§
§time: DateTime<Utc>Timestamp of the bar. Read from JSON as an RFC 3339 time, or as a date alone
("2024-03-15"), which is midnight UTC of that day, the open of its day bar.
open: f64Opening price
high: f64Highest price during the period
low: f64Lowest price during the period
close: f64Closing price
volume: f64Trading volume
colors: Option<Box<BarColors>>Colours of this bar that replace the series’ colours, None for the series’ colours.
payload: Option<Arc<Value>>Data of the host’s own attached to this bar. The chart does not read it; it comes back with the bar in the chart’s pointer and data events and in its bar lookups.
Implementations§
Source§impl Bar
impl Bar
Sourcepub fn new(
time: DateTime<Utc>,
open: f64,
high: f64,
low: f64,
close: f64,
volume: f64,
) -> Self
pub fn new( time: DateTime<Utc>, open: f64, high: f64, low: f64, close: f64, volume: f64, ) -> Self
Creates a new bar
Sourcepub fn from_date(
date: NaiveDate,
open: f64,
high: f64,
low: f64,
close: f64,
volume: f64,
) -> Self
pub fn from_date( date: NaiveDate, open: f64, high: f64, low: f64, close: f64, volume: f64, ) -> Self
Creates a daily OHLCV bar from a calendar date, at midnight UTC, matching date-only JSON and CSV imports. The date is independent of the exchange’s time zone. The chart formats this UTC instant in its display time zone, which can show a different date (for example, the previous day at UTC-05:00).
§Example
use chrono::NaiveDate;
use egui_charts::model::Bar;
let date = NaiveDate::from_ymd_opt(2024, 2, 29).unwrap();
let bar = Bar::from_date(date, 100.0, 105.0, 98.0, 103.0, 1000.0);
let point = Bar::from_value_on_date(date, 103.0);
let gap = Bar::whitespace_on_date(date);
assert_eq!(bar.time.to_rfc3339(), "2024-02-29T00:00:00+00:00");
assert_eq!(point.time, bar.time);
assert_eq!(gap.time, bar.time);
assert!(gap.is_whitespace());Sourcepub fn from_value(time: DateTime<Utc>, value: f64) -> Self
pub fn from_value(time: DateTime<Utc>, value: f64) -> Self
A bar of a single value, such as a point of a line, area, baseline or column series: its
open, high, low and close are value, its volume zero.
Sourcepub fn from_value_on_date(date: NaiveDate, value: f64) -> Self
pub fn from_value_on_date(date: NaiveDate, value: f64) -> Self
A from_value bar on a calendar date, at midnight UTC.
Date and display time zone conventions are those of from_date.
Sourcepub fn whitespace(time: DateTime<Utc>) -> Self
pub fn whitespace(time: DateTime<Utc>) -> Self
A bar without a value: it holds its slot on the time axis, so a gap such as a halted session stays visible and a time of another series has a slot, but nothing is drawn there and studies take it as a bar without a value. Its open, high, low, close and volume are NaN.
Sourcepub fn whitespace_on_date(date: NaiveDate) -> Self
pub fn whitespace_on_date(date: NaiveDate) -> Self
A whitespace bar on a calendar date, at midnight UTC.
Date and display time zone conventions are those of from_date.
Sourcepub fn is_whitespace(&self) -> bool
pub fn is_whitespace(&self) -> bool
Whether this is a whitespace bar: open, high, low, close and volume
are all NaN.
Sourcepub fn is_bullish(&self) -> bool
pub fn is_bullish(&self) -> bool
Returns true if this is a bullish bar (close > open)
Sourcepub fn is_bearish(&self) -> bool
pub fn is_bearish(&self) -> bool
Returns true if this is a bearish bar (close < open)
Sourcepub fn is_doji(&self, threshold: f64) -> bool
pub fn is_doji(&self, threshold: f64) -> bool
Returns true if this is a doji (open ≈ close)
§Arguments
threshold- Ratio of body to range below which it’s considered a doji
Sourcepub fn body_height(&self) -> f64
pub fn body_height(&self) -> f64
Returns the body height (absolute difference between open and close)
Sourcepub fn upper_wick(&self) -> f64
pub fn upper_wick(&self) -> f64
Returns the upper wick height
Sourcepub fn lower_wick(&self) -> f64
pub fn lower_wick(&self) -> f64
Returns the lower wick height
Sourcepub fn typical_price(&self) -> f64
pub fn typical_price(&self) -> f64
Returns the typical price ((high + low + close) / 3)
Commonly used in technical analysis (e.g., VWAP, CCI)
Sourcepub fn weighted_close(&self) -> f64
pub fn weighted_close(&self) -> f64
Returns the weighted close ((high + low + close + close) / 4)
Sourcepub fn body_percentage(&self) -> f64
pub fn body_percentage(&self) -> f64
Returns the body as a percentage of the total range (0.0 to 1.0)
Sourcepub fn wick_ratio(&self) -> f64
pub fn wick_ratio(&self) -> f64
Returns the ratio of upper wick to lower wick
Returns infinity if lower wick is zero.
Sourcepub fn change_percent(&self) -> f64
pub fn change_percent(&self) -> f64
Returns the percentage change ((close - open) / |open| * 100), divided by the magnitude of the open so it has the sign of the change for a negative open too
Sourcepub fn body_bottom(&self) -> f64
pub fn body_bottom(&self) -> f64
Returns the bottom of the body (min of open and close)
Trait Implementations§
Source§impl CandlePatterns for Bar
impl CandlePatterns for Bar
Source§fn is_inverted_hammer(&self) -> bool
fn is_inverted_hammer(&self) -> bool
Source§fn is_shooting_star(&self) -> bool
fn is_shooting_star(&self) -> bool
Source§fn is_spinning_top(&self) -> bool
fn is_spinning_top(&self) -> bool
Source§fn is_marubozu(&self) -> bool
fn is_marubozu(&self) -> bool
Source§fn is_bullish_engulfing(&self, prev: &Bar) -> bool
fn is_bullish_engulfing(&self, prev: &Bar) -> bool
Source§fn is_bearish_engulfing(&self, prev: &Bar) -> bool
fn is_bearish_engulfing(&self, prev: &Bar) -> bool
Source§impl<'de> Deserialize<'de> for Bar
impl<'de> Deserialize<'de> for Bar
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<MetricPoint> for Bar
impl From<MetricPoint> for Bar
Source§fn from(point: MetricPoint) -> Self
fn from(point: MetricPoint) -> Self
Source§impl FromIterator<Bar> for BarData
impl FromIterator<Bar> for BarData
impl StructuralPartialEq for Bar
Auto Trait Implementations§
impl Freeze for Bar
impl RefUnwindSafe for Bar
impl Send for Bar
impl Sync for Bar
impl Unpin for Bar
impl UnsafeUnpin for Bar
impl UnwindSafe for Bar
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more