sclass RSI extends CandleBasedIndicator<Double> { 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<TradingCandle>) 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<TradingCandle> candles) { feed(candles); ret rsiHistory; } }
Began life as a copy of #1036452
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1036460 |
| Snippet name: | RSI backup [trading indicator, probably wrong formula] |
| Eternal ID of this version: | #1036460/1 |
| Text MD5: | bc6e51c5180d041727212fca595a732f |
| Author: | stefan |
| Category: | javax / trading |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-12-16 02:04:55 |
| Source code size: | 1153 bytes / 43 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 395 / 408 |
| Referenced in: | -