高库存随机%d不正确 [英] Highstock stochastic %d is not correct

查看:59
本文介绍了高库存随机%d不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将随机指标与14、3天移动平均线一起使用.结果%k是正确的,但%d不是.对于2018年9月14日的aapl,随机随机数为58.95和56.3.但是,highstock返回的值为44.8和56.3.在我的案例中,它所链接的系列是烛台图.数据包括以毫秒为单位的时间,开盘价,最高价,最低价和收盘价.

I am using the stochastic indicator with the 14, 3 day moving average. The resulting %k is correct, but the %d is not. For aapl on September 14, 2018, the stochastic fast is 58.95 and 56.3. However, the values returned by highstock is 44.8 and 56.3. The series it is linked to in my case is a candlestick chart. The data includes the time in milliseconds, the open, high, low and closing prices.

是否需要设置任何特殊参数以获得正确的%d?谢谢.

Are there any special parameters I need to set to get the correct %d? Thank you.

推荐答案

感谢您的报告.不幸的是,你绝对是正确的.这是由于计算值od %d的起点错误造成的.我刚刚在我们的GitHub存储库上报告了它.这是要发布的链接: https://github.com/highcharts/highcharts/issues/8965

Thank you for your report. Unfortunately, you're definitely right. It's caused by the wrong start point of calculating values od %d. I've just reported it on our GitHub repository. Here is the link to issue: https://github.com/highcharts/highcharts/issues/8965

在将其修复之前,您可以应用一个覆盖getValues功能的自定义修复程序.这是代码:

Until it will be fixed, you can apply a custom fix which overrides the getValues function. Here is the code:

(function(H) {
    var isArray = H.isArray,
    SMA = H.seriesTypes.sma,
    reduce = H.reduce,
    getArrayExtremes = function (arr, minIndex, maxIndex) {
        return reduce(arr, function (prev, target) {
            return [
                Math.min(prev[0], target[minIndex]),
                Math.max(prev[1], target[maxIndex])
            ];
        }, [Number.MAX_VALUE, -Number.MAX_VALUE]);
    };
  console.log(H.seriesTypes.stochastic.prototype)
    H.seriesTypes.stochastic.prototype.getValues = function(series, params) {
  var periodK = params.periods[0],
                periodD = params.periods[1],
                xVal = series.xData,
                yVal = series.yData,
                yValLen = yVal ? yVal.length : 0,
                SO = [], // 0- date, 1-%K, 2-%D
                xData = [],
                yData = [],
                slicedY,
                close = 3,
                low = 2,
                high = 1,
                CL, HL, LL, K,
                D = null,
                points,
                extremes,
                i;


            // Stochastic requires close value
            if (
                yValLen < periodK ||
                !isArray(yVal[0]) ||
                yVal[0].length !== 4
            ) {
                return false;
            }

            // For a N-period, we start from N-1 point, to calculate Nth point
            // That is why we later need to comprehend slice() elements list
            // with (+1)
            for (i = periodK - 1; i < yValLen; i++) {
                slicedY = yVal.slice(i - periodK + 1, i + 1);

                // Calculate %K
                extremes = getArrayExtremes(slicedY, low, high);
                LL = extremes[0]; // Lowest low in %K periods
                CL = yVal[i][close] - LL;
                HL = extremes[1] - LL;
                K = CL / HL * 100;

                xData.push(xVal[i]);
                yData.push([K, null]);

                // Calculate smoothed %D, which is SMA of %K
                if (i >= (periodK - 1) + (periodD - 1)) {
                    points = SMA.prototype.getValues.call(this, {
                        xData: xData.slice(-periodD),
                        yData: yData.slice(-periodD)
                    }, {
                        period: periodD
                    });
                    D = points.yData[0];
                }

                SO.push([xVal[i], K, D]);
                yData[yData.length - 1][1] = D;
            }

            return {
                values: SO,
                xData: xData,
                yData: yData
            };
  }
})(Highcharts)

实时示例: http://jsfiddle.net/d4hjmze1/

这篇关于高库存随机%d不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆