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

    Constructors
    Constructor
    Description
    OHLCBar(double time, double open, double high, double low, double close)
    Validates OHLC data integrity.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Returns the body size (absolute difference between open and close).
    double
    Returns the value of the close record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    double
    Returns the value of the high record component.
    boolean
    Returns true if this is a bearish (red) candle.
    boolean
    Returns true if this is a bullish (green) candle.
    double
    low()
    Returns the value of the low record component.
    double
    Returns the lower wick size (min of open/close minus low).
    static OHLCBar
    of(double time, double open, double high, double low, double close)
    Factory method for creating OHLC bars.
    double
    Returns the value of the open record component.
    double
    Returns the total range (high - low).
    double
    Returns the value of the time record component.
    Converts to ChartPoint for internal rendering.
    final String
    Returns a string representation of this record class.
    double
    Returns the upper wick size (high minus max of open/close).

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • OHLCBar

      public OHLCBar(double time, double open, double high, double low, double close)
      Validates OHLC data integrity.
  • Method Details

    • of

      public static OHLCBar of(double time, double open, double high, double low, double close)
      Factory method for creating OHLC bars.
      Parameters:
      time - X-axis value (timestamp or index)
      open - Opening price
      high - Highest price
      low - Lowest price
      close - Closing price
      Returns:
      new OHLCBar instance
    • toChartPoint

      public ChartPoint 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

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • time

      public double time()
      Returns the value of the time record component.
      Returns:
      the value of the time record component
    • open

      public double open()
      Returns the value of the open record component.
      Returns:
      the value of the open record component
    • high

      public double high()
      Returns the value of the high record component.
      Returns:
      the value of the high record component
    • low

      public double low()
      Returns the value of the low record component.
      Returns:
      the value of the low record component
    • close

      public double close()
      Returns the value of the close record component.
      Returns:
      the value of the close record component