concept JuiceStrategy extends G22TradingStrategy { settableWithVar AbstractJuicer prototypeJuicer; persistable class Position extends G22TradingStrategy.Position { settable AbstractJuicer juicer; } selfType emptyClone() { JuiceStrategy clone = cast super.emptyClone(); clone.prototypeJuicer(prototypeJuicer?.configClone()); ret clone; } void price(double price) { if (currentPrice == price) ret; currentPrice = price; afterwards { change(); } for (p : openPositions()) { cast p to Position; if (p.juicer != null) { var signals = p.juicer.calculateCloseSignals(); var strongest = highestBy(signals, s -> s.strength()); if (strongest != null && strongest.isTrigger()) { p.close(strongest); } } } } Position openShort() { ret openPosition(-1); } Position openLong() { ret openPosition(1); } Position openPosition(int direction) { new Position p; p.marginToUse = marginPerPosition; p.juicer(makeJuicer()); ret openPosition(p, direction); } swappable AbstractJuicer makeJuicer() { ret new StopLossJuicer; } }
Began life as a copy of #1036351
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1036357 |
Snippet name: | JuiceStrategy with prototypeJuicer (old) |
Eternal ID of this version: | #1036357/1 |
Text MD5: | 504bf073f00cd9b65384b18e37b088c7 |
Author: | stefan |
Category: | javax / gazelle 22 |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-11-23 19:33:38 |
Source code size: | 1219 bytes / 45 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 111 / 123 |
Referenced in: | -