Libraryless. Click here for Pure Java version (15695L/93K).
persistable sclass MultiStopLossJuicer extends AbstractJuicer { // Must have at least one level, otherwise no closing at all sclass Level { // At juice value minJuiceValue, define the stopLoss. settable double minJuiceValue; settable double stopLoss; toString { ret "Stop loss " + stopLoss + "% starting at " + formatDouble2(minJuiceValue); } } settableWithVar new L<Level> levels; // Highest juice value seen settableWithVar double crest = -infinity(); // for current level, set by MultiStopLossJuicer itself settableWithVar StopLossJuicer stopLossJuicer; settableWithVar int levelsTriggered; Level nextLevel() { ret _get(levels, levelsTriggered); } { onCalculatingCloseSignals(signals -> { if (juiceValue > crest) crest(juiceValue); Level level; while ((level = nextLevel()) != null && crest >= level.minJuiceValue) { levelsTriggered(levelsTriggered+1); var slj = new StopLossJuicer(level.stopLoss); slj.juiceable(juiceable()); stopLossJuicer(slj); } if (stopLossJuicer != null) addAll(signals, stopLossJuicer.calculateCloseSignals()); }); } void addLevel(double minJuiceValue, double stopLoss) { levels.add(new Level().+minJuiceValue.+stopLoss); } toString { ret commaCombine( shortClassName(this), levels, crest == -infinity() ? null : "Highest profit seen: " + formatDouble2(crest), "Levels triggered: " + levelsTriggered, "Current stop loss: " + stopLossJuicer, ); } // Hmm. Is this correct? void copyTransientValuesFrom(AbstractJuicer juicer) { if (juicer cast MultiStopLossJuicer) crest(juicer.crest); } }
Began life as a copy of #1036534
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj
No comments. add comment
Snippet ID: | #1036611 |
Snippet name: | MultiStopLossJuicer - even simpler version of MultiCallbackJuicer with fixed thresholds & stop loss levels |
Eternal ID of this version: | #1036611/4 |
Text MD5: | 4399043d5be4800f48d0eb617f702031 |
Transpilation MD5: | 5505ccce76d0fc47311c7f271a1cd387 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2023-04-29 00:13:22 |
Source code size: | 1812 bytes / 61 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 179 / 239 |
Version history: | 3 change(s) |
Referenced in: | #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167) |