UNPKG

pricehistory

Version:

Transforms raw OHLCV series data into enriched candles with technical indicators, pattern recognition, and trend analysis.

102 lines 4.95 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const utilN = __importStar(require("@nameer/utils")); function setCandleCandlestick(opt, candle, ctx) { if (opt.candlestick !== true || candle.priceOpen === undefined || candle.priceHigh === undefined || candle.priceLow === undefined || candle.priceClose === undefined) { return; } const wickTop = candle.priceHigh; const bodyTop = Math.max(candle.priceOpen, candle.priceClose); const bodyBottom = Math.min(candle.priceOpen, candle.priceClose); const wickBottom = candle.priceLow; const size = candle.priceRange ?? utilN.math.change.num(wickBottom, wickTop); const upper = utilN.math.change.num(bodyTop, wickTop); const body = utilN.math.change.num(bodyBottom, bodyTop); const lower = utilN.math.change.num(wickBottom, bodyBottom); const isGapBody = opt.gap === "body"; candle.candlestickTop = isGapBody ? bodyTop : wickTop; candle.candlestickBottom = isGapBody ? bodyBottom : wickBottom; candle.candlestickSize = size; candle.candlestickUpper = utilN.math.percent(upper, size); candle.candlestickBody = utilN.math.percent(body, size); candle.candlestickLower = utilN.math.percent(lower, size); if (ctx.prevTopBottom.length === 2) { candle.candlestickIsGapUp = ctx.prevTopBottom[0] < candle.candlestickBottom; candle.candlestickIsGapDown = ctx.prevTopBottom[1] > candle.candlestickTop; if (candle.candlestickIsGapUp) { candle.candlestickGapSize = utilN.math.change.percent(ctx.prevTopBottom[0], candle.candlestickBottom); candle.candlestickGapTarget = ctx.prevTopBottom[0]; } else if (candle.candlestickIsGapDown) { candle.candlestickGapSize = utilN.math.change.percent(candle.candlestickTop, ctx.prevTopBottom[1]); candle.candlestickGapTarget = ctx.prevTopBottom[1]; } else { candle.candlestickGapSize = null; candle.candlestickGapTarget = null; } } candle.candlestickIsBullish = candle.priceClose > candle.priceOpen; candle.candlestickIsBearish = candle.priceClose < candle.priceOpen; candle.candlestickIsNeutral = candle.priceClose === candle.priceOpen; const candlestickUpper = candle.candlestickUpper ?? 0; const candlestickLower = candle.candlestickLower ?? 0; const candlestickBody = candle.candlestickBody ?? 0; candle.candlestickIsHammer = candlestickLower >= 50 && candlestickBody > candlestickUpper * 2; candle.candlestickIsHammerGreen = candle.candlestickIsHammer && candle.candlestickIsBullish; candle.candlestickIsInvertedHammer = candlestickUpper >= 50 && candlestickBody > candlestickLower * 2; candle.candlestickIsInvertedHammerRed = candle.candlestickIsInvertedHammer && candle.candlestickIsBearish; candle.candlestickIsMarubozu = candlestickBody >= 80; candle.candlestickIsMarubozuGreen = candle.candlestickIsMarubozu && candle.candlestickIsBullish; candle.candlestickIsMarubozuRed = candle.candlestickIsMarubozu && candle.candlestickIsBearish; candle.candlestickIsRejectionTop = candlestickUpper > candlestickLower * 2 && candlestickUpper >= 15; candle.candlestickIsRejectionBottom = candlestickLower > candlestickUpper * 2 && candlestickLower >= 15; ctx.prevTopBottom = [candle.candlestickTop, candle.candlestickBottom]; } exports.default = setCandleCandlestick; //# sourceMappingURL=candle.setCandlestick.js.map