1 | concept JuiceStrategy extends G22TradingStrategy { |
2 | settableWithVar AbstractJuicer prototypeJuicer; |
3 | |
4 | persistable class Position extends G22TradingStrategy.Position { |
5 | settable AbstractJuicer juicer; |
6 | } |
7 | |
8 | selfType emptyClone() { |
9 | JuiceStrategy clone = cast super.emptyClone(); |
10 | clone.prototypeJuicer(prototypeJuicer?.configClone()); |
11 | ret clone; |
12 | } |
13 | |
14 | void price(double price) { |
15 | if (currentPrice == price) ret; |
16 | currentPrice = price; |
17 | afterwards { change(); } |
18 | |
19 | for (p : openPositions()) { |
20 | cast p to Position; |
21 | |
22 | if (p.juicer != null) { |
23 | var signals = p.juicer.calculateCloseSignals(); |
24 | var strongest = highestBy(signals, s -> s.strength()); |
25 | if (strongest != null && strongest.isTrigger()) { |
26 | p.close(strongest); |
27 | } |
28 | } |
29 | } |
30 | } |
31 | |
32 | Position openShort() { ret openPosition(-1); } |
33 | Position openLong() { ret openPosition(1); } |
34 | |
35 | Position openPosition(int direction) { |
36 | new Position p; |
37 | p.marginToUse = marginPerPosition; |
38 | p.juicer(makeJuicer()); |
39 | ret openPosition(p, direction); |
40 | } |
41 | |
42 | swappable AbstractJuicer makeJuicer() { |
43 | ret new StopLossJuicer; |
44 | } |
45 | } |
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: | 112 / 125 |
Referenced in: | [show references] |