UNPKG

@sunrise1002/tats

Version:

Techincal Indicators written in javascript

61 lines (60 loc) 1.87 kB
import { Indicator } from '../indicator/indicator'; import { LinkedList } from '../Utils/LinkedList'; //STEP3. Add class based syntax with export export class WilderSmoothing extends Indicator { constructor(input) { super(input); this.period = input.period; this.price = input.values; var genFn = (function* (period) { var list = new LinkedList(); var sum = 0; var counter = 1; var current = yield; var result = 0; while (true) { if (counter < period) { counter++; sum = sum + current; result = undefined; } else if (counter == period) { counter++; sum = sum + current; result = sum; } else { result = result - (result / period) + current; } current = yield result; } }); this.generator = genFn(this.period); this.generator.next(); this.result = []; this.price.forEach((tick) => { var result = this.generator.next(tick); if (result.value != undefined) { this.result.push(this.format(result.value)); } }); } nextValue(price) { var result = this.generator.next(price).value; if (result != undefined) return this.format(result); } ; } WilderSmoothing.calculate = wildersmoothing; export function wildersmoothing(input) { Indicator.reverseInputs(input); var result = new WilderSmoothing(input).result; if (input.reversedInput) { result.reverse(); } Indicator.reverseInputs(input); return result; } ; //STEP 6. Run the tests