sclass G22CandleBasedStrategy extends G22TradingStrategy { settableWithVar double granularity = 1; // candle granularity in minutes settableWithVar TradingCandleMaker candleMaker; // first (usually partial) candle that will be ignored settableWithVar TradingCandle firstCandle; // Last completed candle settableWithVar TradingCandle completedCandle; // A candle has been completed event candleCompleted(TradingCandle candle); // For testing - feed candles directly void feed(Iterable candles) { fOr (candle : candles) try { candleCompleted(candle); } finally { afterStep(); } } // Normal operation from ticker void price(double price) { currentPrice = price; if (hasClosedItself()) ret; try { if (candleMaker == null) candleMaker(new TradingCandleMaker().candleLength(granularity)); var lastCompleted = candleMaker.completedCandle(); candleMaker.add(price, currentTime()); var candle = candleMaker.currentCandle(); if (firstCandle == null) firstCandle(candle); else if (candle != firstCandle) { var completed = completedCandle(); if (completed != lastCompleted) { completedCandle(completed); candleCompleted(completed); } } } finally { afterStep(); } } }