Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #LinesToDraw is the pandas series where we have our dots stored.
- #Input_High and Input_Low are pandas series where we have our highs and lows of the candlesticks stored.
- #Function to find the value of all the points of a line
- def FindYGivenIndex(i,index,Y,subindex,subY):
- return Y+(i-index)*(subY-Y)/(subindex-index)
- LineDots = list() #I will store a list of lines (with each dot in that line) here.
- #Now we calculate the possible existing lines, and store each into a series:
- for index in LinesToDraw.index:
- Y = LinesToDraw.ix[index]
- for subindex in LinesToDraw.index:
- subY = LinesToDraw.ix[subindex]
- if subindex > index and abs(subindex - index)<30 and abs(subindex - index)>3:
- LineDots.append( pd.DataFrame(range(index,subindex),index = range(index,subindex)).apply(FindYGivenIndex,args = (index,Y,subindex,subY,)) )
- CurrentPlot.LineDots = LineDots
- CurrentPlot.LinesToDraw = list()
- #Now for the resulting lines, we filter the ones that are over or under Input_High or Input_Low
- for line in CurrentPlot.LineDots:
- if len(line.dropna()):
- try:
- if (Input_High.ix[line.index].astype('float') <= line.iloc[:,0].astype('float')).all() or (Input_Low.ix[line.index].astype('float') >= line.iloc[:,0].astype('float')).all():
- CurrentPlot.LinesToDraw.append(line)
- except:
- pass
- #Now we can draw them, but as said, we iterated too many times, making the process _very_ slow.
- for line in CurrentPlot.LinesToDraw:
- plot([CurrentPlot.X_Axis.ix[line.index[0]],CurrentPlot.X_Axis.ix[line.index[-1]]], [line.iloc[0],line.iloc[-1]], 'k-')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement