Documentation, examples and further information of the ta4j project
This project is maintained by ta4j Organization
We are at discord. Create your account and join!
Strategy
?You can determine the kind of order in the BarSeriesManager#run
method with help of the OrderType
parameter:
/**
* Runs the provided strategy over the managed series.
* <p>
* Opens the trades with the specified {@link OrderType orderType} order.
* @param strategy the trading strategy
* @param orderType the {@link OrderType} used to open the trades
* @return the trading record coming from the run
*/
public TradingRecord run(Strategy strategy, OrderType orderType) {
return run(strategy, orderType, NaN);
}
The standard value for this method is OrderType.BUY
. That means entry signals generated by your Strategy
will create a buying order and every exit signal will create a complementary (in this case OrderType.SELL
) order. If you change this parameter to OrderType.SELL
, the BarSeriesManager
will create selling orders for entry signals and buying orders for exit signals.
Strategy
with long (buy-sell) or with short (sell-buy) trades. There is no possibility to mix short and long trades in one and the same run done by the BarSeriesManager
.Num
or Function<Number, Num>
?With help of the Num
interface and a Function<Number, Num>
ta4j enables the use of different data types like Double
or BigDecimal
for storage and calculations. For further information take a look at the Num article.
Indicator
not match someone else’s values?If you are using an Indicator
that uses an exponential moving average (EMA) such as EMAIndicator
or RSIIndicator
then you will have to understand data length dependence and convergence. The short answer is that you need to “seed” your Indicator
with several hundred Bars
of data prior to the indices for which you seek the values or those values will have relatively large error.
Since EMA’s use the prior value in their calculation, the values depend on how many prior values you have. Related, there is some question as to how to initialize the first value of an EMA. The first problem is generally solved by including at least 200 Bars
of BarSeries
data prior to the indices for which you are interested. The second problem is currently solved by setting the first EMA value to the first data value:
@Override
protected Num calculate(int index) {
if (index == 0) {
return indicator.getValue(0);
}
}
If a different solution to initialization is required, then the EMAIndicator
may be extended to a subclass with a different solution to if (index == 0)
.
Note that due to the volume of questions of this nature, you are highly encourage to fully educate yourself on these issues prior to being engaged in a conversation about them.
Ta4j lives from your participation! For more information, take a look at the how to contribute section.