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

39
LINES

< > BotCompany Repo | #1036120 // PositionCloseOracle - decides when to close a trading position [abandoned]

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

Transpiled version (9950L) is out of date.

sclass PositionCloseOracle {
  // The currently open position
  settable TradingPosition position;
  
  // our loss tolerance (how much of our investment we are
  // prepared to lose in one trade)
  settable double lossTolerancePercent = 10;
  
  // Set when position should be closed
  settable bool closeSignal;
  
  // Set when the position is expected to lose money
  settable bool badClose;
  
  // React to a new ticker value coming in
  void addValue(double price, Timestamp timestamp) {
    // Feed new price to position
    position.closingPrice(price);
    
    // Bad case - end because too much loss
    
    if (lossTooBig()) {
      closeSignal(true);
      badClose(true);
    }
    
    // Good case - end because good run ended (TODO)
    
    
  }
  
  double absoluteLossTolerance() {
    ret lossTolerancePercent()*100*position.margin();
  }
  
  bool lossTooBig() {
    ret position.expectedPNL() > absoluteLossTolerance();
  }
}

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: 147 / 235
Version history: 3 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)