Warning: session_start(): open(/var/lib/php/sessions/sess_o7e1cvgi31335kos4e3dr3m2g7, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
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;
}
}