forked from nick-nh/qlua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
weekDayOpen.lua
166 lines (154 loc) · 4.41 KB
/
weekDayOpen.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
Settings =
{
Name = "*WeekDayOpen",
showDay = 0,
showWeek = 1,
showMaxMin = 0,
line =
{
{
Name = "dayOpen",
Color = RGB (0, 255, 0),
Type = TYPET_BAR,
Width = 2
},
{
Name = "dayMax",
Color = RGB (89, 213, 107),
Type = TYPET_BAR,
Width = 2
},
{
Name = "dayMin",
Color = RGB (251, 82, 0),
Type = TYPET_BAR,
Width = 2
},
{
Name = "dayMiddle",
Color = RGB (128, 128, 128),
Type = TYPET_BAR,
Width = 2
},
{
Name = "weekOpen",
Color = RGB (0, 128, 255),
Type = TYPET_BAR,
Width = 2
},
{
Name = "weekMax",
Color = RGB (89, 213, 107),
Type = TYPET_BAR,
Width = 2
},
{
Name = "weekMin",
Color = RGB (251, 82, 0),
Type = TYPET_BAR,
Width = 2
},
{
Name = "weekMiddle",
Color = RGB (128, 128, 128),
Type = TYPET_BAR,
Width = 2
}
}
}
dayOpen = nil
dayMax = nil
dayMin = nil
dayMiddle = nil
weekOpen = nil
weekMax = nil
weekMin = nil
weekMiddle = nil
dayOpenIndex = 0
weekOpenIndex = 0
Close = {}
Open = {}
High = {}
Low = {}
function Init ()
return #Settings.line -- кол-во линий
end
function OnCalculate (index)
if index == 1 then
dayOpen = nil
dayMax = nil
dayMin = nil
dayMiddle = nil
weekOpen = nil
weekMax = nil
weekMin = nil
weekMiddle = nil
dayOpenIndex = 1
weekOpenIndex = 1
Close = {}
Close[index] = C(index)
Open = {}
Open[index] = O(index)
High = {}
High[index] = H(index)
Low = {}
Low[index] = L(index)
return nil
end
Close[index] = Close[index-1]
Open[index] = Open[index-1]
High[index] = High[index-1]
Low[index] = Low[index-1]
if not CandleExist(index) then return dayOpen, nil, nil, nil, weekOpen end
Close[index] = C(index)
Open[index] = O(index)
High[index] = H(index)
Low[index] = L(index)
local t = T(index)
local t1 = T(index-1)
if (t.day > t1.day or t.month > t1.month or t.year > t1.year) and Settings.showDay == 1 then
if Settings.showMaxMin==1 then
--dayMax = math.max(Close[dayOpenIndex], Open[dayOpenIndex])
--dayMin = math.min(Close[dayOpenIndex], Open[dayOpenIndex])
dayMax = High[dayOpenIndex]
dayMin = Low[dayOpenIndex]
for i=dayOpenIndex+1,index-1 do
--dayMax = math.max(Close[i], Open[i], dayMax)
--dayMin = math.min(Close[i], Open[i], dayMin)
dayMax = math.max(High[i], dayMax)
dayMin = math.min(Low[i], dayMin)
end
dayMiddle = (dayMax+dayMin)/2
for i=dayOpenIndex,index-1 do
SetValue(i, 2, dayMax)
SetValue(i, 3, dayMin)
SetValue(i, 4, dayMiddle)
end
end
dayOpenIndex = index
dayOpen = O(index)
end
if (t.week_day < t1.week_day or t.month > t1.month or t.year > t1.year) and Settings.showWeek == 1 then
if Settings.showMaxMin==1 then
--weekMax = math.max(Close[weekOpenIndex], Open[weekOpenIndex])
--weekMin = math.min(Close[weekOpenIndex], Open[weekOpenIndex])
weekMax = High[weekOpenIndex]
weekMin = Low[weekOpenIndex]
for i=weekOpenIndex+1,index-1 do
--weekMax = math.max(Close[i], Open[i], weekMax)
--weekMin = math.min(Close[i], Open[i], weekMin)
weekMax = math.max(High[i], weekMax)
weekMin = math.min(Low[i], weekMin)
end
weekMiddle = (weekMax+weekMin)/2
for i=weekOpenIndex,index-1 do
SetValue(i, 6, weekMax)
SetValue(i, 7, weekMin)
SetValue(i, 8, weekMiddle)
end
end
weekOpenIndex = index
weekOpen = O(index)
end
return dayOpen, nil, nil, nil, weekOpen
end