-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathEngBB.js
More file actions
executable file
·76 lines (64 loc) · 2.37 KB
/
EngBB.js
File metadata and controls
executable file
·76 lines (64 loc) · 2.37 KB
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
const predef = require("./tools/predef");
const meta = require("./tools/meta");
const { ParamType } = meta;
const { px, du, op, min } = require("./tools/graphics");
const StdDev = require('./tools/StdDev');
class TOMethod {
init() {
this.stdDev = StdDev(20);
}
map(d, i, history) {
const prior = history.prior();
const pprior = history.get(1);
if (!prior || !pprior) {
return;
}
const stdev = this.stdDev(d.value());
const avg = this.stdDev.avg();
const halfWidth = stdev * 2;
const lowerBand = avg - halfWidth;
const upperBand = avg + halfWidth;
const c0Body = Math.abs(d.open() - d.close())
const c1Body = Math.abs(prior.open() - prior.close())
const c0G = d.close() > d.open();
const c0R = d.close() < d.open();
const c1G = prior.close() > prior.open();
const c1R = prior.close() < prior.open();
const inside = (d.high() >= upperBand || prior.high() >= upperBand) &&
(c0Body > c1Body) &&
(c0R && c1G) &&
(d.close() < prior.open() || d.close() == prior.open())
const outside = (d.low() <= lowerBand || prior.low() <= lowerBand) &&
(c0Body > c1Body) &&
(c0G && c1R) &&
(d.close() > prior.open() || d.close() == prior.open())
const rtn = {
inside,
outside,
};
let candlestick;
let color = "green";
if (inside) {
color = c0G ? this.props.insideColor : this.props.insideDownColor;
candlestick = { color: color };
} else if (outside) {
color = c0G ? this.props.outsideColor : this.props.outsideDownColor;
candlestick = { color: color };
}
rtn["candlestick"] = candlestick;
return rtn;
}
}
module.exports = {
name: "TO Method",
description: "TO - Method",
calculator: TOMethod,
inputType: meta.InputType.BARS,
tags: ['TraderOracle'],
params: {
insideColor: predef.paramSpecs.color("yellow"),
insideDownColor: predef.paramSpecs.color("yellow"),
outsideColor: predef.paramSpecs.color("pink"),
outsideDownColor: predef.paramSpecs.color("pink"),
},
};