Transpiled version (30652L) is out of date.
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<CandleBasedIndicator> indicators() { ret new L; } // For testing - feed candles directly void feed(Iterable<TradingCandle> 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 { createCandleMaker(); var completed = candleMaker.completedCandle(); candleMaker.add(price, currentTime()); /*var candle = candleMaker.currentCandle(); /if (firstCandle == null) firstCandle(candle); else if (candle != firstCandle && ... */ if (completed != completedCandle()) gotCandle(completed); } finally { afterStep(); } } S fieldsToReset() { ret lineCombine(super.fieldsToReset(), [[candleMaker firstCandle completedCandle]]); } L<TradingCandle> candles() { ret candleMaker().candles(); } // How many candles we need to see before the strategy can start making positions (override me) int candlesNeededBeforeOperational() { ret 0; } void createCandleMaker { if (candleMaker == null) candleMaker(new TradingCandleMaker().candleLength(granularity)); } }
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1036449 |
Snippet name: | G22CandleBasedStrategy |
Eternal ID of this version: | #1036449/28 |
Text MD5: | c2c3477ad99b3df6b9393eeff2e53136 |
Author: | stefan |
Category: | javax / trading |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2023-03-16 17:58:47 |
Source code size: | 2140 bytes / 72 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 87 / 216 |
Version history: | 27 change(s) |
Referenced in: | [show references] |