UNPKG

@neabyte/candlestick-cli

Version:

Beautiful terminal candlestick charts with real-time trading data. Create stunning ASCII art charts directly in your terminal with support for live market data, custom colors, and professional trading visualization.

143 lines (142 loc) 4.43 kB
/** * Technical indicators for candlestick charts * * Provides EMA (Exponential Moving Average) and SMA (Simple Moving Average) * calculations for trend analysis and overlay plotting. * * @example * ```typescript * import { calculateEMA, calculateSMA } from '../utils/indicators.js' * * const ema20 = calculateEMA(prices, 20) * const sma50 = calculateSMA(prices, 50) * ``` */ /** * Calculate Simple Moving Average (SMA) * * Computes the average of prices over a specified period. * Each value has equal weight in the calculation. * * @param prices - Array of closing prices * @param period - Number of periods for the moving average * @returns Array of SMA values (same length as input, with NaN for insufficient data) * * @example * ```typescript * const prices = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109] * const sma5 = calculateSMA(prices, 5) * // Result: [NaN, NaN, NaN, NaN, 102, 103, 104, 105, 106, 107] * ``` */ export declare function calculateSMA(prices: number[], period: number): number[]; /** * Calculate Exponential Moving Average (EMA) * * Computes the exponential moving average with more weight given to recent prices. * Uses the smoothing factor: 2 / (period + 1) * * @param prices - Array of closing prices * @param period - Number of periods for the moving average * @returns Array of EMA values (same length as input, with NaN for insufficient data) * * @example * ```typescript * const prices = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109] * const ema5 = calculateEMA(prices, 5) * // Result: [100, 100.5, 101.25, 102.125, 103.0625, 104.03125, ...] * ``` */ export declare function calculateEMA(prices: number[], period: number): number[]; /** * Calculate multiple EMAs for different periods * * Computes EMAs for multiple periods simultaneously for efficiency. * * @param prices - Array of closing prices * @param periods - Array of periods to calculate * @returns Object with period as key and EMA array as value * * @example * ```typescript * const prices = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109] * const emas = calculateMultipleEMAs(prices, [9, 21]) * // Result: { '9': [...], '21': [...] } * ``` */ export declare function calculateMultipleEMAs(prices: number[], periods: number[]): Record<string, number[]>; /** * Calculate multiple SMAs for different periods * * Computes SMAs for multiple periods simultaneously for efficiency. * * @param prices - Array of closing prices * @param periods - Array of periods to calculate * @returns Object with period as key and SMA array as value * * @example * ```typescript * const prices = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109] * const smas = calculateMultipleSMAs(prices, [20, 50]) * // Result: { '20': [...], '50': [...] } * ``` */ export declare function calculateMultipleSMAs(prices: number[], periods: number[]): Record<string, number[]>; /** * Validate indicator parameters * * Ensures prices array and period are valid for indicator calculations. * * @param prices - Array of closing prices * @param period - Number of periods * @throws Error if parameters are invalid * * @example * ```typescript * validateIndicatorParams(prices, 20) * ``` */ export declare function validateIndicatorParams(prices: number[], period: number): void; /** * Get closing prices from candles * * Extracts closing prices from candle data for indicator calculations. * * @param candles - Array of candle objects * @returns Array of closing prices * * @example * ```typescript * const prices = getClosingPrices(candles) * const ema20 = calculateEMA(prices, 20) * ``` */ export declare function getClosingPrices(candles: Array<{ close: number; }>): number[]; /** * Indicator configuration interface * * Defines configuration for technical indicators. */ export interface IndicatorConfig { /** Indicator type */ type: 'EMA' | 'SMA'; /** Period for calculation */ period: number; /** Color for the indicator line */ color?: [number, number, number]; /** Whether to show the indicator */ enabled?: boolean; } /** * Multiple indicators configuration * * Configuration for multiple indicators to be displayed simultaneously. */ export interface IndicatorsConfig { /** Array of indicator configurations */ indicators: IndicatorConfig[]; /** Whether to show indicators */ enabled?: boolean; }