@4ex/indicators
Version:
Technical indicators for ohlc charts written in TypeScript
55 lines (54 loc) • 2.35 kB
TypeScript
import { EMA as EMAIndicator, SMA as SMAIndicator, WEMA as WEMAIndicator, WMA as WMAIndicator } from 'technicalindicators';
import { MovingAverageEnum, OHLC, OHLCEnum } from '../types';
import { Indicator, IndicatorInput } from './base-indicator';
export interface MovingAverageInput extends IndicatorInput {
period: number;
source?: OHLCEnum;
method?: MovingAverageEnum;
}
/**
* In statistics, a moving average is a calculation used to analyze data points
* by creating a series of averages of different subsets of the full data set.
* In finance, a moving average (MA) is a stock indicator that is commonly used
* in technical analysis. The reason for calculating the moving average of a
* stock is to help smooth out the price data by creating a constantly updated
* average price.
* [Investopedia](https://www.investopedia.com/terms/m/movingaverage.asp)
*/
export declare class MA implements Indicator {
indicator: SMAIndicator | EMAIndicator | WMAIndicator | WEMAIndicator;
source: OHLCEnum;
method: MovingAverageEnum;
/**
* Create a new instance for Moving Average
* @param {number} period number of period to calculate moving average
* @param {OHLC[]} series series of candle
* @param {OHLCEnum} source source of calculation
* @param {MovingAverageEnum} method type of moving average calculation
*/
constructor(period: number, series?: OHLC[], source?: OHLCEnum, method?: MovingAverageEnum);
/**
* Calculate Moving Average from object
* @param {MovingAverageInput} input input data for calculation
* @return {number[]} array of MAs based on input
*/
static calculate(input: MovingAverageInput): number[];
/**
* Generate instance of MA indicator
* @param {MovingAverageInput} input object with input for MA
* @return {MA} instance of indicator
*/
static generator({ series, source, method, period, }: MovingAverageInput): MA;
/**
* Calculate moving average for next tick
* @param {OHLC} candle price candle
* @return {number} next ma value or undefined if period is greater
* than actual series length
*/
next(candle: OHLC): number | undefined;
/**
* Same as calculate bat for instance data
* @return {number[]} moving average.
*/
getResults(): number[];
}