import { SMMA } from './smma' ; import { EMA } from './ema' ; import { WEMA } from './wema' ; import { LWMA } from './lwma' ; import { SMA } from './sma' ; import { EWMA } from './ewma' ; import { getTrueRange } from './providers/true-range' ; export class ATR { private prevClose : number ; private avg : EMA | SMMA | WEMA | LWMA | SMA | EWMA ; param period constructor ( period = 14 , smoothing = 'WEMA' ) { switch ( smoothing ) { case 'SMA' : this . avg = new SMA ( period ) ; break ; case 'EMA' : this . avg = new EMA ( period ) ; break ; case 'SMMA' : this . avg = new SMMA ( period ) ; break ; case 'WEMA' : this . avg = new WEMA ( period ) ; break ; case 'LWMA' : this . avg = new LWMA ( period ) ; break ; case 'EWMA' : this . avg = new EWMA ( 0.2 ) ; break ; } this . prevClose = 0 ; } nextValue ( high , low , close ) { const trueRange = getTrueRange ( high , low , this . prevClose ) ; this . prevClose = close ; if ( ! trueRange ) { return ; } return this . avg . nextValue ( trueRange ) ; } momentValue ( high , low ) { const trueRange = getTrueRange ( high , low , this . prevClose ) ; if ( ! trueRange ) { return ; } return this . avg . momentValue ( trueRange ) ; } }