all files / chart/technical-indicators/ tma-indicator.js

100% Statements 61/61
91.3% Branches 21/23
100% Functions 12/12
100% Lines 58/58
11 statements, 6 functions, 9 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78          73×   72× 72× 72× 72× 72× 59× 59× 59× 59× 59× 59× 59× 59× 59× 2320× 2320× 2320× 6981×   2320× 2320× 2320×   59× 125× 125× 219×   125× 125×   59× 59× 2320× 2320× 6981×   2320× 2320× 2320×       72×     41750×        
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "../../common/utils/helper", "./indicator-base"], function (require, exports, helper_1, indicator_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var TmaIndicator = (function (_super) {
        __extends(TmaIndicator, _super);
        function TmaIndicator() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        TmaIndicator.prototype.initDataSource = function (indicator) {
            var tmaPoints = [];
            var field = helper_1.firstToLowerCase(indicator.field);
            var xField = 'x';
            var validData = indicator.points;
            if (validData && validData.length && validData.length >= indicator.period) {
                var signalSeries = indicator.targetSeries[0];
                var validData_1 = indicator.points;
                Eif (validData_1.length && validData_1.length >= indicator.period) {
                    var sum = 0;
                    var smaValues = [];
                    var index = 0;
                    var length_1 = validData_1.length;
                    var period = indicator.period;
                    while (length_1 >= period) {
                        sum = 0;
                        index = validData_1.length - length_1;
                        for (var j = index; j < index + period; j++) {
                            sum = sum + validData_1[j][field];
                        }
                        sum = sum / period;
                        smaValues.push(sum);
                        length_1--;
                    }
                    for (var k = 0; k < period - 1; k++) {
                        sum = 0;
                        for (var j = 0; j < k + 1; j++) {
                            sum = sum + validData_1[j][field];
                        }
                        sum = sum / (k + 1);
                        smaValues.splice(k, 0, sum);
                    }
                    index = indicator.period;
                    while (index <= smaValues.length) {
                        sum = 0;
                        for (var j = index - indicator.period; j < index; j++) {
                            sum = sum + smaValues[j];
                        }
                        sum = sum / indicator.period;
                        tmaPoints.push(this.getDataPoint(validData_1[index - 1][xField], sum, validData_1[index - 1], signalSeries, tmaPoints.length));
                        index++;
                    }
                }
            }
            this.setSeriesRange(tmaPoints, indicator);
        };
        TmaIndicator.prototype.destroy = function () {
        };
        TmaIndicator.prototype.getModuleName = function () {
            return 'TmaIndicator';
        };
        return TmaIndicator;
    }(indicator_base_1.TechnicalAnalysis));
    exports.TmaIndicator = TmaIndicator;
});