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

100% Statements 43/43
95.45% Branches 21/22
100% Functions 13/13
100% Lines 40/40
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          68×   69× 69× 69×   67× 67× 67× 67× 56× 56× 56× 56× 54× 2333× 2333× 2164×       56× 56×       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", "../series/chart-series", "./indicator-base"], function (require, exports, chart_series_1, indicator_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var MomentumIndicator = (function (_super) {
        __extends(MomentumIndicator, _super);
        function MomentumIndicator() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        MomentumIndicator.prototype.initSeriesCollection = function (indicator, chart) {
            _super.prototype.initSeriesCollection.call(this, indicator, chart);
            var upperLine = new chart_series_1.Series(indicator, 'targetSeries', {}, true);
            _super.prototype.setSeriesProperties.call(this, upperLine, indicator, 'UpperLine', indicator.upperLine.color, indicator.upperLine.width, chart);
        };
        MomentumIndicator.prototype.initDataSource = function (indicator) {
            var upperCollection = [];
            var signalCollection = [];
            var validData = indicator.points;
            if (validData && validData.length) {
                var upperSeries = indicator.targetSeries[1];
                var signalSeries = indicator.targetSeries[0];
                var length_1 = indicator.period;
                if (validData.length >= indicator.period) {
                    for (var i = 0; i < validData.length; i++) {
                        upperCollection.push(this.getDataPoint(validData[i].x, 100, validData[i], upperSeries, upperCollection.length));
                        if (!(i < length_1)) {
                            signalCollection.push(this.getDataPoint(validData[i].x, (Number(validData[i].close) / Number(validData[i - length_1].close) * 100), validData[i], signalSeries, signalCollection.length));
                        }
                    }
                }
                this.setSeriesRange(signalCollection, indicator, indicator.targetSeries[0]);
                this.setSeriesRange(upperCollection, indicator, indicator.targetSeries[1]);
            }
        };
        MomentumIndicator.prototype.destroy = function () {
        };
        MomentumIndicator.prototype.getModuleName = function () {
            return 'MomentumIndicator';
        };
        return MomentumIndicator;
    }(indicator_base_1.TechnicalAnalysis));
    exports.MomentumIndicator = MomentumIndicator;
});