Transpiled version (9950L) is out of date.
1 | sclass PositionCloseOracle { |
2 | // The currently open position |
3 | settable TradingPosition position; |
4 | |
5 | // our loss tolerance (how much of our investment we are |
6 | // prepared to lose in one trade) |
7 | settable double lossTolerancePercent = 10; |
8 | |
9 | // Set when position should be closed |
10 | settable bool closeSignal; |
11 | |
12 | // Set when the position is expected to lose money |
13 | settable bool badClose; |
14 | |
15 | // React to a new ticker value coming in |
16 | void addValue(double price, Timestamp timestamp) { |
17 | // Feed new price to position |
18 | position.closingPrice(price); |
19 | |
20 | // Bad case - end because too much loss |
21 | |
22 | if (lossTooBig()) { |
23 | closeSignal(true); |
24 | badClose(true); |
25 | } |
26 | |
27 | // Good case - end because good run ended (TODO) |
28 | |
29 | |
30 | } |
31 | |
32 | double absoluteLossTolerance() { |
33 | ret lossTolerancePercent()*100*position.margin(); |
34 | } |
35 | |
36 | bool lossTooBig() { |
37 | ret position.expectedPNL() > absoluteLossTolerance(); |
38 | } |
39 | } |
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1036120 |
Snippet name: | PositionCloseOracle - decides when to close a trading position [abandoned] |
Eternal ID of this version: | #1036120/4 |
Text MD5: | 8c6e12dc67ab2e565c9f26a54d034305 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-11-07 12:16:17 |
Source code size: | 988 bytes / 39 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 148 / 237 |
Version history: | 3 change(s) |
Referenced in: | [show references] |