Documentation, examples and further information of the ta4j project
This project is maintained by ta4j Organization
A trading strategy is a set of rules designating the conditions that must be met for trade entries and exits to occur.
About trading strategies:
In ta4j a trading strategy is made of trading rules.
Trading rules are designed according to the specification pattern. They can be combined and chained together using boolean logic:
Rule entryRule = new CrossedUpIndicatorRule(shortSma, longSma)
.or(new CrossedDownIndicatorRule(closePrice, Decimal.valueOf("800")));
Ta4j provides a set of basic rules. They are all implementations of the Rule interface and they can be used to build both entry and exit rules.
Rule exitRule = new CrossedDownIndicatorRule(shortSma, longSma)
.or(new StopLossRule(closePrice, Decimal.valueOf("3")))
.or(new StopGainRule(closePrice, Decimal.valueOf("2")));
Using ta4j, you can check if an entry/exit condition is met by calling the Rule#isSatisfied(int, TradingRecord)
method. You just have to give:
TradingRecord
object (for rules with a complex logic, i.e. using trading history and previous results)A trading strategy is just a pair of rules designed to achieve a profitable return over a bar series. It is made of an entry rule and an exit rule.
Strategy myStrategy = new BaseStrategy(entryRule, exitRule);
It can be backtested over a bar series:
BarSeries series = ...
BarSeriesManager seriesManager = new BarSeriesManager(series);
TradingRecord tradingRecord = seriesManager.run(myStrategy);
Or used for live trading, as it’s done in the bot examples.