Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

31
LINES

< > BotCompany Repo | #1036355 // StopLossJuicer - simple juicer that closes when juice level goes below a threshold

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (15571L/92K).

1  
persistable sclass StopLossJuicer extends AbstractJuicer {
2  
  // How much loss we will accept
3  
  // Can be positive (stop loss in profit) or negative (stop loss with actual loss)
4  
  settable double stopLossLimit = -0.5;
5  
  
6  
  settable bool stopLossEnabled = true;
7  
  
8  
  // Reference threshold to calculate signal below 100%
9  
  // (doesn't impact closing behavior)
10  
  settable double startStopLossSignalAt;
11  
  
12  
  *(double *stopLossLimit) {}
13  
  
14  
  {
15  
    onCalculatingCloseSignals(signals -> {
16  
      // How close are we to our loss limit?
17  
      if (stopLossEnabled && stopLossLimit > -infinity()) {
18  
        var signal = new CloseSignal().createdBy(this).reason("Stop loss");
19  
        if (juiceValue <= stopLossLimit)
20  
          signal.strength(100);
21  
        else {
22  
          double startAt = max(startStopLossSignalAt, 0);
23  
          if (startAt > stopLossLimit)
24  
            signal.strength(doubleRatio(startAt-juiceValue, startAt-stopLossLimit)*100);
25  
        }
26  
        
27  
        signals.add(signal);
28  
      }
29  
    });
30  
  }
31  
}

Author comment

Began life as a copy of #1036353

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1036355
Snippet name: StopLossJuicer - simple juicer that closes when juice level goes below a threshold
Eternal ID of this version: #1036355/21
Text MD5: 6751fdc784b768e95a6a89645365a3df
Transpilation MD5: 8211a2db8a2551f4ba3955630c556ffc
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:40
Source code size: 1038 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 130 / 279
Version history: 20 change(s)
Referenced in: [show references]