-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTD.lua
More file actions
125 lines (96 loc) · 2.68 KB
/
Copy pathTD.lua
File metadata and controls
125 lines (96 loc) · 2.68 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
require "IndexLibrary"
-- TD指标
-- @param aryList k线
-- @param getMethodLow 最高价字段
-- @param getMethodClose 收盘价
-- @param param 9
-- @return {"dir" : 1 - 9, 向上九转, -1 - -9, 向下, "arrow" : 1, 0, -1}
function TDIndex(aryList, getMethodLow, getMethodClose, getMethodHigh, param)
upNo = 0
upStart = 0
downNo = 0
downStart = 0
local funcRef1 = REF(getMethodClose, 1, aryList)
local funcRef4 = REF(getMethodClose, 4, aryList)
local funcRef5 = REF(getMethodClose, 5, aryList)
local aryTDs = {}
for i = 1, #aryList, 1 do
local td = {}
-- 向上
if (aryList[i][getMethodClose] > funcRef4(i) and funcRef1(i) <= funcRef5(i)) then
upNo = 1
upStart = 1
downStart = 0
elseif (upStart and upNo < param) then
upNo = upNo + 1
elseif (upStart and upNo == param) then
upNo = 0
end
if (aryList[i][getMethodClose] < funcRef4(i)) then
upNo = 0
upStart = 0
end
-- 向下
if (aryList[i][getMethodClose] < funcRef4(i) and funcRef1(i) >= funcRef5(i)) then
downStart = 1
downNo = 1
upStart = 0
elseif (downStart == 1 and downNo < param) then
downNo = downNo + 1
elseif (downStart == 1 and downNo == param) then
downNo = 0
end
if (aryList[i][getMethodClose] > funcRef4(i)) then
downNo = 0
downStart = 0
end
td["upNo"] = upNo
td["downNo"] = downNo
aryTDs[i] = td
end
-- 过滤
local funcLowRef1 = REF(getMethodLow, 1, aryList)
local funcHighRef1 = REF(getMethodHigh, 1, aryList)
local upParam = false
local downParam = false
for i = 1, #aryTDs, 1 do
aryTDs[i]["dir"] = 0
aryTDs[i]["arrow"] = 0
-- 红色箭头
if (upParam and (aryList[i][getMethodClose] > funcRef1(i))) then
aryTDs[i]["arrow"] = -1
upParam = false
end
-- 绿色箭头
if (downParam and (aryList[i][getMethodClose] < funcRef1(i))) then
aryTDs[i]["arrow"] = 1
downParam = false
end
if (aryTDs[i]["upNo"] == param) then
if (aryList[i][getMethodClose] > funcLowRef1(i)) then
aryTDs[i]["arrow"] = -1
else
upParam = true
end
updateNumber(aryTDs, param, "dir", i)
end
if (aryTDs[i]["downNo"] == param) then
if (aryList[i][getMethodClose] < funcHighRef1(i)) then
aryTDs[i]["arrow"] = 1
else
downParam = true
end
updateNumber(aryTDs, -param, "dir", i)
end
end
return aryTDs
end
function updateNumber(aryList, param, setMethod, index)
count = math.abs(param)
base = param >= 0 and -1 or 1
for i = 1, count, 1 do
aryList[index][setMethod] = param
index = index - 1
param = param + base
end
end