forked from syncfusion/ej2-javascript-ui-controls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmomentum-indicator.ts
81 lines (73 loc) · 2.76 KB
/
momentum-indicator.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* eslint-disable jsdoc/require-returns */
/* eslint-disable @typescript-eslint/no-inferrable-types */
/* eslint-disable valid-jsdoc */
/* eslint-disable jsdoc/require-param */
import { Series, Points } from '../series/chart-series';
import { TechnicalIndicator } from './technical-indicator';
import { TechnicalAnalysis } from './indicator-base';
import { Chart } from '../chart';
/**
* `MomentumIndicator` module is used to render Momentum indicator.
*/
export class MomentumIndicator extends TechnicalAnalysis {
/**
* Defines the collection of series to represent a momentum indicator
*
* @private
*/
public initSeriesCollection(indicator: TechnicalIndicator, chart: Chart): void {
super.initSeriesCollection(indicator, chart);
const upperLine: Series = new Series(indicator, 'targetSeries', {}, true);
super.setSeriesProperties(
upperLine, indicator, 'UpperLine', indicator.upperLine.color, indicator.upperLine.width, chart);
}
/**
* Defines the predictions using momentum approach
*
* @private
*/
public initDataSource(indicator: TechnicalIndicator, chart: Chart): void {
const upperCollection: Points[] = [];
const signalCollection: Points[] = [];
const validData: Points[] = indicator.points;
if (validData && validData.length) {
const upperSeries: Series = indicator.targetSeries[1];
const signalSeries: Series = indicator.targetSeries[0];
const length: number = indicator.period;
if (validData.length >= indicator.period) {
for (let i: number = 0; i < validData.length; i++) {
upperCollection.push(this.getDataPoint(
validData[i].x, 100, validData[i], upperSeries, upperCollection.length));
if (!(i < length)) {
signalCollection.push(this.getDataPoint(
validData[i].x,
(Number(validData[i].close) / Number(validData[i - length].close) * 100),
validData[i], signalSeries, signalCollection.length));
}
}
}
this.setSeriesRange(signalCollection, indicator, indicator.targetSeries[0]);
this.setSeriesRange(upperCollection, indicator, indicator.targetSeries[1]);
}
}
/**
* To destroy the momentum indicator
*
* @returns {void}
* @private
*/
public destroy(): void {
/**
* Destroys the momentum indicator
*/
}
/**
* Get module name.
*/
protected getModuleName(): string {
/**
* Returns the module name of the series
*/
return 'MomentumIndicator';
}
}