-
Notifications
You must be signed in to change notification settings - Fork 3
/
RSI.lua
67 lines (42 loc) · 1002 Bytes
/
RSI.lua
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
require "IndexLibrary"
-- RSI 指标
-- @param list K线数组
-- @param getMethod 计算字段
-- @param param {6, 12, 24}
function RSIIndex(aryList, getMethod, param)
mabArray = {}
risArray = {}
funcREF = REF(getMethod, 1, aryList)
for i = 1, #aryList, 1 do
mabArray[i] = {max = math.max(aryList[i][getMethod] - funcREF(i), 0), abs = math.abs(aryList[i][getMethod] - funcREF(i))}
end
for i = 1, #param, 1 do
number = param[i]
aryRsiN = {}
funcSMAMax = SMA("max", number, 1, mabArray)
funcSMAAbs = SMA("abs", number, 1, mabArray)
for j = 1, #aryList, 1 do
t = funcSMAMax(j)
b = funcSMAAbs(j)
if b == 0 then
b = 1
end
aryRsiN[j] = t / b * 100
end
risArray[i] = aryRsiN
end
titles = {}
for i = 1, #param, 1 do
titles[i] = "RSI"..param[i];
end
aryIndex = {}
for i = 1, #aryList, 1 do
rsi = {}
for j = 1, #titles, 1 do
aryRsiN = risArray[j]
rsi[titles[j]] = aryRsiN[i]
end
aryIndex[i] = rsi
end
return aryIndex
end