sclass RSI extends CandleBasedIndicator { settable int smoothingPeriod; settable SmoothedMovingAverage up; settable SmoothedMovingAverage down; settable double rsi = Double.NaN; // RSI values collected as ticker gettable TickerSequence rsiHistory = new TickerSequence("RSI"); Double value() { ret rsi(); } // Do we have enough data for a proper value calculation? bool complete() { ret up != null && up.steps() >= length(); } { length = 25; onCandleAdded((IVF1) candle -> { if (isNull(up())) init(); var x = candle.move(); var u = max(x, 0.0); var d = neg(min(x, 0.0)); up().add(u); down().add(d); if (complete()) { var rs = div(up()!, down()!); rsi(100-100/(1+rs)); rsiHistory?.addIfPriceChanged(rsi, candle.endTime().toLong()); } }); } void init() { up = new SmoothedMovingAverage(this.length()); down = new SmoothedMovingAverage(this.length()); } TickerSequence asTicker(L candles) { feed(candles); ret rsiHistory; } }