Could you help me to solve the following problem,please ?
I did write a module in pyhton . For the next module I need the following variables or values:
lastprice and lastpivotprice
What definition or script change is neccessary, that this 2 variables are global variables)?
Actually if i try to call lastpivotprice outside the module i get the following error message:
nameError: name 'pivots' is not defined
Module Code: checkpivots.py
try:
df['High'].plot(label='high')
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+=1
else:
counter = 0
if counter == 5:
lastPivot=currentMax
dateloc =Range.index(lastPivot)
lastDate = daterange[dateloc]
pivots.append(lastPivot)
dates.append(lastDate)
except Exception:
print("-")
lastpivotprice = pivots[-1]
lastprice=df.iloc[-1]['Close'] #read value in the last row in col 'close'
lastprice2 = df['Close'].values[-2] #read value in the last row minus2 in col 'close'
#print (lastprice)
# print (lastpivotprice)
# print (lastprice2)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…