Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class Indicators
- Object
- 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
vdouble[]- the values
periodint- the window length
Returns
the average of each window,
NaN for the first period - 1 valuesema
public static double[] ema(double[] v, int period)The exponential moving average, seeded with the simple average of the first window.
Parameters
vdouble[]- the values
periodint- the window length
Returns
the average,
NaN for the first period - 1 valuesbollinger
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
vdouble[]- the values
periodint- the window length, 20 is customary
deviationsdouble- 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
vdouble[]- the closing prices
periodint- the window length, 14 is customary
Returns
the index,
NaN for the first period valuesmacd
public static double[][] macd(double[] v, int fast, int slow, int signal)Moving average convergence divergence.
Parameters
vdouble[]- the closing prices
fastint- the fast EMA period, 12 is customary
slowint- the slow EMA period, 26 is customary
signalint- 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
pricesCandlestickSeries- 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
nameString- the series name
sourceXYSeries- the series whose x values to reuse
valuesdouble[]- the indicator values, parallel to the source
Returns
a new line series