persistable sclass TradingCandleMaker { settable double candleLength = 1; // in minutes *(double *candleLength) {} new L candles; TradingCandle currentCandle() { ret last(candles); } void add(double price, long timestamp) { if (currentCandle() != null) currentCandle().addValue(price, new Timestamp(timestamp)); if (needNewCandle(timestamp)) { candles.add(new TradingCandle); currentCandle().addValue(price, new Timestamp(timestamp)); } } void addTickerSequence(TickerSequence ts) { int n = l(ts); for i to n: add(ts.prices.get(i), ts.timestamps.get(i)); } bool needNewCandle(long timestamp) { ret empty(candles) || timestamp >= currentCandle().startTime.plusSeconds(candleLength*60).unixDate(); } }