UNPKG

turingtrader.js

Version:
69 lines (61 loc) 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IndicatorsTrend = void 0; var _ = require("."); //============================================================================== // Name: indicators/trend // Description: trend indicators. // History: FUB, 2021v07, created //============================================================================== var IndicatorsTrend = function IndicatorsTrend(sim, id0, promise0) { return { sma: function sma(length) { var id = "".concat(id0, ".sma(").concat(length, ")"); return sim.cache(id, function () { return (0, _.IndicatorsNum)(sim, id, promise0.then(function (data) { var b = []; var s = 0.0; return { t: data.t, x: data.x.map(function (v) { s += v; b.push(v); while (b.length > length) { s -= b[0]; b.shift(); } return s / b.length; }) }; }) // FIXME: catch here ); }); }, //---------------------------------------- ema: function ema(length) { var id = "".concat(id0, ".ema(").concat(length, ")"); return sim.cache(id, function () { return (0, _.IndicatorsNum)(sim, id, promise0.then(function (data) { var a = 2.0 / (length + 1.0); var x = data.x[0]; return { t: data.t, x: data.x.map(function (v) { return a * (v - x) + x; }) }; }) // FIXME: catch here ); }); } //---------------------------------------- // dema // tema // zlema // kama // macd }; }; //============================================================================== // end of file exports.IndicatorsTrend = IndicatorsTrend;