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 complete() ? rsi() : Double.NaN; } // Do we have enough data for a proper value calculation? bool complete() { ret up != null && up.steps() >= length(); } { length = 25; onCandleAdded((IVF1) c -> { if (isNull(up())) init(); var x = c.move(); var u = max(x, 0.0); var d = neg(min(x, 0.0)); up().add(u); down().add(d); 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; } }