sclass BollingerBands { replace Candle with TradingCandle. new Welford welford; settable int length = 20; // Bollinger length (how many candles to look at) settable double deviation = 2; // result settable DoubleRange range; simplyCached CircularFifoBuffer candles() { ret new CircularFifoBuffer(length); } gettable AverageAndStandardDeviation as; Candle lastCandle() { ret candles().last(); } // add completed candles only void add(TradingCandle candle) { if (lastCandle() != null && candle.startTime <= lastCandle().startTime) ret; candles().removeToSize(length-1); candles().add(candle); if (l(candles) >= length) { var bCandles = takeLast(length, candles()); var prices = mapToDoubleArray(bCandles, ->.endPrice); as = averageAndStandardDeviation(prices); range = bollingerRange(as, deviation); } } }