dataToNow = [] quotes = [] for i in range(len(data.Times)): quotes.append([ i, data.Data[0][i], data.Data[3][i], data.Data[2][i], data.Data[1][i] ]) global chan #chan = Chan(data.Data[0], data.Data[1], data.Data[2],data.Data[3], data.Data[4], data.Times) chan = Chan([], [], [], [], [], []) print(len(data.Times)) start = 400 for tick in range(0, start): chan.append(data.Data[0][tick], data.Data[1][tick], data.Data[2][tick], data.Data[3][tick], data.Data[4][tick], data.Times[tick]) for tick in range(start, len(data.Times)): chan.append(data.Data[0][tick], data.Data[1][tick], data.Data[2][tick], data.Data[3][tick], data.Data[4][tick], data.Times[tick]) chan.barsMerge() chan.findFenxing() chan.findBi() chan.findLines() chan.findZhongshus() chan.calculate_ta() chan.findBiZhongshus() chan.macdSeparate() chan.findTrendLines() chan.decisionBi()
def initplotTick(self): """""" import pandas as pd class ValuesParser: def __init__(self, dataframe): self.Data = [ data['open'].tolist(), data['high'].tolist(), data['low'].tolist(), data['close'].tolist(), data['volume'].tolist() ] self.Times = data.index.tolist() data = pd.DataFrame.from_csv('rb1705_year.csv')[10000:11100] data = ValuesParser(data) global dataToNow #dataToNow = w.wst(code, "last", data.Times[-1], nowTime, "") dataToNow = [] quotes = [] for i in range(len(data.Times)): quotes.append([ i, data.Data[0][i], data.Data[3][i], data.Data[2][i], data.Data[1][i] ]) global chan #chan = Chan(data.Data[0], data.Data[1], data.Data[2],data.Data[3], data.Data[4], data.Times) chan = Chan([], [], [], [], [], []) print(len(data.Times)) start = 1000 for tick in range(0, start): chan.append(data.Data[0][tick], data.Data[1][tick], data.Data[2][tick], data.Data[3][tick], data.Data[4][tick], data.Times[tick]) for tick in range(start, len(data.Times)): chan.append(data.Data[0][tick], data.Data[1][tick], data.Data[2][tick], data.Data[3][tick], data.Data[4][tick], data.Times[tick]) chan.barsMerge() chan.findFenxing() chan.findBi() chan.findLines() chan.findZhongshus() chan.calculate_ta() chan.findBiZhongshus() chan.macdSeparate() chan.findTrendLines() chan.decisionBi() #chan.plotBuySell() chan.plotBeichi() #chan.plotBiZhongshu() #plt.show() print(len(chan.dingbeichi)) #win = pg.GraphicsWindow() layout = QtGui.QVBoxLayout(self) win = pg.GraphicsLayoutWidget(self) layout.addWidget(win) self.setLayout(layout) #win = ApplicationWindow() win.setWindowTitle('行情+缠论') label = pg.LabelItem(justify="center") win.addItem(label) axis = self.DateAxis(data.Times, orientation='bottom') p1 = win.addPlot(row=1, col=0, axisItems={'bottom': axis}) p2 = win.addPlot(row=2, col=0, axisItems={'bottom': axis}) p2.setXLink(p1) p2.plot(x=list(range(len(data.Times))), y=chan.diff, pen='w') p2.plot(x=list(range(len(data.Times))), y=chan.dea, pen='y') hLine = pg.InfiniteLine(angle=0, movable=False) hLine.setPos(0) p2.addItem(hLine, ignoreBounds=True) macdPositive = [] macdNegetive = [] for i in chan.macd: if i >= 0: macdPositive.append(i) macdNegetive.append(0) else: macdPositive.append(0) macdNegetive.append(i) curve0 = p2.plot(x=list(range(len(data.Times))), y=np.zeros(len(data.Times))) curve1 = p2.plot(x=list(range(len(data.Times))), y=macdPositive, pen='w') curve2 = p2.plot(x=list(range(len(data.Times))), y=macdNegetive, pen='w') itemFill1 = pg.FillBetweenItem(curve0, curve1, pg.mkBrush('r')) itemFill2 = pg.FillBetweenItem(curve0, curve2, pg.mkBrush('g')) p2.addItem(itemFill1) p2.addItem(itemFill2) #win.addItem(label) #text = pg.TextItem('test',anchor=(0,1)) # p1.addItem(text) itemK = self.CandlestickItem() itemK.set_data(quotes) itemBi = self.BisItem() itemBi.set_data(chan.bis) itemLine = self.LinesItem() itemLine.set_data(chan.lines) itemZhongshu = self.ZhongshusItem() #itemZhongshu.set_data(chan.zhongshus) itemZhongshu.set_data(chan.biZhongshus) itemDiBeiChi = self.BeiChiItem() itemDiBeiChi.set_data(chan.dibeichi) itemDingBeiChi = self.BeiChiItem() itemDingBeiChi.set_data(chan.dingbeichiLine) itemTrendDiBeiChi = self.BeiChiItem() itemTrendDiBeiChi.set_data(chan.trendDibeichi) itemTrendDingBeiChi = self.BeiChiItem() itemTrendDingBeiChi.set_data(chan.trendDingbeichi) p1.plot() p1.addItem(itemK) p1.addItem(itemBi) p1.addItem(itemLine) p1.addItem(itemZhongshu) p1.addItem(itemDiBeiChi) p1.addItem(itemDingBeiChi) p1.addItem(itemTrendDiBeiChi) p1.addItem(itemTrendDingBeiChi) p1.showGrid(x=True, y=True) #p1.setWindowTitle('pyqtgraph example: customGraphicsItem') # cross hair vLine = pg.InfiniteLine(angle=90, movable=False) hLine = pg.InfiniteLine(angle=0, movable=False) p1.addItem(vLine, ignoreBounds=True) p1.addItem(hLine, ignoreBounds=True) vb1 = p1.vb vb2 = p2.vb def mouseMoved(evt): pos = evt[ 0] # using signal proxy turns original arguments into a tuple print("..") if p1.sceneBoundingRect().contains(pos): mousePoint = vb1.mapSceneToView(pos) index = int(mousePoint.x()) if index > 0 and index < len(quotes): label.setText( "<span style='font-size: 12pt'>date=%s, <span style='color: red'>open=%0.01f</span>, <span style='color: green'>close=%0.01f\n, high = %0.01f, low = %0.01f</span>" % (data.Times[index].strftime('%Y%m%d,%H:%M'), quotes[index][1], quotes[index][2], quotes[index][3], quotes[index][4])) vLine.setPos(mousePoint.x()) hLine.setPos(mousePoint.y()) setYRange() def setYRange(): r = vb1.viewRange() xmin = math.floor(r[0][0]) xmax = math.ceil(r[0][1]) #fix index <0 bug xmax = max(0, xmax - xmin) xmin = max(0, xmin) xmin = min(xmin, len(data.Times)) xmax = min(xmax, len(data.Times)) xmax = max(xmin, xmax) if (xmin == xmax): return highBound1 = max(data.Data[1][xmin:xmax]) lowBound1 = min(data.Data[2][xmin:xmax]) p1.setRange(yRange=(lowBound1, highBound1)) highBound2 = max(chan.diff[xmin:xmax]) lowBound2 = min(chan.diff[xmin:xmax]) p2.setRange(yRange=(lowBound2, highBound2)) #self.pw1 = win #self.vbl_1.addWidget(self.pw1) #self.setMouseTracking(True) proxy = pg.SignalProxy(p1.scene().sigMouseMoved, rateLimit=60, slot=mouseMoved) self.proxy = proxy
def initplotTick(self): """""" global chan chan = Chan([], [], [], [], [], []) for index in range(0, len(self.listBar)): chan.append(self.listOpen[index], self.listHigh[index], self.listLow[index], self.listClose[index], self.listOpenInterest[index], self.listTimes[index]) if (chan.length > 26): chan.barsMerge() chan.findFenxing() chan.findBi() chan.findLines() chan.findZhongshus() chan.calculate_ta() chan.findBiZhongshus() chan.macdSeparate() chan.findTrendLines() chan.decisionBi() win = pg.GraphicsWindow() win.setWindowTitle('行情+缠论') label = pg.LabelItem(justify="center") win.addItem(label) axis = self.DateAxis(self.listTimes, orientation='bottom') p1 = win.addPlot(row=1, col=0, axisItems={'bottom': axis}) p2 = win.addPlot(row=2, col=0, axisItems={'bottom': axis}) p2.setXLink(p1) p2.plot(x=list(range(len(self.listBar))), y=chan.diff, pen='w') p2.plot(x=list(range(len(self.listBar))), y=chan.dea, pen='y') hLine = pg.InfiniteLine(angle=0, movable=False) hLine.setPos(0) p2.addItem(hLine, ignoreBounds=True) macdPositive = [] macdNegetive = [] for i in chan.macd: if i >= 0: macdPositive.append(i) macdNegetive.append(0) else: macdPositive.append(0) macdNegetive.append(i) self.curve0 = p2.plot(x=list(range(len(self.listBar))), y=np.zeros(len(self.listBar))) self.curve1 = p2.plot(x=list(range(len(self.listBar))), y=macdPositive, pen='w') self.curve2 = p2.plot(x=list(range(len(self.listBar))), y=macdNegetive, pen='w') self.itemFill1 = pg.FillBetweenItem(self.curve0, self.curve1, pg.mkBrush('r')) self.itemFill2 = pg.FillBetweenItem(self.curve0, self.curve2, pg.mkBrush('g')) p2.addItem(self.itemFill1) p2.addItem(self.itemFill2) self.itemK = self.CandlestickItem() self.itemK.set_data(self.listBar) self.itemBi = self.BisItem() self.itemBi.set_data(chan.bis) self.itemLine = self.LinesItem() self.itemLine.set_data(chan.lines) self.itemZhongshu = self.ZhongshusItem() #itemZhongshu.set_data(chan.zhongshus) self.itemZhongshu.set_data(chan.biZhongshus) # self.itemDiBeiChi = self.BeiChiItem() # self.itemDiBeiChi.set_data(chan.dibeichi) # self.itemDingBeiChi = self.BeiChiItem() # self.itemDingBeiChi.set_data(chan.dingbeichiLine) # self.itemTrendDiBeiChi = self.BeiChiItem() # self.itemTrendDiBeiChi.set_data(chan.trendDibeichi) # self.itemTrendDingBeiChi = self.BeiChiItem() # self.itemTrendDingBeiChi.set_data(chan.trendDingbeichi) p1.plot() p1.addItem(self.itemK) p1.addItem(self.itemBi) p1.addItem(self.itemLine) p1.addItem(self.itemZhongshu) # p1.addItem(self.itemDiBeiChi) # p1.addItem(self.itemDingBeiChi) # p1.addItem(self.itemTrendDiBeiChi) # p1.addItem(self.itemTrendDingBeiChi) p1.showGrid(x=True, y=True) #p1.setWindowTitle('pyqtgraph example: customGraphicsItem') # cross hair vLine = pg.InfiniteLine(angle=90, movable=False) hLine = pg.InfiniteLine(angle=0, movable=False) p1.addItem(vLine, ignoreBounds=True) p1.addItem(hLine, ignoreBounds=True) vb1 = p1.vb vb2 = p2.vb def mouseMoved(evt): pos = evt[ 0] # using signal proxy turns original arguments into a tuple if p1.sceneBoundingRect().contains(pos): mousePoint = vb1.mapSceneToView(pos) index = int(mousePoint.x()) if index > 0 and index < len(self.listBar): label.setText( "<span style='font-size: 12pt'>date=%d, <span style='color: red'>open=%0.01f</span>, <span style='color: green'>close=%0.01f\n, high = %0.01f, low = %0.01f</span>" % (self.listTimes[index], self.listBar[index][1], self.listBar[index][2], self.listBar[index][3], self.listBar[index][4])) vLine.setPos(mousePoint.x()) hLine.setPos(mousePoint.y()) setYRange() def setYRange(): r = vb1.viewRange() xmin = math.floor(r[0][0]) xmax = math.ceil(r[0][1]) #fix index <0 bug xmax = max(0, xmax - xmin) xmin = max(0, xmin) xmin = min(xmin, len(self.listBar)) xmax = min(xmax, len(self.listBar)) xmax = max(xmin, xmax) if (xmin == xmax): return if (len(self.listBar)): highBound1 = max(self.listHigh[xmin:xmax]) lowBound1 = min(self.listLow[xmin:xmax]) p1.setRange(yRange=(lowBound1, highBound1)) if (len(self.chan.diff)): highBound2 = max(self.chan.diff[xmin:xmax]) lowBound2 = min(self.chan.diff[xmin:xmax]) p2.setRange(yRange=(lowBound2, highBound2)) self.proxy = pg.SignalProxy(p1.scene().sigMouseMoved, rateLimit=60, slot=mouseMoved) self.win = win self.p1 = p1 self.p2 = p2 self.chan = chan self.axis = axis