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

33
LINES

< > BotCompany Repo | #1036488 // ROCIndicator [rate of change, trading indicator]

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

Libraryless. Click here for Pure Java version (17534L/101K).

1  
persistable sclass ROCIndicator extends CandleBasedIndicator<Double> {
2  
  // ROC values collected as ticker
3  
  gettable TickerSequence rocHistory = new TickerSequence("ROC");
4  
  
5  
  // ATR value
6  
  settable double roc = Double.NaN;
7  
8  
  Double value() { ret roc(); }
9  
  
10  
  *(int *length) {}
11  
12  
  {
13  
    length = 10;
14  
    
15  
    onCandleAdded((IVF1<TradingCandle>) candle -> {
16  
      if (l(candles()) >= length) {
17  
        roc(asPercentIncrease(candle.close(), candles().first().close()));
18  
19  
        long time = candle.endTime().toLong();
20  
        rocHistory?.addIfPriceChanged(roc, time);
21  
      }
22  
    });
23  
  }
24  
  
25  
  TickerSequence asTicker(L<TradingCandle> candles) {
26  
    feed(candles);
27  
    ret rocHistory;
28  
  }
29  
  
30  
  void reset :: after {
31  
    resetFields(this, "roc rocHistory");
32  
  }
33  
}

Author comment

Began life as a copy of #1036469

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1036488
Snippet name: ROCIndicator [rate of change, trading indicator]
Eternal ID of this version: #1036488/4
Text MD5: c5780c08f7a0f075a0b4fea2727761f1
Transpilation MD5: 359dec07458f89292ac74027da45b530
Author: stefan
Category: javax / trading
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-12-18 03:41:52
Source code size: 796 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 152 / 224
Version history: 3 change(s)
Referenced in: [show references]