Class Indicators

java.lang.Object
com.codename1.ui.chart.indicator.Indicators

public final class Indicators extends Object

Technical indicators computed from price arrays.

Every method returns arrays as long as its input. Values before the indicator has enough history are NaN, which line series draw as a gap, so an indicator lines up with its prices index for index.

double[] open = {10, 11, 12, 11, 13}, high = {12, 13, 14, 13, 15};
double[] low = {9, 10, 11, 10, 12}, close = {11, 12, 11, 13, 14};
CandlestickSeries prices = new CandlestickSeries("ACME").setOhlc(null, open, high, low, close);
Chart chart = new Chart();
chart.addSeries(prices);
chart.addSeries(Indicators.line("SMA 3", prices, Indicators.sma(close, 3)));
double[][] bb = Indicators.bollinger(close, 3, 2);
  • Method Summary

    Modifier and Type
    Method
    Description
    static double[][]
    bollinger(double[] v, int period, double deviations)
    Bollinger bands: a simple moving average with bands a number of standard deviations away.
    static double[]
    The closing prices of a candlestick series.
    static double[]
    ema(double[] v, int period)
    The exponential moving average, seeded with the simple average of the first window.
    static LineSeries
    line(String name, XYSeries source, double[] values)
    A line series of indicator values that shares the x values of source.
    static double[][]
    macd(double[] v, int fast, int slow, int signal)
    Moving average convergence divergence.
    static double[]
    rsi(double[] v, int period)
    The relative strength index with Wilder smoothing, between 0 and 100.
    static double[]
    sma(double[] v, int period)
    The simple moving average.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • sma

      public static double[] sma(double[] v, int period)

      The simple moving average.

      Parameters
      • v: the values

      • period: the window length

      Returns

      the average of each window, NaN for the first period - 1 values

    • ema

      public static double[] ema(double[] v, int period)

      The exponential moving average, seeded with the simple average of the first window.

      Parameters
      • v: the values

      • period: the window length

      Returns

      the average, NaN for the first period - 1 values

    • bollinger

      public static double[][] bollinger(double[] v, int period, double deviations)

      Bollinger bands: a simple moving average with bands a number of standard deviations away.

      Parameters
      • v: the values

      • period: the window length, 20 is customary

      • deviations: the band width in standard deviations, 2 is customary

      Returns

      {middle, upper, lower}

    • rsi

      public static double[] rsi(double[] v, int period)

      The relative strength index with Wilder smoothing, between 0 and 100.

      Parameters
      • v: the closing prices

      • period: the window length, 14 is customary

      Returns

      the index, NaN for the first period values

    • macd

      public static double[][] macd(double[] v, int fast, int slow, int signal)

      Moving average convergence divergence.

      Parameters
      • v: the closing prices

      • fast: the fast EMA period, 12 is customary

      • slow: the slow EMA period, 26 is customary

      • signal: the signal EMA period, 9 is customary

      Returns

      {macd, signal, histogram}

    • closes

      public static double[] closes(CandlestickSeries prices)

      The closing prices of a candlestick series.

      Parameters
      • prices: the series
      Returns

      a new array of closes

    • line

      public static LineSeries line(String name, XYSeries source, double[] values)

      A line series of indicator values that shares the x values of source.

      Parameters
      • name: the series name

      • source: the series whose x values to reuse

      • values: the indicator values, parallel to the source

      Returns

      a new line series