A Java library for technical analysis.
Technical Analysis for Java
Documentation · Javadoc · Examples · Discord
ta4j is an open-source Java library for technical analysis and trading-system research. Build indicators and rules, backtest strategies with realistic costs and execution assumptions, inspect the results, and reuse the same strategy logic in live applications.
Why ta4j? · Install · Quick start · Workflow · Examples · Contributing
ta4j gives Java developers a typed, composable model for market data, indicators, rules, strategies, backtests, analysis, and live-style execution records. It fits naturally into JVM applications and tooling without requiring a Python bridge, a separate service, or a proprietary strategy DSL.
The goal is reproducible research, not guaranteed returns. ta4j helps you state a trading idea precisely, test it under explicit assumptions, and understand where the result came from. Market data and broker connectivity remain under your control.
BarSeries implementations for ordinary, moving-window, and concurrent workflows
Broad indicator and pattern catalog
Moving averages, momentum, volatility, volume, candlestick patterns, market structure, and more
Composable strategies
Fluent Indicator, Rule, and Strategy APIs with no required DSL
Backtesting and research
Single-strategy runs, large candidate sets, ranking, parameter research, and walk-forward workflows
Execution realism
Transaction and borrowing costs, slippage, stop-limit fills, position sizing, partial fills, and lot matching
Analysis and presentation
Risk/return criteria, charting workflows, and JSON serialization support
Forecasting
Causal forecast-state and projection APIs for Monte Carlo, analog, Kalman, and conformal workflows
Live integration
Reuse strategy logic while your application owns data ingestion, order routing, reconciliation, and recovery
ta4j requires Java 25+. Most applications need only ta4j-core:
<dependency>
<groupId>org.ta4j</groupId>
<artifactId>ta4j-core</artifactId>
<version>0.25.0</version>
</dependency>
Use ta4j-examples for runnable demos, sample data sources, and charting workflows to learn from or copy into your own project. It is not required by ta4j-core.
Snapshot builds are published through the Sonatype Central snapshot repository:
<repository>
<id>central-portal-snapshots</id>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<dependency>
<groupId>org.ta4j</groupId>
<artifactId>ta4j-core</artifactId>
<version>0.25.1-SNAPSHOT</version>
</dependency>
Stable examples artifact:
<dependency>
<groupId>org.ta4j</groupId>
<artifactId>ta4j-examples</artifactId>
<version>0.25.0</version>
</dependency>
Snapshot examples artifact:
<dependency>
<groupId>org.ta4j</groupId>
<artifactId>ta4j-examples</artifactId>
<version>0.25.1-SNAPSHOT</version>
</dependency>
git clone https://github.com/ta4j/ta4j.git
cd ta4j
# Build the reactor once, then run the default Quickstart example.
./mvnw -DskipTests install
./mvnw -pl ta4j-examples exec:java
On Windows, use mvnw.cmd instead of ./mvnw. The example loads bundled Bitcoin data, evaluates a strategy, prints performance metrics, and displays a chart when a graphical environment is available.
Run another example by overriding the configured main class:
./mvnw -pl ta4j-examples exec:java -Dexec.mainClass=ta4jexamples.backtesting.TradingRecordParityBacktest
The essential model is:
BarSeries→Indicator→Rule→Strategy→TradingRecord
…
The runnable Quickstart adds data loading, metrics, and charting around this same flow.
A typical ta4j application follows one path:
market data →
BarSeries→ indicators → rules → strategy → backtest or live evaluation → metrics and charts
ta4j-core works with any OHLCV source. The ta4j-examples module includes a shared BarSeriesDataSource model and ready-to-run loaders for:
For production systems, adapt your broker, exchange, database, REST API, or WebSocket feed into bars and keep normalization, gap handling, and corporate-action adjustments explicit.
Backtests can model costs before you calculate returns and risk:
TradingRecord record = new BarSeriesManager(
series,
new LinearTransactionCostModel(0.001),
new LinearBorrowingCostModel(0.0001))
.run(strategy);
Num netReturn = new NetReturnCriterion().calculate(series, record);
Num maximumDrawdown = new MaximumDrawdownCriterion().calculate(series, record);
Use TradeExecutionModel implementations when fill timing, slippage, stop-limit behavior, or partial execution matters. Use BacktestExecutor when you need to evaluate and rank many independent strategy candidates. The backtesting guide and realism checklist explain the assumptions that most often invalidate attractive results.
Charting helpers live in ta4j-examples and build on JFreeChart:
…
More charting examplesRSI in a separate subchart:
…
A performance criterion beside the strategy:
…
Multiple indicators and performance layers:
…
See the charting guide for layout, export, and time-axis options.
The same Strategy can evaluate historical or newly arriving bars, but ta4j is not an order-management system. A live integration must:
shouldEnter(index, tradingRecord) and shouldExit(index, tradingRecord)TradingRecord synchronizedStart with the core API decision guide, live-candle semantics, and the live trading runbook.
Forecast indicators stay inside the normal Indicator model while producing a distribution at a fixed future horizon. A forecast evaluated at index i reads source values only through i, so it can later be compared with the realized value at i + horizon without look-ahead leakage.
LogReturnIndicator returns = new LogReturnIndicator(series);
ReturnForecastStateIndicator<ReturnForecastState> state =
new EwmaReturnForecastStateIndicator(returns);
ForecastProjectionIndicator fiveBarForecast =
new MonteCarloPriceForecastIndicator(state, 5);
Indicator<Num> median = fiveBarForecast.median();
Indicator<Num> downside = fiveBarForecast.quantile(0.05);
Use deterministic seeds and explicit projection indicators when results must be repeatable. The examples module includes complete rolling conformal and kinematic Kalman walkthroughs.
Supported indicators, rules, and strategies can be serialized for persistence, sharing, and integration with other systems.
JSON serialization examples// Serialize an indicator (RSI) to JSON
ClosePriceIndicator close = new ClosePriceIndicator(series);
RSIIndicator rsi = new RSIIndicator(close, 14);
String rsiJson = rsi.toJson();
LOG.info("Output: {}", rsiJson);
// Output:
// {"type":"RSIIndicator","parameters":{"barCount":14},"components":[{"type":"ClosePriceIndicator"}]}
…
…
Restore supported components with Indicator.fromJson(series, json) and Strategy.fromJson(series, json). See migration and version compatibility before persisting descriptors across releases.
Beyond the basic strategy loop, ta4j includes building blocks for batch backtests, parameter research, position sizing, causal swing detection, rolling correlations, regime-aware rules, candlestick patterns, Elliott Wave analysis, LPPL residuals, streaming trade ingestion, and fill-aware live records.
These capabilities are intentionally not expanded into mini-manuals here. Use the examples index, core API guide, Javadoc, and wiki to go deeper without losing the onboarding path.
ta4j lets you choose DecimalNum for precision-first workflows or DoubleNum for throughput-first workflows with accepted floating-point tradeoffs. Moving series can cap retained history, indicator values are cached, and independent strategy candidates can be evaluated in parallel.
Measure changes on your own workload rather than relying on generic claims. Use the BacktestPerformanceTuningHarness, the Num guide, and Performance Characterization for repeatable comparisons.
The ta4j-examples module is organized as progressive learning tracks:
Quickstart, StrategyAnalysis
Data sourcing
YahooFinanceBacktest, CoinbaseBacktest
Execution semantics
TradingRecordParityBacktest, [TradeFillRecordingExample](ta4j-examples/src/main/java/ta4jexamples/backtesting/Trade
No open issues yet, or sync has not completed.