import { percentChange } from './utils' ; import { CircularBuffer } from './providers/circular-buffer' ; export class Move { private changes : CircularBuffer ; private prevPrice : number ; private value = 0 ; param period param period constructor ( private period ) { this . changes = new CircularBuffer ( period ) ; } nextValue ( close ) { if ( this . prevPrice ) { const change = percentChange ( close , this . prevPrice ) ; this . calculate ( change ) ; this . prevPrice = close ; return this . value ; } this . prevPrice = close ; } calculate ( change ) { this . value += change ; this . value -= this . changes . push ( change ) ; return this . value ; } }