UNPKG

trading-signals

Version:

Technical indicators to run technical analysis with JavaScript / TypeScript.

45 lines (44 loc) 1.87 kB
type Nullable<Result> = Result | null; interface Indicator<Result = number, Input = number> { isStable: boolean; add(input: Input): Nullable<Result>; getRequiredInputs(): number; getResult(): Nullable<Result>; getResultOrThrow(): Result; replace(input: Input): Nullable<Result>; update(input: Input, replace: boolean): Nullable<Result>; updates(input: Input[], replace: boolean): Nullable<Result>[]; } export declare const TradingSignal: { readonly BEARISH: 'BEARISH'; readonly BULLISH: 'BULLISH'; readonly SIDEWAYS: 'SIDEWAYS'; readonly UNKNOWN: 'UNKNOWN'; }; export type TradingSignals = (typeof TradingSignal)[keyof typeof TradingSignal]; export declare abstract class TechnicalIndicator<Result, Input> implements Indicator<Result, Input> { protected result: Result | undefined; abstract getRequiredInputs(): number; getResult(): (Result & {}) | null; getResultOrThrow(): Result & ({} | null); get isStable(): boolean; add(input: Input): Result | null; replace(input: Input): Result | null; abstract update(input: Input, replace: boolean): Result | null; updates(inputs: readonly Input[], replace?: boolean): (Result | null)[]; } export declare abstract class IndicatorSeries<Input = number> extends TechnicalIndicator<number, Input> { protected previousResult?: number; protected setResult(value: number, replace: boolean): number; protected rollbackLastResult(): void; } export declare abstract class TrendIndicatorSeries<Input = number, SignalState = TradingSignals> extends IndicatorSeries<Input> { #private; protected abstract calculateSignalState(result?: number | null | undefined): SignalState; protected setResult(value: number, replace: boolean): number; getSignal(): { state: SignalState; hasChanged: boolean; }; } export {};