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)); } bool needNewCandle(long timestamp) { ret empty(candles) || timestamp >= currentCandle().startTime.plusSeconds(candleLength*60).unixDate(); } }