|
请问如下的这种用精易的js脚本如何调用,如果传递二维数组。还是只能传文本之后返回也是文本返回?
var getMaxHighAndMinLow = function (ticks) {
var maxHigh = ticks[0][0], minLow = ticks[0][1];
for (var i = 0; i < ticks.length; i++) {
var t = ticks, high = t[0], low = t[1];
if (high > maxHigh) {
maxHigh = high;
}
if (low < minLow) {
minLow = low;
}
}
return [maxHigh, minLow];
};
/**
*
* @param {Array} ticks
* 二维数组类型,其中内层数组包含三个元素值,第一个值表示当前Tick的最高价格,第二个表示当前Tick的最低价格,第三个表示当前Tick的收盘价格
* @Return {Object} 返回一个包含k d j属性的对象,每个属性对应的类型为{Array[Number]}
*/
var kdj = function (ticks) {
var nineDaysTicks = [], days = 9, rsvs = [];
var ks = [], ds = [], js = [];
var lastK, lastD, curK, curD;
var maxAndMin, max, min;
for (var i = 0; i < ticks.length; i++) {
var t = ticks, close = t[2];
nineDaysTicks.push(t);
maxAndMin = getMaxHighAndMinLow(nineDaysTicks);
max = maxAndMin[0];
min = maxAndMin[1];
if (max == min) {
rsvs.push(0);
} else {
rsvs.push((close - min) / (max - min) * 100);
}
if (nineDaysTicks.length == days) {
nineDaysTicks.shift();
}
if (i == 0) {
lastK = lastD = rsvs;
}
curK = 2 / 3 * lastK + 1 / 3 * rsvs;
ks.push(curK);
lastK = curK;
curD = 2 / 3 * lastD + 1 / 3 * curK;
ds.push(curD);
lastD = curD;
js.push(3 * curK - 2 * curD);
}
return {"k": ks, "d": ds, "j": js};
};
|
|