Use this file to discover all available pages before exploring further.
ta4j runs strategy backtests on the JVM with no GIL bottleneck. BacktestExecutor saturates all available CPU cores, making it practical to evaluate hundreds or thousands of parameter combinations in seconds.
For very large parameter sweeps (10,000+ strategies), use executeAndKeepTopK to minimise memory usage. It uses a min-heap to track only the top K results and discards worse performers immediately:
BacktestExecutionResult result = new BacktestExecutor(series) .executeAndKeepTopK( strategies, series.numFactory().numOf(1), Trade.TradeType.BUY, new NetProfitCriterion(), 10, // keep only the top 10 ProgressCompletion.loggingWithMemory());
Memory usage is O(K + batchSize) instead of O(strategyCount).
Walk-forward analysis splits the data into consecutive in-sample and out-of-sample windows to test whether a strategy generalises beyond its training period.
DecimalNum (default): arbitrary-precision arithmetic. More accurate, slower.
DoubleNum: double-backed arithmetic. Faster, acceptable precision for most strategies.
To use DoubleNum for a parameter sweep:
import org.ta4j.core.num.DoubleNumFactory;BarSeries series = new BaseBarSeriesBuilder() .withNumFactory(DoubleNumFactory.getInstance()) .withName("BTC-USD") .build();
This can meaningfully reduce backtest time for large sweeps.
Limit bar history with maximumBarCount
If your strategy only needs a rolling window of history (for example the last 200 bars), set maximumBarCount to cap memory usage:
series.setMaximumBarCount(500); // keep only the last 500 bars
This is especially useful for live series that grow continuously.
Use executeAndKeepTopK for massive sweeps
When evaluating more than a few thousand strategies and you only need the top performers, executeAndKeepTopK avoids storing all results in memory.