Usage Examples
The ta4j-examples module is the runnable companion to this wiki. Each example is a standalone main program you can open in your IDE or run with Maven.
Choose by intent
If you are deciding where to start, use this map:
- First successful run: Start quickly
- Build and compare strategy logic: Strategy patterns
- Preview compact serialization configuration: Serialization and Named Shorthand
- Validate execution assumptions and metrics: Backtesting & analytics
- Integrate bot loops and fill-driven recording: Bots & live trading
- Debug indicators and visual behavior: Indicators & visualization
- Deep Elliott workflows: Elliott Wave analysis
For a curated progression, also see the module-level examples index: ta4j-examples/README.md.
For verification signals and common failure patterns, see Examples Expected Outputs.
Start quickly
- Quickstart - Load data, build a strategy, run a backtest, and render the result
- StrategyAnalysis - Print common criteria and strategy diagnostics
Indicators & visualization
- IndicatorsToCsv - Export indicator values for spreadsheet analysis
- IndicatorsToChart - Plot price plus indicator overlays
- CandlestickChart - Candlestick chart overlays
- Forecast Indicators - Build forward-looking return and price distributions, then project them to rule-friendly point forecasts
- Charting - Full
ChartWorkflowguide - ElliottWaveIndicatorSuiteDemo - Full Elliott Wave indicator-suite run with charts and scenario analysis
- ElliottWavePresetDemo - Preset Elliott Wave launcher for ossified BTC/ETH/SP500 datasets or live datasource arguments
- WyckoffCycleIndicatorSuiteDemo - Wyckoff cycle facade and one-shot analysis demo
Strategy patterns
- CCICorrectionStrategy - Baseline trend-reversion pattern
- RSI2Strategy - Classic mean-reversion example
- NetMomentumStrategy - Strategy built around Net Momentum
- HighRewardElliottWaveStrategy - Elliott Wave strategy using scenario confidence, risk/reward, trend, and momentum gates
- WalkForward - Full walk-forward optimization loop
Backtesting & analytics
- SimpleMovingAverageBacktest - Baseline crossover backtest
- MovingAverageCrossOverRangeBacktest - Parameter sweeps across SMA windows
- SimpleMovingAverageRangeBacktest - Parameter sweep that ranks the shortlist with weighted normalized criteria (
WeightedCriterion.of(...),getTopStrategiesWeighted(...)) - CoinbaseBacktest - Backtest against Coinbase-sourced data
- YahooFinanceBacktest - Backtest against Yahoo Finance data
- TradingRecordParityBacktest - Compare next-open, current-close, and slippage execution models side by side, then show the same fills across default, provided, and factory-configured
BaseTradingRecordruns - TradeFillRecordingExample - Stream fills with
TradingRecord.operate(fill), group batches withTrade.fromFills(...), and compareFIFO,LIFO,AVG_COST, andSPECIFIC_IDexit matching - BacktestPerformanceTuningHarness - Tune large batch runs built on
BacktestExecutor - StaticPortfolioBacktest - Run a deterministic static target-weight portfolio simulation with aligned assets, cash and transaction costs
- StrategyExecutionLogging - Trace rule evaluation and execution decisions line by line
- ElliottWaveTrendBacktest - Evaluate Elliott Wave trend-bias prediction accuracy across ossified datasets
- HighRewardElliottWaveBacktest - Run several parameter profiles for the high-reward Elliott Wave strategy
If you are learning the current execution stack, start with Quickstart, then TradingRecordParityBacktest, then TradeFillRecordingExample, and finally SimpleMovingAverageRangeBacktest.
Elliott Wave analysis
- ElliottWaveAdaptiveSwingAnalysis - Composite fractal/adaptive-ZigZag swing detection with confidence breakdown logging
- ElliottWaveMultiDegreeAnalysisDemo - Multi-degree analysis with cross-degree scenario support
- ElliottWavePatternProfileDemo - Compare default and pattern-aware confidence profiles
Bots & live trading
- TradingBotOnMovingBarSeries - Minimal manual bot loop using a moving series and
BaseTradingRecord - Live Trading - Production-oriented guidance for
ConcurrentBarSeries, fill-driven record updates, and recovery - Bar Series & Bars - Streaming aggregation and bar-ingestion patterns
For new live code:
- Use
BaseTradingRecordas the record type - Update the record from confirmed fills with
TradingRecord.operate(fill)or batch one logical order withTrade.fromFills(...) - Use
ConcurrentBarSerieswhen feed ingestion and strategy evaluation happen on different threads - Treat
LiveTradingRecordandExecutionFillas compatibility-only APIs during migration
More examples
The examples module also contains data-source adapters, charting helpers, Elliott Wave demos, and indicator showcases. If a workflow is documented in the wiki but missing a runnable example, contributions are welcome.
For compatibility migration between legacy and preferred APIs, see Migration and Version Compatibility.