-
Notifications
You must be signed in to change notification settings - Fork 0
/
customRules_00005_EMA.js
103 lines (99 loc) · 3.98 KB
/
customRules_00005_EMA.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
92
93
94
95
96
97
98
99
100
101
102
103
var EMA_Fast = yield talib.exec({
name: 'SMA',
startIdx: 0,
endIdx: quotelength - 1,
inReal: closes,
optInTimePeriod:10
});
var EMA_Middle = yield talib.exec({
name: 'SMA',
startIdx: 0,
endIdx: quotelength - 1,
inReal: closes,
optInTimePeriod: 30
});
var EMA_Slow = yield talib.exec({
name: 'SMA',
startIdx: 0,
endIdx: quotelength - 1,
inReal: closes,
optInTimePeriod: 52
});
var MACD = yield talib.exec({
name: "MACD",
startIdx: 0,
endIdx: quotelength - 1,
inReal: closes,
optInFastPeriod: 12,
optInSlowPeriod: 26,
optInSignalPeriod: 9}
);
var RSI_9 = yield talib.exec({
name: "RSI",
startIdx: 0,
endIdx: quotelength - 1,
high: highs,
low: lows,
close: closes,
open: opens,
inReal: closes,
optInTimePeriod: 9
});
customHeaders["RSI_9"] = function(idx) {
return RSI_9["outReal"][idx];
};
customHeaders["EMA_fast"] = function(idx) {
return EMA_Fast["outReal"][idx];
};
customHeaders["EMA_Middle"] = function(idx) {
return EMA_Middle["outReal"][idx];
};
customHeaders["EMA_Slow"] = function(idx) {
return EMA_Slow["outReal"][idx];
};
buyrules["buy_MACD>MACD"] = function(idx, holdprice) {
if (EMA_Fast["outReal"][idx] != null)
{
if (
EMA_Slow["outReal"][idx-2] < EMA_Slow["outReal"][idx-1] &&
EMA_Slow["outReal"][idx-1] < EMA_Slow["outReal"][idx] &&
EMA_Fast["outReal"][idx] > EMA_Middle["outReal"][idx] &&
EMA_Fast["outReal"][idx-1] < EMA_Slow["outReal"][idx-1] &&
EMA_Fast["outReal"][idx] >= EMA_Slow["outReal"][idx] )
{
return true;
}else
{
return false;
}
}else
{
return false;
}
};
sellrules["win_3%"] = function(idx, holdprice) {
if (((highs[idx] - holdprice) / holdprice) >= 0.03) {
return true;
}
else {
return false;
}
};
sellrules["loss_2%"] = function(idx, holdprice) {
if (((highs[idx] - holdprice) / holdprice) <= -0.02) {
return true;
}
else {
return false;
}
};
sellrules["sell EMA_Middle<EMA_Slow"] = function(idx, holdprice) {
if (EMA_Fast["outReal"][idx] < EMA_Middle["outReal"][idx] &&
EMA_Middle["outReal"][idx-1] >= EMA_Slow["outReal"][idx-1] &&
EMA_Middle["outReal"][idx]< EMA_Slow["outReal"][idx] ) {
return true;
}
else {
return false;
}
};