pub struct BarInput {
pub close: Decimal,
pub high: Decimal,
pub low: Decimal,
pub open: Decimal,
pub volume: Decimal,
}Expand description
Thin input type for signal computation, decoupled from OhlcvBar.
Carrying all four price fields and volume allows future indicators (e.g. MACD on
high-low, OBV on volume) without forcing a dependency on OhlcvBar.
Fields§
§close: DecimalClosing price (used by most indicators).
high: DecimalHigh price of the bar.
low: DecimalLow price of the bar.
open: DecimalOpening price of the bar.
volume: DecimalTotal traded volume during the bar.
Implementations§
Source§impl BarInput
impl BarInput
Sourcepub fn new(
close: Decimal,
high: Decimal,
low: Decimal,
open: Decimal,
volume: Decimal,
) -> Self
pub fn new( close: Decimal, high: Decimal, low: Decimal, open: Decimal, volume: Decimal, ) -> Self
Constructs a BarInput with all fields explicitly specified.
Sourcepub fn from_close(close: Decimal) -> Self
pub fn from_close(close: Decimal) -> Self
Constructs a BarInput from a single close price, setting all OHLC fields to close
and volume to zero. Useful in tests and for close-only indicators (SMA/EMA/RSI).
Sourcepub fn typical_price(&self) -> Decimal
pub fn typical_price(&self) -> Decimal
Returns the typical price of this bar: (high + low + close) / 3.
Sourcepub fn weighted_close(&self) -> Decimal
pub fn weighted_close(&self) -> Decimal
Returns the weighted close price: (high + low + close + close) / 4.
Weights the close twice, giving it extra significance compared to the typical price. Used by some indicators (e.g. CCI variants) and charting systems as a price reference.
Sourcepub fn close_location_value(&self) -> Decimal
pub fn close_location_value(&self) -> Decimal
Close Location Value: ((close - low) - (high - close)) / (high - low).
Ranges from -1.0 (close at low) to +1.0 (close at high). Returns zero when the range is zero (doji / flat bar).
Sourcepub fn net_move(&self) -> Decimal
pub fn net_move(&self) -> Decimal
Returns the signed intrabar move: close - open.
Positive for bullish bars, negative for bearish, zero for doji.
Unlike body_size, this preserves direction.
Sourcepub fn upper_wick(&self) -> Decimal
pub fn upper_wick(&self) -> Decimal
Returns the upper wick length: high - max(open, close).
Sourcepub fn lower_wick(&self) -> Decimal
pub fn lower_wick(&self) -> Decimal
Returns the lower wick length: min(open, close) - low.
Sourcepub fn is_bullish(&self) -> bool
pub fn is_bullish(&self) -> bool
Returns true if the bar closed higher than it opened (bullish candle).
Sourcepub fn is_bearish(&self) -> bool
pub fn is_bearish(&self) -> bool
Returns true if the bar closed lower than it opened (bearish candle).
Sourcepub fn price_change(&self, prev_close: Option<Decimal>) -> Decimal
pub fn price_change(&self, prev_close: Option<Decimal>) -> Decimal
Returns the close-to-close price change: close - prev_close.
When prev_close is None (first bar), returns Decimal::ZERO.
Sourcepub fn log_return(&self, prev_close: Option<Decimal>) -> Option<Decimal>
pub fn log_return(&self, prev_close: Option<Decimal>) -> Option<Decimal>
Returns the log return: ln(close / prev_close) via f64.
Returns None when prev_close is None, zero, or negative, or when the
f64 conversion fails.
Sourcepub fn true_range(&self, prev_close: Option<Decimal>) -> Decimal
pub fn true_range(&self, prev_close: Option<Decimal>) -> Decimal
Returns the True Range of this bar given the previous bar’s close.
TR = max(high - low, |high - prev_close|, |low - prev_close|)
When there is no previous close (first bar), high - low is used as the true range.