-
Notifications
You must be signed in to change notification settings - Fork 41
/
ichimokuCloud.src.js
91 lines (84 loc) · 2.9 KB
/
ichimokuCloud.src.js
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
82
83
84
85
86
87
88
89
90
91
function getBufferSize (conversionLinePeriods, baseLinePeriods, leadingSpanPeriods) {
return Math.max(conversionLinePeriods, baseLinePeriods, leadingSpanPeriods);
}
function validate (conversionLinePeriods, baseLinePeriods, leadingSpanPeriods, laggingSpanPeriods) {
validateField("conversionLinePeriods", conversionLinePeriods);
validateField("baseLinePeriods", baseLinePeriods);
validateField("leadingSpanPeriods", leadingSpanPeriods);
validateField("laggingSpanPeriods", laggingSpanPeriods);
}
function validateField (fieldName, value) {
if (typeof value !== "number") {
error("Ichimoku Cloud " + fieldName + " must be a number");
}
if (value % 1 !== 0) {
error("Ichimoku Cloud " + fieldName + " must be an integer");
}
if (value <= 0) {
error("Ichimoku Cloud " + fieldName + " must be an integer");
}
if (value > 100) {
error("Ichimoku Cloud " + fieldName + " maximum value is 100");
}
}
function onIntervalClose (conversionLinePeriods, baseLinePeriods, leadingSpanPeriods, laggingSpanPeriods) {
var conversionLineCloses = prices(conversionLinePeriods),
baseLineCloses = prices(baseLinePeriods),
leadingSpanBCloses = prices(leadingSpanPeriods),
conversionLine,
baseLine,
spanALine,
spanBLine,
greenCloud,
redCloud;
conversionLine = (Math.highest(conversionLineCloses) + Math.lowest(conversionLineCloses)) / 2;
baseLine = (Math.highest(baseLineCloses) + Math.lowest(baseLineCloses)) / 2;
spanALine = (conversionLine + baseLine) / 2;
spanBLine = (Math.highest(leadingSpanBCloses) + Math.lowest(leadingSpanBCloses)) / 2;
if (spanALine > spanBLine) {
greenCloud = [spanALine, spanBLine];
redCloud = [spanBLine, spanBLine];
} else {
greenCloud = [spanALine, spanALine];
redCloud = [spanALine, spanBLine];
}
return [{
name: "Ichimoku Tenkan-sen (Conversion Line)",
value: conversionLine
}, {
name: "Ichimoku Kijun-sen (Base Line)",
value: baseLine
}, {
name: "Ichimoku Senkou Span A (Leading Span A)",
color: "#90ed7d",
plotOffset: baseLinePeriods,
value: spanALine
}, {
name: "Ichimoku Senkou Span B (Leading Span B)",
color: "#f15c80",
plotOffset: baseLinePeriods,
value: spanBLine
}, {
name: "Ichimoku Chikou Span (Lagging Span)",
plotOffset: -laggingSpanPeriods,
value: CLOSE
}, {
color: "#90ed7d",
lineWidth: 0,
plotOffset: baseLinePeriods,
value: greenCloud,
tooltip: {
headerFormat: "",
pointFormat: ""
}
}, {
color: "#f15c80",
lineWidth: 0,
plotOffset: baseLinePeriods,
value: redCloud,
tooltip: {
headerFormat: "",
pointFormat: ""
}
}];
}