Create your strategy

Your strategy is in src/main/java/com/example/SimpleTa4jStrategy.java

Choose the requested currency pair.

This is done by implementing getRequestedCurrencyPair() this way :

@Override
public CurrencyPairDTO getRequestedCurrencyPair() {
return new CurrencyPairDTO(BTC, USDT);
}

Choose your trading account.

On the exchange, you usually have several accounts and Cassandre needs to know which one of your account is the trading one (for example, to calculate if you have enough assets to buy/sell). So the following method gives you as a parameter the list of accounts and you have to return the trading one :

@Override
public Optional<AccountDTO> getTradeAccount(Set<AccountDTO> accounts) {
return accounts.stream()
.filter(a -> "trade".equals(a.getName()))
.findFirst();
}

Choose the number of bars.

This is done by implementing getMaximumBarCount() this way :

@Override
public int getMaximumBarCount() {
return 10;
}

Choose the delay between two bars.

This is done by implementing getDelayBetweenTwoBars() this way :

@Override
public Duration getDelayBetweenTwoBars() {
return Duration.ofDays(1);
}

This method allows you, for example, to receive tickers every second, but only add one to the bar every day.

Create your strategy.

Now it's time to implement your own strategy, here, we chose Simple Moving Average (SMA) :

@Override
public Strategy getStrategy() {
ClosePriceIndicator closePrice = new ClosePriceIndicator(getSeries());
SMAIndicator sma = new SMAIndicator(closePrice, getMaximumBarCount());
return new BaseStrategy(new UnderIndicatorRule(sma, closePrice), new OverIndicatorRule(sma, closePrice));
}