Warning: session_start(): open(/var/lib/php/sessions/sess_pob0roqgvfl8gql01p1id824kg, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
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);
event newPrice(double price);
// override me
L indicators() { ret new L; }
// For testing - feed candles directly
void feed(Iterable candles) {
fOr (candle : candles) try {
currentTime(candle.endTime.toLong());
gotCandle(candle);
} finally {
afterStep();
}
}
void gotCandle(TradingCandle candle) {
completedCandle(candle);
fOr (indicator : indicators())
indicator?.feed(candle);
candleCompleted(candle);
}
// Normal operation from ticker
void price(double price) {
currentPrice = price;
if (hasClosedItself()) ret;
newPrice(price);
//printVars("G22CandleBasedStrategy.price", +price);
try {
if (candleMaker == null)
candleMaker(new TradingCandleMaker().candleLength(granularity));
var completed = candleMaker.completedCandle();
candleMaker.add(price, currentTime());
var candle = candleMaker.currentCandle();
if (firstCandle == null)
firstCandle(candle);
else if (candle != firstCandle && completed != completedCandle())
gotCandle(completed);
} finally {
afterStep();
}
}
S fieldsToReset() {
ret lineCombine(super.fieldsToReset(), [[candleMaker firstCandle completedCandle]]);
}
L candles() { ret candleMaker().candles(); }
}