⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 roc.java

📁 网上期货交易的外挂原码,可实现自动交易功能,自动添加模块
💻 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 + -