从库存工具自定义指标

Costumize indicators from stock tools

我正在尝试实现一些技术指标系列并将它们添加到库存工具的指标弹出窗口中。如果我导入 highcharts/indicators/indicators-all 我最终会得到几十个指标,所以我想只导入我需要的那些,到目前为止我无法实现,如果我导入 highcharts/indicators/indicators 我最终会得到只有 SMA,我尝试通过 highcharts/indicators/indicators-INDICATOR-NAME 导入其他技术指标,但没有成功。

除此之外,我想创建一个技术 indicator/function,例如线性回归(来自 this 示例),并将它们也附加到指标弹出窗口。

function getLinearRegression(xData, yData) {
  var sumX = 0,
    sumY = 0,
    sumXY = 0,
    sumX2 = 0,
    linearData = [],
    linearXData = [],
    linearYData = [],
    n = xData.length,
    alpha,
    beta,
    i,
    x,
    y;

  // Get sums:
  for (i = 0; i < n; i++) {
    x = xData[i];
    y = yData[i];
    sumX += x;
    sumY += y;
    sumXY += x * y;
    sumX2 += x * x;
  }

  // Get slope and offset:
  alpha = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);
  if (isNaN(alpha)) {
    alpha = 0;
  }
  beta = (sumY - alpha * sumX) / n;

  // Calculate linear regression:
  for (i = 0; i < n; i++) {
    x = xData[i];
    y = alpha * x + beta;

    // Prepare arrays required for getValues() method
    linearData[i] = [x, y];
    linearXData[i] = x;
    linearYData[i] = y;
  }

  return {
    xData: linearXData,
    yData: linearYData,
    values: linearData
  };
}

这可能吗?

Live Demo


编辑

要添加特定技术指标,您应该添加为导入 highcharts/indicators/NAME(highcharts/indicators/emahighcharts/indicators/rsi 例如)

该功能未在库存工具中实现,但它可能非常有用,因此您可以在此处创建新功能请求:https://github.com/highcharts/highcharts/issues/new/choose

解决方法:

绘图选项中的所有指标系列都已添加到库存工具中,因此您可以自定义 chart.options.plotOptions,例如在 load 事件中:

chart: {
  events: {
    load: function() {
      var plotOptions = this.options.plotOptions,
        filteredSeries = {};

      Highcharts.objectEach(plotOptions, function(option, key) {
        if (!option.params || key === 'dema' || key === 'customlinearregression') {
          filteredSeries[key] = option;
        }
      });

      this.options.plotOptions = filteredSeries;
    }
  }
}

现场演示: https://jsfiddle.net/BlackLabel/xwec9hr7/2/

有用的例子:https://www.highcharts.com/stock/demo/stock-tools-custom-gui

代码参考:https://github.com/highcharts/highcharts/blob/371424be0b168de96aa6a58b81ce0b2b7f40d5c5/ts/annotations/popup.ts#L783