Спасибо за ваш отчет. К сожалению, вы определенно правы. Это вызвано неправильной начальной точкой расчета значений od %d
. Я только что сообщил об этом в нашем репозитории GitHub. Вот ссылка на выпуск: https://github.com/highcharts/highcharts/issues/8965
Пока оно не будет исправлено, вы можете применить пользовательское исправление, которое отменяет функцию getValues
. Вот код:
(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/