sclass TradingCandleMaker { settable double candleLength = 1; // in minutes new L candles; TradingCandle currentCandle() { ret last(candles); } void add(double price, long timestamp) { if (needNewCandle(timestamp)) candles.add(new TradingCandle); var c = currentCandle(); c.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(); } }