
代碼:
//獲取day日的移動平均值
function getEMA(data,day){
var arr = [];
arr.push(data[0]);
for(var i = 1;i < data.length;i++){
var a = 2/(day + 1);
//EMAtoday=α * Pricetoday + ( 1 - α ) * EMAyesterday;
//α為平滑指數,一般取作2/(N+1)。在計算MACD指標時,EMA計算中的N一般選取12和26天,因此α相應為2/13和2/27。
arr.push((1-a) * arr[i-1] + a* data[i]);
}
console.log(day+"天="+arr);
return arr;
}
//獲取diff的差值
function getDiff(DiffArr12,DiffArr26){
var arr = [];
for(var i = 0;i < DiffArr12.length;i++){
arr.push(DiffArr12[i] - DiffArr26[i]);
}
return arr;
}
v
