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


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

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
    // Bad case - end because too much loss
    if (lossTooBig()) {
    // 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 [dev.]
Eternal ID of this version: #1036120/3
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-09-22 18:47:29
Source code size: 988 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 6 / 21
Version history: 2 change(s)
Referenced in: [show references]