Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

ta4j

> 编程语言
Open source

A Java library for technical analysis.

2.5K stars0 likes0 views
WebsiteGitHub

About

A Java library for technical analysis.

ta4j

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


Why ta4j?

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.

Features at a glance

Capability What it gives you Market-series model OHLCV 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

Install in seconds

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.

Snapshots and the ta4j-examples dependency

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>

Quick start: Your first strategy

Run the included example

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

Use the core API

The essential model is:

BarSeries → Indicator → Rule → Strategy → TradingRecord

…

The runnable Quickstart adds data loading, metrics, and charting around this same flow.

The core workflow

A typical ta4j application follows one path:

market data → BarSeries → indicators → rules → strategy → backtest or live evaluation → metrics and charts

Sourcing market data

ta4j-core works with any OHLCV source. The ta4j-examples module includes a shared BarSeriesDataSource model and ready-to-run loaders for:

  • Yahoo Finance for stocks, ETFs, and crypto
  • Coinbase for cryptocurrency pairs
  • CSV, JSON, and trade-level Bitstamp CSV

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.

Evaluate performance with metrics

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.

Visualize and share strategies

Charting helpers live in ta4j-examples and build on JFreeChart:

…
More charting examples

RSI 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.

From backtest to live trading

The same Strategy can evaluate historical or newly arriving bars, but ta4j is not an order-management system. A live integration must:

  • choose deliberately between forming-candle and closed-candle evaluation
  • call shouldEnter(index, tradingRecord) and shouldExit(index, tradingRecord)
  • record broker-confirmed fills and keep TradingRecord synchronized
  • deduplicate orders, reconcile state after restart, and handle rejected or partial fills

Start with the core API decision guide, live-candle semantics, and the live trading runbook.

Advanced capabilities

Forecasting

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.

Strategy and component serialization

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.

Specialized research tools

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.

Performance

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.

Real-world examples

The ta4j-examples module is organized as progressive learning tracks:

Goal Start here First strategy and metrics Quickstart, StrategyAnalysis Data sourcing YahooFinanceBacktest, CoinbaseBacktest Execution semantics TradingRecordParityBacktest, [TradeFillRecordingExample](ta4j-examples/src/main/java/ta4jexamples/backtesting/Trade

GitHub Issues· 0 open

View all on GitHub

No open issues yet, or sync has not completed.

Highlights

  • •Yahoo Finance for stocks, ETFs, and crypto
  • •Coinbase for cryptocurrency pairs
  • •CSV, JSON, and trade-level Bitstamp CSV
  • •choose deliberately between forming-candle and closed-candle evaluation
  • •call shouldEnter(index, tradingRecord) and shouldExit(index, tradingRecord)
  • •record broker-confirmed fills and keep TradingRecord synchronized
  • •deduplicate orders, reconcile state after restart, and handle rejected or partial fills

> Tags

Javabitcoinethereumforexjava

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言