Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ta4j/ta4j/llms.txt

Use this file to discover all available pages before exploring further.

ta4j indicators implement the Indicator<T> interface and compose into pipelines. Every indicator calculates a value for a given bar index, caches results, and declares how many initial bars it needs to warm up before producing reliable output.

The Indicator<T> interface

public interface Indicator<T> {
    T getValue(int index);
    int getCountOfUnstableBars();
    BarSeries getBarSeries();
}
getValue(int index) is the primary method. Pass the index of the bar you want to evaluate. Numeric indicators return Num; pattern indicators return Boolean.

Indicator composition

Indicators are designed to accept another indicator as input, not raw price data directly. This lets you pipe one computation into another without boilerplate.
BarSeries series = ...;

// Layer indicators: close -> EMA -> MACD -> signal line
ClosePriceIndicator close = new ClosePriceIndicator(series);
MACDIndicator macd         = new MACDIndicator(close, 12, 26);
EMAIndicator  signal       = macd.getSignalLine(9);

Num macdValue   = macd.getValue(49);
Num signalValue = signal.getValue(49);
Each indicator holds a reference to its source indicator; the chain is evaluated lazily on the first getValue call and cached afterward.

Warm-up (unstable bars)

Every indicator exposes getCountOfUnstableBars(). Indices below this threshold return NaN (for numeric indicators) or false (for boolean indicators). Always skip warm-up bars in strategies:
ATRIndicator atr = new ATRIndicator(series, 14);
int stable = atr.getCountOfUnstableBars();

for (int i = stable; i <= series.getEndIndex(); i++) {
    Num value = atr.getValue(i); // guaranteed stable
}
Warm-up periods accumulate through indicator chains. A StandardDeviationIndicator(closePrice, 20) wrapping an EMAIndicator(close, 10) requires at least 20 + 10 - 1 = 29 bars before producing reliable output.

Helper (price) indicators

These zero-latency helpers extract OHLCV fields from each bar. They have getCountOfUnstableBars() == 0 and are the standard inputs for other indicators.
ClassReturns
ClosePriceIndicator(BarSeries)Close price
OpenPriceIndicator(BarSeries)Open price
HighPriceIndicator(BarSeries)High price
LowPriceIndicator(BarSeries)Low price
VolumeIndicator(BarSeries)Volume
TypicalPriceIndicator(BarSeries)(high + low + close) / 3
MedianPriceIndicator(BarSeries)(high + low) / 2
BarSeries series = new BaseBarSeriesBuilder().withName("BTC").build();

ClosePriceIndicator close  = new ClosePriceIndicator(series);
HighPriceIndicator  high   = new HighPriceIndicator(series);
LowPriceIndicator   low    = new LowPriceIndicator(series);
VolumeIndicator     volume = new VolumeIndicator(series);

Custom indicators

Extend AbstractIndicator<T> for stateless indicators, or CachedIndicator<T> to get automatic result caching (strongly recommended for anything with a loop or recursive access).
import org.ta4j.core.Indicator;
import org.ta4j.core.indicators.CachedIndicator;
import org.ta4j.core.num.Num;

/** Mid-price: (high + low) / 2 */
public class MidPriceIndicator extends CachedIndicator<Num> {

    private final Indicator<Num> highIndicator;
    private final Indicator<Num> lowIndicator;

    public MidPriceIndicator(BarSeries series) {
        super(series);
        this.highIndicator = new HighPriceIndicator(series);
        this.lowIndicator  = new LowPriceIndicator(series);
    }

    @Override
    protected Num calculate(int index) {
        Num high = highIndicator.getValue(index);
        Num low  = lowIndicator.getValue(index);
        return high.plus(low).dividedBy(getBarSeries().numFactory().two());
    }

    @Override
    public int getCountOfUnstableBars() {
        return 0;
    }
}
Use RecursiveCachedIndicator<T> when your calculate method calls getValue(index - 1) on itself (e.g., Parabolic SAR, KAMA).

Indicator categories

Trend

Moving averages, MACD, ADX, Aroon, Ichimoku, Parabolic SAR, SuperTrend — 40+ indicators.

Momentum

RSI, Stochastic, CCI, Williams %R, ROC, TSI, Vortex — 20+ indicators.

Volatility

ATR, Bollinger Bands, Keltner Channels, Chandelier Exit, Ulcer Index — 15+ indicators.

Volume

OBV, VWAP, Chaikin Money Flow, MFI, Accumulation/Distribution — 20+ indicators.

Candlestick Patterns

Hammer, Engulfing, Doji, Morning/Evening Star, Marubozu — 25+ patterns.

Statistics

Variance, Standard Deviation, Correlation, Z-Score, Linear Regression.