RSI Strategy is build to gain profit on buying / selling shares in a specific market conditions. RSI Strategy calculates two values:

  • Average gain - weighted average of gains
  • Average loss - weighted average of loses

This two values are used to compute a Relative Strength Index (RSI):

\text{RSI} = 100 - \frac{100}{1 + \frac{\text{avgGain}}{\text{avgLoss}}}

Moreover, there are two values given: overbought (normally around 70) and oversold (normally around 30) which are used in a process of making a decision if a strategy should sell or buy an asset.

Strategy settings

RSI Strategy parameters
OVERSOLD Level that crossing from the bottom causes a buy order
OVERBOUGHT Level that crossing from the top causes a buy order
LENGTH OF A STARTING PERIOD Number of trades that RSI Strategy needs to start

Case scenario

For case scenario RSI Strategy is set to default values and is executed on daily tick data.

RSI Example view

When the RSI crosses overbought line from the top then the strategy make a sell order. Similarly, when the RSI crosses a oversold line from the bottom then the strategy makes a buy order.

RSI Strategy statistics

As can be seen in strategy statistics, RSI Strategy brought net profit of $0.35.


RSI Strategy is composed of one trading action.

               .withQuantity((s) -> BigDecimal.ONE)))

Action when fired checks conditions if it should buy or sell shares in the moment (or does nothing). If condition is fulfilled then trading action makes order with proper side and price.

Additionally in the strategy instance there is a ON_TRADE consumer that is executed with every incoming trade.

private Consumer<TradeEvent> ON_TRADE = new Consumer<TradeEvent>() {
        public void accept(TradeEvent tradeEvent) {
            if (rsi.isReady() && rsi.doesPriceChanged())

With every trade strategy recalculates Relative Strength Index and when proper number of trades pass it starts triggering defined trading action.