# RSIStrategy¶

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):

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¶

 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.

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.

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

## Development¶

RSI Strategy is composed of one trading action.

action(tradingAction
.condition(TRADE_SIGNAL)
.actionType(TradingActionType.NEW_ORDER)
.createOrderWith(orderBuilder
.withSymbol(marketSymbol)
.side(SIDE)
.withPriceLimit(PRICE)
.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>() {
@Override
public void accept(TradeEvent tradeEvent) {
rsi.add(tradeEvent.getPrice());
if (rsi.isReady() && rsi.doesPriceChanged())
triggerTradingActions(tradeEvent.getMarketSymbol());
}
};


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