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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 62× 1× 63× 63× 63× 63× 62× 63× 63× 63× 63× 63× 63× 1× 62× 62× 62× 62× 62× 62× 62× 62× 62× 62× 62× 62× 50× 50× 50× 50× 50× 50× 50× 50× 50× 150× 50× 50× 2207× 2207× 2107× 2057× 2057× 2057× 2057× 2057× 2057× 50× 50× 50× 2107× 2107× 2107× 2107× 50× 100× 2107× 100× 100× 100× 100× 50× 50× 50× 2207× 2107× 2107× 2107× 2107× 2107× 2107× 2107× 2097× 62× 61× 62× 62× 62× 1× 1× 41750× 1× 1× | /* 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 BollingerBands = (function (_super) { __extends(BollingerBands, _super); function BollingerBands() { return _super !== null && _super.apply(this, arguments) || this; } BollingerBands.prototype.initSeriesCollection = function (indicator, chart) { indicator.targetSeries = []; var rangeArea = new chart_series_1.Series(indicator, 'targetSeries', {}, true); rangeArea.type = 'RangeArea'; if (indicator.bandColor !== 'transparent' && indicator.bandColor !== 'none') { this.setSeriesProperties(rangeArea, indicator, 'BollingerBand', indicator.bandColor, 0, chart); } var signalLine = new chart_series_1.Series(indicator, 'targetSeries', {}, true); this.setSeriesProperties(signalLine, indicator, 'BollingerBand', indicator.fill, indicator.width, chart); var upperLine = new chart_series_1.Series(indicator, 'targetSeries', {}, true); this.setSeriesProperties(upperLine, indicator, 'UpperLine', indicator.upperLine.color, indicator.upperLine.width, chart); var lowerLine = new chart_series_1.Series(indicator, 'targetSeries', {}, true); this.setSeriesProperties(lowerLine, indicator, 'LowerLine', indicator.lowerLine.color, indicator.lowerLine.width, chart); }; BollingerBands.prototype.initDataSource = function (indicator) { var enableBand = indicator.bandColor !== 'transparent' && indicator.bandColor !== 'none'; var start = enableBand ? 1 : 0; var signalCollection = []; var upperCollection = []; var lowerCollection = []; var bandCollection = []; var upperSeries = indicator.targetSeries[start + 1]; var lowerSeries = indicator.targetSeries[start + 2]; var signalSeries = indicator.targetSeries[start]; var rangeAreaSeries = enableBand ? indicator.targetSeries[0] : null; var validData = indicator.points; if (validData.length && validData.length >= indicator.period) { var sum = 0; var deviationSum = 0; var multiplier = indicator.standardDeviation; var limit = validData.length; var length_1 = Math.round(indicator.period); var smaPoints = []; var deviations = []; var bollingerPoints = []; for (var i_1 = 0; i_1 < length_1; i_1++) { sum += Number(validData[i_1].close); } var sma = sum / indicator.period; for (var i_2 = 0; i_2 < limit; i_2++) { var y = Number(validData[i_2].close); if (i_2 >= length_1 - 1 && i_2 < limit) { if (i_2 - indicator.period >= 0) { var diff = y - Number(validData[i_2 - length_1].close); sum = sum + diff; sma = sum / (indicator.period); smaPoints[i_2] = sma; deviations[i_2] = Math.pow(y - sma, 2); deviationSum += deviations[i_2] - deviations[i_2 - length_1]; } else { smaPoints[i_2] = sma; deviations[i_2] = Math.pow(y - sma, 2); deviationSum += deviations[i_2]; } var range = Math.sqrt(deviationSum / (indicator.period)); var lowerBand = smaPoints[i_2] - (multiplier * range); var upperBand = smaPoints[i_2] + (multiplier * range); if (i_2 + 1 === length_1) { for (var j_1 = 0; j_1 < length_1 - 1; j_1++) { bollingerPoints[j_1] = { 'X': validData[j_1].x, 'mb': smaPoints[i_2], 'lb': lowerBand, 'ub': upperBand, visible: true }; } } bollingerPoints[i_2] = { 'X': validData[i_2].x, 'mb': smaPoints[i_2], 'lb': lowerBand, 'ub': upperBand, visible: true }; } else { Eif (i_2 < indicator.period - 1) { smaPoints[i_2] = sma; deviations[i_2] = Math.pow(y - sma, 2); deviationSum += deviations[i_2]; } } } var i = -1; var j = -1; for (var k = 0; k < limit; k++) { if (k >= (length_1 - 1)) { var ub = 'ub'; var lb = 'lb'; var mb = 'mb'; upperCollection.push(this.getDataPoint(validData[k].x, bollingerPoints[k][ub], validData[k], upperSeries, upperCollection.length)); lowerCollection.push(this.getDataPoint(validData[k].x, bollingerPoints[k][lb], validData[k], lowerSeries, lowerCollection.length)); signalCollection.push(this.getDataPoint(validData[k].x, bollingerPoints[k][mb], validData[k], signalSeries, signalCollection.length)); if (enableBand) { bandCollection.push(this.getRangePoint(validData[k].x, upperCollection[++i].y, lowerCollection[++j].y, validData[k], rangeAreaSeries, bandCollection.length)); } } } } if (enableBand) { this.setSeriesRange(bandCollection, indicator, indicator.targetSeries[0]); } this.setSeriesRange(signalCollection, indicator, indicator.targetSeries[start]); this.setSeriesRange(upperCollection, indicator, indicator.targetSeries[start + 1]); this.setSeriesRange(lowerCollection, indicator, indicator.targetSeries[start + 2]); }; BollingerBands.prototype.destroy = function () { }; BollingerBands.prototype.getModuleName = function () { return 'BollingerBandsIndicator'; }; return BollingerBands; }(indicator_base_1.TechnicalAnalysis)); exports.BollingerBands = BollingerBands; }); |