UNPKG

canvas-trading

Version:
102 lines (101 loc) 3.86 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var MountedIndicator = /** @class */ (function () { function MountedIndicator(type, value, yPos) { this.type = type; this.yPos = yPos; this.value = value; } return MountedIndicator; }()); export { MountedIndicator }; var MountedTrade = /** @class */ (function () { function MountedTrade(tradeType, profitable, yPos) { this.type = 'trade'; this.tradeType = tradeType; this.profitable = profitable; this.yPos = yPos; } return MountedTrade; }()); export { MountedTrade }; var CandleMountPoints = /** @class */ (function () { function CandleMountPoints(candleWidth, candleIndicators, trades, low, high, above) { this.above = []; this.below = []; this.mountIndicators(candleWidth, candleIndicators, trades, low, high, above); } CandleMountPoints.prototype.mountIndicators = function (candleWidth, indicators, trades, low, high, above) { var _this = this; // mount revBar if (indicators.revBar === 'sell') { this.mountUp('revBar', 'sell', candleWidth, high); } else if (indicators.revBar === 'buy') { this.mountDown('revBar', 'buy', candleWidth, low); } // mount fractal if (indicators.fractal === 'up') { this.mountUp('fractal', 'up', candleWidth, high); } else if (indicators.fractal === 'down') { this.mountDown('fractal', 'down', candleWidth, low); } // mount trade if both start and end are in this candle trades.forEach(function (trade) { var tradeID = trade.tradeID; var foundStart = !trade.isThisCandleEnd && trade.isThisCandleStart; var foundEnd = trades.find(function (trade) { return trade.tradeID === tradeID && trade.isThisCandleEnd && !trade.isThisCandleStart; }); if (foundStart && foundEnd) { var profit = trade.profit; if (above) _this.mountDown('trade', profit, candleWidth, low, trade.tradeType); else _this.mountUp('trade', profit, candleWidth, high, trade.tradeType); } }); }; CandleMountPoints.prototype.mountUp = function (type, value, candleWidth, high, tradeType) { var yGap = candleWidth; var retObj = { type: type, value: value, yPos: high - yGap * (1 + this.above.length), }; var isTrade = type === 'trade' && tradeType; this.above.push(isTrade ? __assign(__assign({}, retObj), { tradeType: tradeType, //? when its a trade, value is a number profitable: Number(value) > 0 }) : retObj); }; CandleMountPoints.prototype.mountDown = function (type, value, candleWidth, low, tradeType) { var yGap = candleWidth; var retObj = { type: type, value: value, yPos: low + yGap * (1 + this.below.length), }; var isTrade = type === 'trade' && tradeType; this.below.push(isTrade ? __assign(__assign({}, retObj), { tradeType: tradeType, //? when its a trade, value is a number profitable: Number(value) > 0 }) : retObj); }; return CandleMountPoints; }()); export { CandleMountPoints };