-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighslows.py
66 lines (55 loc) · 1.69 KB
/
highslows.py
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
import sys
import forex as f
def process(data, first_fun):
item = data[0]
high = item.high
low = item.low
low_t = high_t = item.time
highs = []
lows = []
first_done = True
for item in data:
if not first_done and first_fun(item):
# have crossed a time boundary
highs.append(high_t)
lows.append(low_t)
high = item.high
low = item.low
low_t = high_t = item.time
first_done = True
else:
if not first_fun(item):
first_done = False
if item.high > high:
high = item.high
high_t = item.time
elif item.low < low:
low = item.low
low_t = item.time
highs.append(high_t)
lows.append(low_t)
return highs, lows
if __name__ == '__main__':
years = [2013, 2014, 2015, 2016, 2017, 2018]
# years = [2018]
# data
datafile = sys.argv[1]
data = f.filter(
f.load_candles(datafile),
f.filter_year,
years)
periods = [
# (f.first_fun_hour, f.Summaries.HOURS, "which hour of day?"),
(f.first_fun_day, f.Summaries.DAY, "which day of month?"),
(f.first_fun_weekday, f.Summaries.DAYOFWEEK, "which day of week?"),
(f.first_fun_month, f.Summaries.MONTHS, "which month of year?")
]
for period in periods:
f_, p_, t_ = period
highs_, lows_ = process(data, f_)
print("HIGHS - {}".format(t_))
f.print_complete_summary(highs_, [p_])
# print(highs_)
print("LOWS - {}".format(t_))
f.print_complete_summary(lows_, [p_])
# print(lows_)