-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPATS.js
More file actions
97 lines (86 loc) · 2.73 KB
/
PATS.js
File metadata and controls
97 lines (86 loc) · 2.73 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// vim: syntax=pine
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 PATS {
init() {
}
map(d, i, history) {
const value = d.value();
const prior = history.prior();
const pprior = history.get(1);
if (!prior || !pprior) {
return;
}
const high = d.high();
const low = d.low();
const phigh = prior.high();
const plow = prior.low();
const open = d.open();
const popen = prior.open();
const close = d.close();
const pclose = prior.close();
const upbar = false
const downbar = false
const insidebar = false;
const outsidebar = false;
if (high < phigh && low > plow){ // INSIDE BAR
if (close > pclose && open > popen)
upbar = true;
else if (close < pclose && open < popen)
downbar = true;
else
insidebar = true;
}
else if (high > phigh && low < plow) { // OUTSIDE BAR
if (close > pclose && open > popen)
upbar = true;
else if (close > phigh || open > phigh)
upbar = true;
else if (close < pclose && open < popen)
downbar = true;
else if (close < plow || open < plow)
downbar = true;
else
outsidebar = true;
}
else if (high > phigh){ // HIGHER
upbar = true;
}
else if (low < plow){ // LOWER
downbar = true;
}
//else
// s.setPriceBarColor(index, WHITE);
const rtn = {
upbar,
downbar,
};
let candlestick;
if (upbar) { candlestick = { color: this.props.buyColor };
} else if (downbar) {
candlestick = { color: this.props.sellColor };
} else if (insidebar) {
candlestick = { color: this.props.insideColor };
} else if (outsidebar) {
candlestick = { color: this.props.outsidebar };
}
rtn["candlestick"] = candlestick;
return rtn;
}
}
module.exports = {
name: "PATS Trading System",
description: "PATS Trading System",
calculator: PATS,
inputType: meta.InputType.BARS,
tags: ['TraderOracle'],
params: {
buyColor: predef.paramSpecs.color("lime"),
sellColor: predef.paramSpecs.color("red"),
insideColor: predef.paramSpecs.color("yellow"),
outsideColor: predef.paramSpecs.color("blue"),
},
};