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.

Volatility indicators quantify how much price moves, independent of direction. They are used for position sizing, setting stop distances, identifying squeeze conditions, and filtering low-volatility environments where breakout strategies struggle.

ATR — Average True Range

Constructors:
  • ATRIndicator(BarSeries series, int barCount)
  • ATRIndicator(TRIndicator tr, int barCount)
Wilder’s Average True Range: Smoothed (MMA) average of the True Range, where True Range = max(high - low, |high - prevClose|, |low - prevClose|). The standard measure of volatility used by most other volatility indicators.
ATRIndicator atr = new ATRIndicator(series, 14);

int idx = series.getEndIndex();
Num atrValue = atr.getValue(idx);

// Stop distance = 2 × ATR
Num stopDistance = atrValue.multipliedBy(series.numFactory().two());
Unstable bars: trIndicator.getCountOfUnstableBars() + barCount

Bollinger Bands

Constructor: BollingerBandsMiddleIndicator(Indicator<Num> indicator)The middle band is any moving average. Typically an SMAIndicator is used. The upper and lower bands reference this indicator.
ClosePriceIndicator close = new ClosePriceIndicator(series);
SMAIndicator sma = new SMAIndicator(close, 20);
BollingerBandsMiddleIndicator bbm = new BollingerBandsMiddleIndicator(sma);
Constructors:
  • BollingerBandsUpperIndicator(BollingerBandsMiddleIndicator bbm, Indicator<Num> deviation) — k = 2
  • BollingerBandsUpperIndicator(BollingerBandsMiddleIndicator bbm, Indicator<Num> deviation, Num k)
  • BollingerBandsLowerIndicator(BollingerBandsMiddleIndicator bbm, Indicator<Num> indicator) — k = 2
  • BollingerBandsLowerIndicator(BollingerBandsMiddleIndicator bbm, Indicator<Num> indicator, Num k)
Upper band = SMA + k × StdDev; lower band = SMA - k × StdDev. The standard deviation indicator is typically a StandardDeviationIndicator.
ClosePriceIndicator close = new ClosePriceIndicator(series);
SMAIndicator sma = new SMAIndicator(close, 20);
StandardDeviationIndicator sd = new StandardDeviationIndicator(close, 20);

BollingerBandsMiddleIndicator bbm = new BollingerBandsMiddleIndicator(sma);
BollingerBandsUpperIndicator  bbu = new BollingerBandsUpperIndicator(bbm, sd);
BollingerBandsLowerIndicator  bbl = new BollingerBandsLowerIndicator(bbm, sd);

Num upper = bbu.getValue(series.getEndIndex());
Num lower = bbl.getValue(series.getEndIndex());
Constructor: BollingerBandWidthIndicator(BollingerBandsUpperIndicator bbu, BollingerBandsMiddleIndicator bbm, BollingerBandsLowerIndicator bbl)(upper - lower) / middle × 100. Measures how wide the bands are relative to the middle. Squeeze conditions (low bandwidth) often precede significant breakouts.
BollingerBandWidthIndicator bbw = new BollingerBandWidthIndicator(bbu, bbm, bbl);
Num bandwidth = bbw.getValue(series.getEndIndex());
Constructor: PercentBIndicator(Indicator<Num> indicator, int barCount, double k)Measures where price sits within the Bollinger Bands: 0 = at lower band, 1 = at upper band, 0.5 = at middle. Values above 1 or below 0 indicate price is outside the bands.
ClosePriceIndicator close = new ClosePriceIndicator(series);
PercentBIndicator percentB = new PercentBIndicator(close, 20, 2.0);

Num pb = percentB.getValue(series.getEndIndex());
// pb > 1.0 = overbought (price above upper band)
// pb < 0.0 = oversold  (price below lower band)
BollingerBandFacade wires all four components together in one call:
ClosePriceIndicator close = new ClosePriceIndicator(series);
BollingerBandFacade bb = new BollingerBandFacade(close, 20, 2);

BollingerBandsUpperIndicator  upper     = bb.upper();
BollingerBandsMiddleIndicator middle    = bb.middle();
BollingerBandsLowerIndicator  lower     = bb.lower();
BollingerBandWidthIndicator   bandwidth = bb.bandwidth();
PercentBIndicator             percentB  = bb.percentB();

Keltner Channels

Constructors:
  • KeltnerChannelMiddleIndicator(BarSeries series, int barCountEMA) — uses typical price
  • KeltnerChannelMiddleIndicator(Indicator<Num> indicator, int barCountEMA) — custom source
EMA of typical price. The center line of the Keltner Channel.
KeltnerChannelMiddleIndicator middle = new KeltnerChannelMiddleIndicator(series, 20);
Constructor: KeltnerChannelUpperIndicator(KeltnerChannelMiddleIndicator middle, double ratio, int barCountATR)Upper band = middle + ratio × ATR(barCountATR). The lower band mirrors this below the middle.
KeltnerChannelMiddleIndicator middle = new KeltnerChannelMiddleIndicator(series, 20);
KeltnerChannelUpperIndicator  upper  = new KeltnerChannelUpperIndicator(middle, 2.0, 10);
KeltnerChannelLowerIndicator  lower  = new KeltnerChannelLowerIndicator(middle, 2.0, 10);
When Bollinger Bands contract inside Keltner Channels, a “squeeze” is active — often preceding a large move:
ClosePriceIndicator close = new ClosePriceIndicator(series);
StandardDeviationIndicator sd = new StandardDeviationIndicator(close, 20);

BollingerBandsMiddleIndicator bbm = new BollingerBandsMiddleIndicator(new SMAIndicator(close, 20));
BollingerBandsUpperIndicator  bbu = new BollingerBandsUpperIndicator(bbm, sd);
BollingerBandsLowerIndicator  bbl = new BollingerBandsLowerIndicator(bbm, sd);

KeltnerChannelMiddleIndicator km = new KeltnerChannelMiddleIndicator(series, 20);
KeltnerChannelUpperIndicator  ku = new KeltnerChannelUpperIndicator(km, 1.5, 10);
KeltnerChannelLowerIndicator  kl = new KeltnerChannelLowerIndicator(km, 1.5, 10);

int idx = series.getEndIndex();
boolean squeezed = bbu.getValue(idx).isLessThan(ku.getValue(idx))
                && bbl.getValue(idx).isGreaterThan(kl.getValue(idx));

Chandelier Exit

Constructors:
  • ChandelierExitLongIndicator(BarSeries series) — defaults: barCount 22, k 3.0
  • ChandelierExitLongIndicator(BarSeries series, int barCount, double k)
highest(high, n) - k × ATR(n). A trailing stop for long positions that tightens as ATR contracts.
ChandelierExitLongIndicator chandelierLong = new ChandelierExitLongIndicator(series, 22, 3.0);

Num stopLevel = chandelierLong.getValue(series.getEndIndex());
Constructors:
  • ChandelierExitShortIndicator(BarSeries series) — defaults: barCount 22, k 3.0
  • ChandelierExitShortIndicator(BarSeries series, int barCount, double k)
lowest(low, n) + k × ATR(n). Mirror of the long version for short positions.
ChandelierExitShortIndicator chandelierShort = new ChandelierExitShortIndicator(series, 22, 3.0);

Ulcer Index, Chop

Constructor: UlcerIndexIndicator(Indicator<Num> indicator, int barCount)Measures downside volatility by calculating the RMS of percentage drawdowns from the highest point in the window. Higher values = more painful drawdowns. Useful for risk-adjusted return metrics.
ClosePriceIndicator close = new ClosePriceIndicator(series);
UlcerIndexIndicator ulcer = new UlcerIndexIndicator(close, 14);
Constructor: ChopIndicator(BarSeries barSeries, int ciTimeFrame, int scaleTo)Identifies whether price is trending (scaleTo = 100, values below 38.2) or choppy (values above 61.8).
ChopIndicator chop = new ChopIndicator(series, 14, 100);

Num choppiness = chop.getValue(series.getEndIndex());
boolean isTrending = choppiness.isLessThan(series.numFactory().numOf(38.2));

SqueezeProIndicator

Constructor: SqueezeProIndicator(BarSeries series, int barCount)Combines Bollinger Bands and Keltner Channels to detect squeeze conditions. Returns a value representing the momentum histogram when squeeze fires.
SqueezeProIndicator squeezePro = new SqueezeProIndicator(series, 20);

Statistics indicators

Constructor: StandardDeviationIndicator(Indicator<Num> indicator, int barCount)Rolling population standard deviation over barCount bars. The standard input for Bollinger Band deviations.
ClosePriceIndicator close = new ClosePriceIndicator(series);
StandardDeviationIndicator sd = new StandardDeviationIndicator(close, 20);
Rolling variance. The default constructor uses sample variance (n-1 divisor). Use factory methods to be explicit:
  • VarianceIndicator(Indicator<Num> indicator, int barCount) — sample variance (default)
  • VarianceIndicator(Indicator<Num> indicator, int barCount, SampleType sampleType) — explicit type
  • VarianceIndicator.ofSample(indicator, barCount) — sample variance (n-1)
  • VarianceIndicator.ofPopulation(indicator, barCount) — population variance (n)
ClosePriceIndicator close = new ClosePriceIndicator(series);

// Sample variance (matches spreadsheet STDEV)
VarianceIndicator sampleVariance = VarianceIndicator.ofSample(close, 20);

// Population variance
VarianceIndicator popVariance = VarianceIndicator.ofPopulation(close, 20);
Constructor: CorrelationCoefficientIndicator(Indicator<Num> indicator1, Indicator<Num> indicator2, int barCount)Pearson correlation between two indicators over a rolling window. Returns -1 to +1.
ClosePriceIndicator close1 = new ClosePriceIndicator(series1);
ClosePriceIndicator close2 = new ClosePriceIndicator(series2);
CorrelationCoefficientIndicator corr = new CorrelationCoefficientIndicator(close1, close2, 20);
ClassDescription
ZScoreIndicator(indicator, barCount)Rolling Z-score (standard deviations from mean)
SimpleLinearRegressionIndicator(indicator, barCount, type)Linear regression line, slope, or intercept
SigmaIndicator(indicator, barCount)Distance from mean in standard deviations
CovarianceIndicator(indicator1, indicator2, barCount)Rolling covariance
PearsonCorrelationIndicator(indicator1, indicator2, barCount)Pearson correlation
MeanDeviationIndicator(indicator, barCount)Mean absolute deviation