-
Notifications
You must be signed in to change notification settings - Fork 64
/
hourOpen.lua
122 lines (107 loc) · 2.97 KB
/
hourOpen.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
--logfile=io.open(getWorkingFolder().."\\LuaIndicators\\openHour.txt", "w")
Settings =
{
Name = "*hour open",
showMaxMin = 0,
line =
{
{
Name = "HourOpen",
Color = RGB (0, 128, 255),
Type = TYPET_BAR,
Width = 2
},
{
Name = "HourMax",
Color = RGB (89, 213, 107),
Type = TYPET_BAR,
Width = 2
},
{
Name = "HourMin",
Color = RGB (251, 82, 0),
Type = TYPET_BAR,
Width = 2
},
{
Name = "HourMiddle",
Color = RGB (128, 128, 128),
Type = TYPET_BAR,
Width = 2
}
}
}
function WriteLog(text)
logfile:write(tostring(os.date("%c",os.time())).." "..text.."\n");
logfile:flush();
LASTLOGSTRING = text;
end
function Init ()
return #Settings.line -- кол-во линий
end
hourOpen = nil
hourMax = nil
hourMin = nil
HourMiddle = nil
hourOpenIndex = 0
Close = {}
Open = {}
High = {}
Low = {}
function OnCalculate (index)
if index == 1 then
local source_info = getDataSourceInfo()
if source_info.interval > 60 then
message("interval must be less then 60")
return nil
end
hourOpen = nil
hourMax = nil
hourMin = nil
HourMiddle = nil
hourOpenIndex = 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 hourOpen end
Close[index] = C(index)
Open[index] = O(index)
High[index] = H(index)
Low[index] = L(index)
local t = T(index)
local t1 = T(hourOpenIndex)
if t.hour > t1.hour or t.week_day ~= t1.week_day then
if Settings.showMaxMin==1 then
--hourMax = math.max(Close[hourOpenIndex], Open[hourOpenIndex])
--hourMin = math.min(Close[hourOpenIndex], Open[hourOpenIndex])
hourMax = High[hourOpenIndex]
hourMin = Low[hourOpenIndex]
for i=hourOpenIndex+1,index-1 do
--hourMax = math.max(Close[i], Open[i], hourMax)
--hourMin = math.min(Close[i], Open[i], hourMin)
hourMax = math.max(High[i], hourMax)
hourMin = math.min(Low[i], hourMin)
end
HourMiddle = (hourMax+hourMin)/2
for i=hourOpenIndex,index-1 do
SetValue(i, 2, hourMax)
SetValue(i, 3, hourMin)
SetValue(i, 4, HourMiddle)
end
end
hourOpenIndex = index
hourOpen = O(index)
end
return hourOpen
end