UNPKG

osr-quant

Version:

[![NPM](https://nodei.co/npm/osr-quant.png?mini=true)](https://nodei.co/npm/osr-quant/) ###How to use npm install osr-quant

40 lines 1.21 kB
/** * �����ָ��ƽ���ƶ�ƽ�� *�÷�:MEMA(X,N) *Y = MEMA(X,N); *Y = (X+(N-1)*Y')/N; * Created by Administrator on 2015/8/10. */ var mema = function (express, number, ext) { var key = this.getKey(express, number); if (!this.datas[key]) { this.datas[key] = []; } var _this = this; number = number || 5; return function (index) { if ("@@key" == index) { return key; } var index = index || _this.index; if (_this.datas[key][index]) { return _this.datas[key][index]; } var value = 0; var current = _this.kline[index]; var temp = 0; if ("function" == typeof(express)) { temp = express(index); } else if ("string" == typeof(express)) { temp = _this.getValue(express, current); } var _y = _this.datas[key][index - 1] || temp; value = (temp + ( number - 1 ) * _y ) / number; if(isNaN(value) || value == Infinity || value == -Infinity){ value = temp; } _this.datas[key][index] = parseFloat(value.toFixed(2)); return _this.datas[key][index]; } }; module.exports = mema;