Пример #1
0
    def _draw_bar_picture(self, ix: int, bar: BarData) -> QtGui.QPicture:
        """"""
        # Create objects
        volume_picture = QtGui.QPicture()
        painter = QtGui.QPainter(volume_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 volume body
        rect = QtCore.QRectF(
            ix - BAR_WIDTH,
            0,
            BAR_WIDTH * 2,
            bar.volume
        )
        painter.drawRect(rect)

        # Finish
        painter.end()
        return volume_picture
Пример #2
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
Пример #3
0
 def boundingRect(self) -> QtCore.QRectF:
     """"""
     min_volume, max_volume = self._manager.get_volume_range()
     rect: QtCore.QRectF = QtCore.QRectF(0, min_volume,
                                         len(self._bar_picutures),
                                         max_volume - min_volume)
     return rect
Пример #4
0
 def boundingRect(self) -> QtCore.QRectF:
     """"""
     min_price, max_price = self._manager.get_price_range()
     rect = QtCore.QRectF(
         0,
         min_price,
         len(self._bar_picutures),
         max_price - min_price
     )
     return rect
Пример #5
0
 def boundingRect(self) -> QtCore.QRectF:
     """"""
     min_y, max_y = self.get_y_range()
     rect = QtCore.QRectF(
         0,
         min_y,
         len(self._bar_picutures),
         max_y
     )
     return rect
Пример #6
0
    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
Пример #7
0
 def boundingRect(self):
     return QtCore.QRectF(self.picture.boundingRect())