forked from anandanand84/technicalindicators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinusDM.ts
65 lines (58 loc) · 1.58 KB
/
MinusDM.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Indicator, IndicatorInput } from '../indicator/indicator';
/**
* Created by AAravindan on 5/8/16.
*/
"use strict"
export class MDMInput extends IndicatorInput {
low:number[]
high:number[]
};
export class MDM extends Indicator {
result : number[];
generator:IterableIterator<number | undefined>;
constructor(input:MDMInput) {
super(input);
var lows = input.low
var highs = input.high;
var format = this.format;
if(lows.length != highs.length) {
throw ('Inputs(low,high) not of equal size');
}
this.result = [];
this.generator = (function* (){
var minusDm;
var current = yield;
var last;
while (true) {
if(last){
let upMove = (current.high - last.high)
let downMove = (last.low - current.low)
minusDm = format((downMove > upMove && downMove > 0) ? downMove : 0);
}
last = current;
current = yield minusDm;
}
})();
this.generator.next();
lows.forEach((tick, index) => {
var result = this.generator.next({
high : highs[index],
low : lows[index]
});
if(result.value !== undefined)
this.result.push(result.value);
});
};
static calculate(input:MDMInput):number[] {
Indicator.reverseInputs(input);
var result = new MDM(input).result;
if(input.reversedInput) {
result.reverse();
}
Indicator.reverseInputs(input);
return result;
};
nextValue(price:number):number | undefined {
return this.generator.next(price).value;
};
}