Record Class OHLCBar
java.lang.Object
java.lang.Record
com.arbergashi.charts.model.OHLCBar
- All Implemented Interfaces:
Serializable
public record OHLCBar(double time, double open, double high, double low, double close)
extends Record
implements Serializable
OHLCBar - Type-Safe Financial Data Point
Immutable record representing Open-High-Low-Close financial data. Designed for end-user convenience with clear, self-documenting fields.
Usage Example:
// Create OHLC bar for candlestick charts
OHLCBar bar = OHLCBar.of(0, 100.0, 105.0, 98.0, 103.0);
// Add to chart model
DefaultChartModel model = new DefaultChartModel("AAPL");
model.addOHLC(bar);
// Or create with timestamp
long timestamp = System.currentTimeMillis();
OHLCBar timestamped = OHLCBar.of(timestamp, 100, 105, 98, 103);
Field Mapping:
- time: X-axis value (timestamp, index, or ordinal)
- open: Opening price
- high: Highest price in period
- low: Lowest price in period
- close: Closing price
- Since:
- 2026-01-16
- Version:
- 1.0.0
- Author:
- Arber Gashi
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionOHLCBar(double time, double open, double high, double low, double close) Validates OHLC data integrity. -
Method Summary
Modifier and TypeMethodDescriptiondoublebodySize()Returns the body size (absolute difference between open and close).doubleclose()Returns the value of thecloserecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.doublehigh()Returns the value of thehighrecord component.booleanReturns true if this is a bearish (red) candle.booleanReturns true if this is a bullish (green) candle.doublelow()Returns the value of thelowrecord component.doubleReturns the lower wick size (min of open/close minus low).static OHLCBarof(double time, double open, double high, double low, double close) Factory method for creating OHLC bars.doubleopen()Returns the value of theopenrecord component.doublerange()Returns the total range (high - low).doubletime()Returns the value of thetimerecord component.Converts to ChartPoint for internal rendering.final StringtoString()Returns a string representation of this record class.doubleReturns the upper wick size (high minus max of open/close).
-
Constructor Details
-
OHLCBar
public OHLCBar(double time, double open, double high, double low, double close) Validates OHLC data integrity.
-
-
Method Details
-
of
Factory method for creating OHLC bars.- Parameters:
time- X-axis value (timestamp or index)open- Opening pricehigh- Highest pricelow- Lowest priceclose- Closing price- Returns:
- new OHLCBar instance
-
toChartPoint
Converts to ChartPoint for internal rendering. Mapping: x→time, y→close, weight→open, min→low, max→high -
isBullish
public boolean isBullish()Returns true if this is a bullish (green) candle. -
isBearish
public boolean isBearish()Returns true if this is a bearish (red) candle. -
bodySize
public double bodySize()Returns the body size (absolute difference between open and close). -
upperWick
public double upperWick()Returns the upper wick size (high minus max of open/close). -
lowerWick
public double lowerWick()Returns the lower wick size (min of open/close minus low). -
range
public double range()Returns the total range (high - low). -
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with thecomparemethod from their corresponding wrapper classes. -
time
public double time()Returns the value of thetimerecord component.- Returns:
- the value of the
timerecord component
-
open
public double open()Returns the value of theopenrecord component.- Returns:
- the value of the
openrecord component
-
high
public double high()Returns the value of thehighrecord component.- Returns:
- the value of the
highrecord component
-
low
public double low()Returns the value of thelowrecord component.- Returns:
- the value of the
lowrecord component
-
close
public double close()Returns the value of thecloserecord component.- Returns:
- the value of the
closerecord component
-