Class CandlestickSeries


public class CandlestickSeries extends XYSeries

Open/high/low/close prices drawn as candlesticks, OHLC bars or Heikin-Ashi candles.

A rising period (close at or above open) is drawn in the theme's positive colour and a falling one in its negative colour. Pair it with a SessionTimeAxis to skip weekends, or with a TimeAxis to keep calendar spacing.

Chart chart = new Chart();
long day = 24L * 60 * 60 * 1000;
long[] timestamps = {0, day, 4 * day};
double[] open = {10, 11, 12}, high = {12, 13, 14}, low = {9, 10, 11}, close = {11, 12, 13};
CandlestickSeries prices = new CandlestickSeries("ACME");
prices.setOhlc(null, open, high, low, close);
chart.setXAxis(new SessionTimeAxis(Axis.BOTTOM, timestamps));
chart.addSeries(prices);

Candles OHLC bars Heikin-Ashi candles

  • Field Details

    • CANDLES

      public static final int CANDLES
      Filled bodies with wicks.
      See Also:
    • OHLC_BARS

      public static final int OHLC_BARS
      A vertical high-low line with open and close ticks.
      See Also:
    • HEIKIN_ASHI

      public static final int HEIKIN_ASHI
      Candles of Heikin-Ashi averaged prices, which smooth out noise to show the trend.
      See Also:
  • Constructor Details

    • CandlestickSeries

      public CandlestickSeries(String name)

      Creates an empty series.

      Parameters
      • name: the series name
  • Method Details

    • setOhlc

      public CandlestickSeries setOhlc(double[] x, double[] open, double[] high, double[] low, double[] close)

      Replaces all prices.

      Parameters
      • x: the x value of each period (a time, or an index for SessionTimeAxis); null for 0, 1, 2...

      • open: opening prices

      • high: highest prices

      • low: lowest prices

      • close: closing prices

      Returns

      this series

    • addOhlc

      public CandlestickSeries addOhlc(double x, double open, double high, double low, double close)

      Appends one period, for streaming quotes.

      Parameters
      • x: the period's x value

      • open: the opening price

      • high: the highest price

      • low: the lowest price

      • close: the closing price

      Returns

      this series

    • add

      public XYSeries add(double x, double y)
      Description copied from class: XYSeries
      Appends a point. With setMaxPoints the oldest point drops off, for real time data.
      Overrides:
      add in class XYSeries
    • updateLast

      public CandlestickSeries updateLast(double price)

      Updates the last period in place, as a live tick does to the current candle.

      Parameters
      • price: the latest traded price
      Returns

      this series

    • setStyle

      public CandlestickSeries setStyle(int style)

      Chooses candles, OHLC bars or Heikin-Ashi candles.

      Parameters
      • style: CANDLES, OHLC_BARS or HEIKIN_ASHI
      Returns

      this series

    • getStyle

      public int getStyle()
      The drawing style.
    • setBodyFraction

      public CandlestickSeries setBodyFraction(float f)

      The fraction of each slot a body takes, 0.1 to 1.

      Parameters
      • f: the fraction
      Returns

      this series

    • setColors

      public CandlestickSeries setColors(int up, int down)

      Overrides the theme's rising and falling colours.

      Parameters
      • up: colour of rising periods

      • down: colour of falling periods

      Returns

      this series

    • getOpen

      public double getOpen(int i)
      Opening price of period i.
    • getHigh

      public double getHigh(int i)
      Highest price of period i.
    • getLow

      public double getLow(int i)
      Lowest price of period i.
    • getClose

      public double getClose(int i)
      Closing price of period i.
    • heikinAshi

      public double[][] heikinAshi()

      Computes Heikin-Ashi values, {open, high, low, close} arrays.

      Returns

      the averaged prices for every period

    • dataChanged

      protected void dataChanged()
      Drops the cached Heikin-Ashi values: they depend on every candle, so any change to the data (an add, a slide, a set, an updateLast) makes them stale, not only a change of length.
      Overrides:
      dataChanged in class XYSeries
    • getYBounds

      public double[] getYBounds()
      Description copied from class: Series
      The extent of the data along y, {min, max}, or null when empty or not cartesian.
      Overrides:
      getYBounds in class XYSeries
    • getXBounds

      public double[] getXBounds()
      Description copied from class: Series
      The extent of the data along x, {min, max}, or null when empty or not cartesian.
      Overrides:
      getXBounds in class XYSeries
    • paint

      public void paint(ChartContext ctx)
      Description copied from class: Series

      Paints the series.

      Parameters
      • ctx: the current frame: graphics, plot area, axes and animation progress
      Specified by:
      paint in class Series
    • hitTest

      public ChartPoint hitTest(ChartContext ctx, int x, int y, int radius)
      Description copied from class: Series

      Finds the data point nearest a screen position.

      Parameters
      • ctx: the frame the series was last painted in

      • x: chart relative x

      • y: chart relative y

      • radius: how far from the point a touch may land and still hit it

      Returns

      the point, or null

      Overrides:
      hitTest in class XYSeries
    • formatTooltip

      public String formatTooltip(ChartContext ctx, ChartPoint p)
      Description copied from class: Series

      The tooltip row for a point: the series or point name and its formatted value. Series with several values per point (open/high/low/close, ranges, box plots) override this.

      Parameters
      • ctx: the last paint context

      • p: the point

      Returns

      one line of text

      Overrides:
      formatTooltip in class Series
    • paintLegendSymbol

      public void paintLegendSymbol(Graphics g, int x, int y, int size)
      Description copied from class: Series

      Paints the legend swatch.

      Parameters
      • g: graphics

      • x: swatch left

      • y: swatch top

      • size: swatch size

      Overrides:
      paintLegendSymbol in class Series
    • tableValue

      protected String tableValue(int i)
      Description copied from class: XYSeries

      The text of point i in the accessible data table.

      Parameters
      • i: the point index
      Returns

      the formatted value

      Overrides:
      tableValue in class XYSeries