UNPKG

pricehistory

Version:

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

35 lines 1.33 kB
import * as utilN from "@nameer/utils"; function setCandleEma(opt, candle, ctx) { var _a, _b; if (candle.priceClose === undefined) return; for (const period of opt.ema) { const winKey = `ema${period}`; (_a = ctx.window)[winKey] ?? (_a[winKey] = []); ctx.window[winKey].push(candle.priceClose); if (ctx.window[winKey].length > period) ctx.window[winKey].shift(); if (ctx.window[winKey].length < period) continue; (_b = ctx.ema)[period] ?? (_b[period] = {}); if (ctx.ema[period].initialized !== true) { const sma = utilN.math.mean(ctx.window[winKey]); if (sma === undefined) continue; candle[`ema${period}`] = utilN.math.num(sma); ctx.ema[period].prev = sma; ctx.ema[period].initialized = true; delete ctx.window[winKey]; continue; } if (ctx.ema[period].prev === undefined) continue; const multiplier = 2 / (period + 1); const ema = (candle.priceClose - ctx.ema[period].prev) * multiplier + ctx.ema[period].prev; candle[`ema${period}`] = utilN.math.num(ema); ctx.ema[period].prev = ema; } } export default setCandleEma; //# sourceMappingURL=candle.setEma.js.map