Exemplo n.º 1
0
    def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture:
        """"""
        # Create objects
        candle_picture = QtGui.QPicture()
        painter = QtGui.QPainter(candle_picture)

        # Set painter color
        if bar.close_price >= bar.open_price:
            painter.setPen(self._up_pen)
            painter.setBrush(self._up_brush)
        else:
            painter.setPen(self._down_pen)
            painter.setBrush(self._down_brush)

        # Draw candle shadow
        painter.drawLine(QtCore.QPointF(ix, bar.high_price),
                         QtCore.QPointF(ix, bar.low_price))

        # Draw candle body
        if bar.open_price == bar.close_price:
            painter.drawLine(
                QtCore.QPointF(ix - BAR_WIDTH, bar.open_price),
                QtCore.QPointF(ix + BAR_WIDTH, bar.open_price),
            )
        else:
            rect = QtCore.QRectF(ix - BAR_WIDTH, bar.open_price, BAR_WIDTH * 2,
                                 bar.close_price - bar.open_price)
            painter.drawRect(rect)

        # Finish
        painter.end()
        return candle_picture
Exemplo n.º 2
0
Arquivo: item.py Projeto: asciili/vnpy
    def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture:
        """"""
        value = self.values[ix]
        last_value = self.values[ix - 1]
        # Create objects
        picture = QtGui.QPicture()
        painter = QtGui.QPainter(picture)

        # Set painter color
        painter.setPen(self.yellow_pen)
        # painter.setBrush(self.yellow_brush)

        # Draw Line
        if np.isnan(last_value) or np.isnan(value):
            # print(ix - 1, last_value,ix, value,)
            pass
        else:
            start_point = QtCore.QPointF(ix - 1, last_value)
            end_point = QtCore.QPointF(ix, value)
            painter.drawLine(start_point, end_point)

        # Draw Circle
        # painter.drawEllipse(QtCore.QPointF(ix, self.values[ix]), 2, 2)

        # Finish
        painter.end()
        return picture
Exemplo n.º 3
0
    def _update_label(self) -> None:
        """"""
        bottom_plot = list(self._plots.values())[-1]
        axis_width = bottom_plot.getAxis("right").width()
        axis_height = bottom_plot.getAxis("bottom").height()
        axis_offset = QtCore.QPointF(axis_width, axis_height)

        bottom_view = list(self._views.values())[-1]
        bottom_right = bottom_view.mapSceneToView(
            bottom_view.sceneBoundingRect().bottomRight() - axis_offset
        )
        # LWH 2019-10-30
        bottom_left = bottom_view.mapSceneToView(
            bottom_view.sceneBoundingRect().bottomLeft() + 3 * axis_offset
        )
        for plot_name, label in self._y_labels.items():
            if plot_name == self._plot_name:
                label.setText(str(self._y))
                label.show()
                label.setPos(bottom_right.x(), self._y)
            else:
                label.hide()

        dt = self._manager.get_datetime(self._x)
        if dt:
            self._x_label.setText(dt.strftime("%Y-%m-%d %H:%M:%S"))
            self._x_label.show()
            #self._x_label.setPos(self._x, bottom_right.y())
            self._x_label.setPos(bottom_left.x(), bottom_right.y())
            self._x_label.setAnchor((0, 0))
Exemplo n.º 4
0
    def _update_label(self) -> None:
        """"""
        bottom_plot = list(self._plots.values())[-1]
        axis_width = bottom_plot.getAxis("right").width()
        axis_height = bottom_plot.getAxis("bottom").height()
        axis_offset = QtCore.QPointF(axis_width + 150, axis_height + 100)

        bottom_view = list(self._views.values())[-1]
        bottom_right = bottom_view.mapSceneToView(
            bottom_view.sceneBoundingRect().bottomRight() - axis_offset
        )

        if self._x < self._manager.get_count():
            current_data_series = self._manager.get_df().iloc[self._x]
            label_text = "".join([f'{key} : {value}\n\n' for key, value in current_data_series.items()])
            for plot_name, label in self._y_labels.items():
                if plot_name == self._plot_name:
                    # label.setText(str(self._y))
                    label.setText(label_text)
                    label.show()
                    label.setPos(bottom_right.x(), self._y)
                else:
                    label.hide()

            dt = self._manager.get_datetime(self._x)
            if dt:
                self._x_label.setText(dt.strftime("%Y-%m-%d %H:%M:%S"))
                self._x_label.show()
                self._x_label.setPos(self._x, bottom_right.y())
                self._x_label.setAnchor((0, 0))
Exemplo n.º 5
0
Arquivo: item.py Projeto: asciili/vnpy
    def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture:
        """"""
        macd_value = self.get_macd_value(ix)
        last_macd_value = self.get_macd_value(ix - 1)

        # # Create objects
        picture = QtGui.QPicture()
        painter = QtGui.QPainter(picture)

        # # Draw macd lines
        if np.isnan(macd_value[0]) or np.isnan(last_macd_value[0]):
            # print("略过macd lines0")
            pass
        else:
            end_point0 = QtCore.QPointF(ix, macd_value[0])
            start_point0 = QtCore.QPointF(ix - 1, last_macd_value[0])
            painter.setPen(self.white_pen)
            painter.drawLine(start_point0, end_point0)

        if np.isnan(macd_value[1]) or np.isnan(last_macd_value[1]):
            # print("略过macd lines1")
            pass
        else:
            end_point1 = QtCore.QPointF(ix, macd_value[1])
            start_point1 = QtCore.QPointF(ix - 1, last_macd_value[1])
            painter.setPen(self.yellow_pen)
            painter.drawLine(start_point1, end_point1)

        if not np.isnan(macd_value[2]):
            if (macd_value[2] > 0):
                painter.setPen(self.red_pen)
                painter.setBrush(pg.mkBrush(255, 0, 0))
            else:
                painter.setPen(self.green_pen)
                painter.setBrush(pg.mkBrush(0, 255, 0))
            painter.drawRect(QtCore.QRectF(ix - 0.3, 0, 0.6, macd_value[2]))
        else:
            # print("略过macd lines2")
            pass

        painter.end()
        return picture
Exemplo n.º 6
0
    def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture:
        """"""
        sma_value = self.get_sma_value(ix)
        last_sma_value = self.get_sma_value(ix - 1)

        # Create objects
        picture = QtGui.QPicture()
        painter = QtGui.QPainter(picture)

        # Set painter color
        painter.setPen(self.blue_pen)

        # Draw Line
        start_point = QtCore.QPointF(ix-1, last_sma_value)
        end_point = QtCore.QPointF(ix, sma_value)
        painter.drawLine(start_point, end_point)

        # Finish
        painter.end()
        return picture
Exemplo n.º 7
0
    def generatePicture(self):

        self.picture = QtGui.QPicture()
        p = QtGui.QPainter(self.picture)
        # 白色
        p.setPen(pg.mkPen('w'))
        prema5 = 0
        prema10 = 0
        prema20 = 0

        for m in self.data:

            if prema5 != 0 and self.period == 5:
                # 白色
                p.setPen(pg.mkPen('w'))
                p.setBrush(pg.mkBrush('w'))
                p.drawLine(QtCore.QPointF(m.t - 1, prema5), QtCore.QPointF(m.t, m.ma))
            prema5 = m.ma
            if prema10 != 0 and self.period == 10:
                # 青色
                p.setPen(pg.mkPen('c'))
                p.setBrush(pg.mkBrush('c'))
                p.drawLine(QtCore.QPointF(m.t - 1, prema10), QtCore.QPointF(m.t, m.ma))
            prema10 = m.ma
            if prema20 != 0 and self.period == 20:
                # 品色
                p.setPen(pg.mkPen('m'))
                p.setBrush(pg.mkBrush('m'))
                p.drawLine(QtCore.QPointF(m.t - 1, prema20), QtCore.QPointF(m.t, m.ma))
            prema20 = m.ma
        p.end()
Exemplo n.º 8
0
    def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture:
        """"""
        rsi_value = self.get_rsi_value(ix)
        last_rsi_value = self.get_rsi_value(ix - 1)

        # Create objects
        picture = QtGui.QPicture()
        painter = QtGui.QPainter(picture)

        # Draw RSI line
        painter.setPen(self.yellow_pen)

        end_point = QtCore.QPointF(ix, rsi_value)
        start_point = QtCore.QPointF(ix - 1, last_rsi_value)
        painter.drawLine(start_point, end_point)

        # Draw oversold/overbought line
        painter.setPen(self.white_pen)

        painter.drawLine(
            QtCore.QPointF(ix, 70),
            QtCore.QPointF(ix - 1, 70),
        )

        painter.drawLine(
            QtCore.QPointF(ix, 30),
            QtCore.QPointF(ix - 1, 30),
        )

        # Finish
        painter.end()
        return picture
Exemplo n.º 9
0
    def _mouse_moved(self, evt: tuple) -> None:
        """
        Callback function when mouse is moved.
        """
        if not self._manager.get_count():
            return

        # First get current mouse point
        pos = evt

        for plot_name, view in self._views.items():
            rect = view.sceneBoundingRect()

            if rect.contains(pos):
                mouse_point = view.mapSceneToView(pos)
                self._x = to_int(mouse_point.x())
                self._y = mouse_point.y()
                self._plot_name = plot_name
                break

        # Then update cursor component
        self._update_line()
        self._update_label()
        self.update_info()

        if self.dt_ix:
            #print(self.dt_ix)
            for plot_name, plot in self._plots.items():
                #info = self._infos[plot_name]
                # print(plot_info_text)
                try:
                    text = ""
                    for k,v in self.dt_ix.items():
                        text += k+":"+str(v[int(self._x)])+"\n"
                    self.inf.setText(text)
                    #self.inf.setText("bkhigh:"+self.dt_ix[int(self._x)])
                    self.inf.show()
                    #print(plot_name)
                    view = self._views[plot_name]
                    coodinate = QtCore.QPointF(100,0)
                #view = self._views["candle"]
                    top_left = view.mapSceneToView(view.sceneBoundingRect().topLeft()+coodinate)
                    # print(view.sceneBoundingRect())
                    # print(view.sceneBoundingRect().topLeft())
                    # print(top_left)
                    #print(self._x)

                    self.inf.setPos(top_left)
                except:
                    print("该K线无数据")
Exemplo n.º 10
0
Arquivo: item.py Projeto: asciili/vnpy
    def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture:
        """"""
        last_bar = self._manager.get_bar(ix - 1)

        # Create objects
        picture = QtGui.QPicture()
        painter = QtGui.QPainter(picture)

        # Set painter color
        painter.setPen(self.white_pen)

        # Draw Line
        end_point = QtCore.QPointF(ix, bar.close_price)

        if last_bar:
            start_point = QtCore.QPointF(ix - 1, last_bar.close_price)
        else:
            start_point = end_point

        painter.drawLine(start_point, end_point)

        # Finish
        painter.end()
        return picture
Exemplo n.º 11
0
    def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture:
        """"""
        boll_value = self.get_boll_value(ix)
        last_boll_value = self.get_boll_value(ix - 1)


        # Create objects
        picture = QtGui.QPicture()
        painter = QtGui.QPainter(picture)

        # Set painter color
        painter.setPen(self.blue_pen)

        if last_boll_value==0:
            # Draw Line
            start_point = QtCore.QPointF(0, 0)
            end_point = QtCore.QPointF(0, 0)
            painter.drawLine(start_point, end_point)
        else:
            # Draw Line
            start_point = QtCore.QPointF(ix-1, last_boll_value["upper"])
            end_point = QtCore.QPointF(ix, boll_value["upper"])
            painter.drawLine(start_point, end_point)
            
            start_point = QtCore.QPointF(ix-1, last_boll_value["lower"])
            end_point = QtCore.QPointF(ix, boll_value["lower"])
            painter.drawLine(start_point, end_point)

            start_point = QtCore.QPointF(ix-1, last_boll_value["middle"])
            end_point = QtCore.QPointF(ix, boll_value["middle"])
            painter.setPen(self.white_pen)
            painter.drawLine(start_point, end_point)
            

        
        # Finish
        painter.end()
        return picture
Exemplo n.º 12
0
Arquivo: item.py Projeto: asciili/vnpy
    def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture:
        """"""
        rsi_value = self.values[ix]
        last_rsi_value = self.values[ix - 1]

        # Create objects
        picture = QtGui.QPicture()
        painter = QtGui.QPainter(picture)

        # Draw RSI line
        painter.setPen(self.yellow_pen)

        if np.isnan(last_rsi_value) or np.isnan(rsi_value):
            # print(ix - 1, last_rsi_value,ix, rsi_value,)
            pass
        else:
            end_point = QtCore.QPointF(ix, rsi_value)
            start_point = QtCore.QPointF(ix - 1, last_rsi_value)
            painter.drawLine(start_point, end_point)

        # Draw oversold/overbought line
        painter.setPen(self.white_pen)

        painter.drawLine(
            QtCore.QPointF(ix, 70),
            QtCore.QPointF(ix - 1, 70),
        )

        painter.drawLine(
            QtCore.QPointF(ix, 30),
            QtCore.QPointF(ix - 1, 30),
        )

        # Finish
        painter.end()
        return picture