I want to be able to plot Donchian-channels. It's probably easier to use numpy but, am not that fluent with numpy yet so i thought i could make a function that takes two arrays as input(Highs and lows), make a little size-limited-dynamical-array over x days and then within that array find out the max and min value. And at the end output two arrays to plot the data with.
The code that i came up with is
zl=[2,3,4,5,5,4,3,2,3,4,3,4,5,6,7,8,7,6,5,4,5,6]
zh=[3,4,5,6,6,5,4,3,4,5,4,5,6,7,8,9,8,7,6,5,6,7]
def donchianChannels(highValue, lowValue, window):
highOutput = []
lowOutput = []
lsth = [None]*window
lstl = [None]*window
for i in range(0, len(highValue)):
maxValue=0
lsth.append(highValue[i])
lsth = lsth[-window:]
for j in range(0, len(lsth)):
if lsth[j] > maxValue:
maxValue = lsth[j]
highOutput.append(maxValue)
for i in range(0, len(lowValue)):
minValue=100000
lstl.append(lowValue[i])
lstl = lstl[-window:]
for j in range(0, len(lstl)):
if lstl[j] < minValue:
minValue = lstl[j]
lowOutput.append(lowValue)
return highOutput, lowOutput
maxvalue, minvalue = donchianChannels(zh, zl, 3) print maxvalue, minvalue
and the output i get is
[3, 4, 5, 6, 6, 6, 6, 5, 4, 5, 5, 5, 6, 7, 8, 9, 9, 9, 8, 7, 6, 7] [[2, 3, 4, 5, 5, 4, 3, 2, 3, 4, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 5, 6], [2, 3, 4, 5, 5, 4, 3, 2, 3, 4, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 5, 6], [2, 3, 4, 5, 5, 4, 3, 2, 3, 4, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 5, 6], [2, 3, 4, 5, 5, 4, 3, 2, 3, 4, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 5, 6], [2, 3, 4, 5, 5, 4, 3, 2, 3, 4, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 5, 6], [2, 3, 4, 5, 5, 4, 3, 2, 3, 4, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 5, 6], [2, 3, 4, 5, 5, 4, 3, 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, 4, 5, 6]]
the algorithm for the maximum array works fine, but the minimum one does not work at all. First of all it makes 22 arrays(the lenght of the input array) within one array. Second none of the minimum arrays plots the minimum values. They should be
[2,2,2,3,4,4,3,2,2,2,3,3,3,4,5,6,7,6,5,4,4,4,5]
Due to my calculations i can not see the problem it would be great if i could get some help please :)