Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class Indicators

  1. Object
  2. Indicators

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);

Methods

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

Inherited methods

Method details

sma

public static double[] sma(double[] v, int period)
The simple moving average.

Parameters

v double[]
the values
period int
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 double[]
the values
period int
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 double[]
the values
period int
the window length, 20 is customary
deviations double
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 double[]
the closing prices
period int
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 double[]
the closing prices
fast int
the fast EMA period, 12 is customary
slow int
the slow EMA period, 26 is customary
signal int
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 CandlestickSeries
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 String
the series name
source XYSeries
the series whose x values to reuse
values double[]
the indicator values, parallel to the source

Returns

a new line series