-
Notifications
You must be signed in to change notification settings - Fork 64
/
WaveTrend.lua
135 lines (112 loc) · 2.14 KB
/
WaveTrend.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
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
126
127
128
129
130
131
132
133
134
135
Settings =
{
Name = "*WaveTrend",
ChannelLength = 7,
AverageLength = 30,
line=
{
{
Name = "wt1",
Color = RGB(0, 128, 0),
Type = TYPE_LINE,
Width = 2
}
,
{
Name = "wt2",
Color = RGB(128, 0, 0),
Type = TYPE_POINT,
Width = 2
}
,
{
Name = "wt1-wt2",
Color = RGB(150, 150, 150),
Type = TYPE_HISTOGRAM,
Width = 2
}
,
{
Name = "53",
Color = RGB(230, 240, 8),
Type = TYPE_LINE,
Width = 1
}
,
{
Name = "-53",
Color = RGB(230, 240, 8),
Type = TYPE_LINE,
Width = 1
}
,
{
Name = "60",
Color = RGB(80, 170, 255),
Type = TYPE_LINE,
Width = 1
}
,
{
Name = "-60",
Color = RGB(80, 170, 255),
Type = TYPE_LINE,
Width = 1
}
}
}
----------------------------------------------------------
function WaveTrend()
local esa={}
local d={}
local wt1={}
local wt2={}
local SMA=fSMA()
return function(ind, _c, _a)
local index = ind
local n1 = _c
local n2 = _a
local ci = 0
local k = 2/(n1+1)
local kk = 2/(n2+1)
if index == 1 then
esa = {}
d={}
wt1={}
wt2={}
esa[index]=0
d[index]=0
wt1[index]=0
wt2[index]=0
return nil, nil, nil, 53, -53, 60, -60
end
ap = (H(index) + L(index) + C(index))/3
esa[index] = k*ap+(1-k)*esa[index-1]
d[index] = k*math.abs(ap - esa[index])+(1-k)*d[index-1]
ci = (ap - esa[index]) / (0.015 * d[index])
wt1[index] = kk*ci+(1-kk)*wt1[index-1]
wt2[index] = SMA(index, 4, wt1)
return wt1[index], wt2[index], wt1[index] - wt2[index], 53, -53, 60, -60
end
end
----------------------------
function Init()
myWaveTrend = WaveTrend()
return #Settings.line
end
function OnCalculate(index)
return myWaveTrend(index, Settings.ChannelLength, Settings.AverageLength)
end
function fSMA()
return function (Index, Period, bb)
local Out = 0
if Index >= Period then
local sum = 0
for i = Index-Period+1, Index do
sum = sum + bb[i]
end
Out = sum/Period
end
return Out
end
end