import { Average } from './average' ; description author shawn8901 example export class CCI { public static calculate ( periods , length , c = 0.015 ) { if ( periods . length <= length ) { return null ; } const [ period ] = periods ; const calcWindow = periods . slice ( 0 , length ) ; const tp = this . calculateTP ( period ) ; const tps = calcWindow . map ( ( curPeriod ) => this . calculateTP ( curPeriod ) ) ; const avgTp = Average . calculateValue ( tps , length ) ; const meanDev = Average . calculateValue ( tps . map ( ( curTp ) => Math . abs ( curTp - avgTp ) ) , length ) ; return ( tp - avgTp ) / ( c * meanDev ) ; } private static calculateTP ( { high , low , close } ) { return ( high + low + close ) / 3 ; } }