📄 roc.java
字号:
package com.jsystemtrader.indicator;
import com.jsystemtrader.platform.*;
/**
* Rate of Price Change.
*/
public class ROC extends Indicator {
private final int lookBackLength;
public ROC(long time, QuoteHistory qh, int lookBackLength) {
super(time, qh);
this.lookBackLength = lookBackLength;
}
public double calculate() throws IndicatorCalculationException {
int thenBar = qh.size() - 1 - lookBackLength;
if (thenBar < 0) {
String msg = "Quote history length " + qh.size() + " is insufficient to calculate the indicator.";
throw new IndicatorCalculationException(msg);
}
double priceNow = qh.getLastPriceBar().getClose();
double priceThen = qh.getPriceBar(thenBar).getClose();
double rateOfChange = ( (priceNow - priceThen) / priceThen) * 100;
value = rateOfChange;
return value;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -