-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpivots_calc.py
106 lines (81 loc) · 2.67 KB
/
pivots_calc.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
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
# Function to find the pivot low with alternating pivots or finding the highest between two pivots low or vice cersa
def find_pivot(pivottype, df):
pivots =[]
dates = []
counter = 0
Range = [0 for _ in range(10)]
dateRange = [0 for _ in range(10)]
for i in df.index:
currentMin = min(Range,default = 0)
currentMax = max(Range,default = 0)
value = round(df[pivottype][i], 2)
Range = Range[1:9]
Range.append(value)
dateRange = dateRange[1:9]
dateRange.append(i)
if currentMax == max(Range, default=0):
counter = counter + 1
elif currentMin == min(Range, default=0):
counter = counter + 1
else:
counter = 0
if counter == 5:
lastPivot = currentMin
if pivottype == "High":
lastPivot = currentMax
dateloc = Range.index(lastPivot)
lastDate = dateRange[dateloc]
pivots.append(lastPivot)
dates.append(lastDate)
return pivots,dates
def pivothigh(df):
""" Function to find the pivot high with alternating pivots or fidning the lowest between two pivots high or vice cersa"""
pivots =[]
dates = []
counter = 0
lastPivot = 0
Range = [0,0,0,0,0,0,0,0,0,0]
daterange = [0,0,0,0,0,0,0,0,0,0]
for i in df.index:
currentMax = max(Range,default = 0)
value=round(df["High"][i],2)
Range=Range[1:9]
Range.append (value)
daterange=daterange[1:9]
daterange.append(i)
if currentMax == max(Range , default=0):
counter = counter + 1
else:
counter = 0
if counter == 5:
lastPivot=currentMax
dateloc =Range.index(lastPivot)
lastDate = daterange[dateloc]
pivots.append(lastPivot)
dates.append(lastDate)
return pivots,dates
def pivotlow(df):
pivots1 =[]
dates1 = []
counter = 0
lastPivot = 0
Range = [0,0,0,0,0,0,0,0,0,0]
daterange = [0,0,0,0,0,0,0,0,0,0]
for i in df.index:
currentMin = min(Range,default = 0)
value = round(df["Low"][i],2)
Range = Range[1:9]
Range.append (value)
daterange = daterange[1:9]
daterange.append(i)
if currentMin == min(Range ,default=0):
counter = counter + 1
else:
counter = 0
if counter == 5:
lastPivot = currentMin
dateloc = Range.index(lastPivot)
lastDate = daterange[dateloc]
pivots1.append(lastPivot)
dates1.append(lastDate)
return pivots1,dates1