Python pyqtgraph.ArrowItem() Examples

The following are 17 code examples of pyqtgraph.ArrowItem(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyqtgraph , or try the search function .
Example #1
Source File: uiBasicWidget.py    From InplusTrader_Linux with MIT License 6 votes vote down vote up
def plotText(self):
        """开平仓信号"""
        lenClose = len(self.listClose)

        if lenClose >= 5:                                       # Fractal Signal
            if self.listClose[-1] > self.listClose[-2] and self.listClose[-3] > self.listClose[-2] and self.listClose[-4] > self.listClose[-2] and self.listClose[-5] > self.listClose[-2] and self.listfastEMA[-1] > self.listslowEMA[-1]:
                ## Draw an arrowhead next to the text box
                # self.pw2.removeItem(self.arrow)
                self.arrow = pg.ArrowItem(pos=(lenClose-1, self.listLow[-1]), angle=90, brush=(255, 0, 0))
                self.pw2.addItem(self.arrow)
            elif self.listClose[-1] < self.listClose[-2] and self.listClose[-3] < self.listClose[-2] and self.listClose[-4] < self.listClose[-2] and self.listClose[-5] < self.listClose[-2] and self.listfastEMA[-1] < self.listslowEMA[-1]:
                ## Draw an arrowhead next to the text box
                # self.pw2.removeItem(self.arrow)
                self.arrow = pg.ArrowItem(pos=(lenClose-1, self.listHigh[-1]), angle=-90, brush=(0, 255, 0))
                self.pw2.addItem(self.arrow)

    #---------------------------------------------------------------------- 
Example #2
Source File: uiBasicWidget修改.py    From chanlun with MIT License 6 votes vote down vote up
def plotText(self):
        lenClose = len(self.listClose)

        if lenClose >= 5:                                       # Fractal Signal
            if self.listClose[-1] > self.listClose[-2] and self.listClose[-3] > self.listClose[-2] and self.listClose[-4] > self.listClose[-2] and self.listClose[-5] > self.listClose[-2] and self.listfastEMA[-1] > self.listslowEMA[-1]:
                ## Draw an arrowhead next to the text box
                # self.pw2.removeItem(self.arrow)
                self.arrow = pg.ArrowItem(pos=(lenClose-1, self.listLow[-1]), angle=90, brush=(255, 0, 0))
                self.pw2.addItem(self.arrow)
            elif self.listClose[-1] < self.listClose[-2] and self.listClose[-3] < self.listClose[-2] and self.listClose[-4] < self.listClose[-2] and self.listClose[-5] < self.listClose[-2] and self.listfastEMA[-1] < self.listslowEMA[-1]:
                ## Draw an arrowhead next to the text box
                # self.pw2.removeItem(self.arrow)
                self.arrow = pg.ArrowItem(pos=(lenClose-1, self.listHigh[-1]), angle=-90, brush=(0, 255, 0))
                self.pw2.addItem(self.arrow)

    #---------------------------------------------------------------------- 
Example #3
Source File: demoUi.py    From chanlun with MIT License 6 votes vote down vote up
def plotText(self):
        lenClose = len(self.listClose)

        if lenClose >= 5:                                       # Fractal Signal
            if self.listClose[-1] > self.listClose[-2] and self.listClose[-3] > self.listClose[-2] and self.listClose[-4] > self.listClose[-2] and self.listClose[-5] > self.listClose[-2] and self.listfastEMA[-1] > self.listslowEMA[-1]:
                ## Draw an arrowhead next to the text box
                # self.pw2.removeItem(self.arrow)
                self.arrow = pg.ArrowItem(pos=(lenClose-1, self.listLow[-1]), angle=90, brush=(255, 0, 0))
                self.pw2.addItem(self.arrow)
            elif self.listClose[-1] < self.listClose[-2] and self.listClose[-3] < self.listClose[-2] and self.listClose[-4] < self.listClose[-2] and self.listClose[-5] < self.listClose[-2] and self.listfastEMA[-1] < self.listslowEMA[-1]:
                ## Draw an arrowhead next to the text box
                # self.pw2.removeItem(self.arrow)
                self.arrow = pg.ArrowItem(pos=(lenClose-1, self.listHigh[-1]), angle=-90, brush=(0, 255, 0))
                self.pw2.addItem(self.arrow)

    #---------------------------------------------------------------------- 
Example #4
Source File: demoUi.py    From chanlun with MIT License 6 votes vote down vote up
def initplotKline(self):
        """Kline"""
        self.pw2 = pg.PlotWidget(name='Plot2')  # K线图
        self.vbl_2.addWidget(self.pw2)
        self.pw2.setDownsampling(mode='peak')
        self.pw2.setClipToView(True)

        self.curve5 = self.pw2.plot()
        self.curve6 = self.pw2.plot()

        self.candle = self.CandlestickItem(self.listBar)
        self.pw2.addItem(self.candle)
        ## Draw an arrowhead next to the text box
        # self.arrow = pg.ArrowItem()
        # self.pw2.addItem(self.arrow)

    #---------------------------------------------------------------------- 
Example #5
Source File: uiKLine.py    From uiKLine with MIT License 6 votes vote down vote up
def plotMark(self):
        """显示开平仓信号"""
        # 检查是否有数据
        if len(self.datas)==0:
            return
        for arrow in self.arrows:
            self.pwKL.removeItem(arrow)
        # 画买卖信号
        for i in range(len(self.listSig)):
            # 无信号
            if self.listSig[i] == 0:
                continue
            # 买信号
            elif self.listSig[i] > 0:
                arrow = pg.ArrowItem(pos=(i, self.datas[i]['low']),  angle=90, brush=(255, 0, 0))
            # 卖信号
            elif self.listSig[i] < 0:
                arrow = pg.ArrowItem(pos=(i, self.datas[i]['high']), angle=-90, brush=(0, 255, 0))
            self.pwKL.addItem(arrow)
            self.arrows.append(arrow)

    #---------------------------------------------------------------------- 
Example #6
Source File: uiKLine.py    From uiKLine with MIT License 5 votes vote down vote up
def plotIndex_LIMIT (self):
        """画指标"""
        # 检查是否有数据
        if len(self.KLINE_SHORT_TERM_LIST_LIMIT)==0 :
            self.refresh()   
            return
        for arrow in self.KLINE_SHORT_TERM_LIST_LIMIT_arrows:
            self.pwKL.removeItem(arrow)      
        for curves in self.KLINE_SHORT_TERM_LIST_LIMIT_curves:
            self.pwKL.removeItem(curves)              
        for i in range(len(self.KLINE_SHORT_TERM_LIST_LIMIT)):
            if  self.KLINE_SHORT_TERM_LIST_LIMIT[i] == 1:
                arrow = pg.ArrowItem(pos=(i, self.datas[i]['low']), size=7,tipAngle=55,tailLen=3,tailWidth=4, angle=90, brush=(34, 139, 34),pen=({'color': "228B22", 'width': 1}))   
                self.pwKL.addItem(arrow)
                self.KLINE_SHORT_TERM_LIST_LIMIT_arrows.append(arrow)    
            if  self.KLINE_SHORT_TERM_LIST_LIMIT[i] == 2:  
                arrow = pg.ArrowItem(pos=(i, self.datas[i]['high']),size=7,tipAngle=55,tailLen=3,tailWidth=4 ,angle=-90, brush=(34, 139, 34),pen=({'color': "228B22", 'width': 1}))
                self.pwKL.addItem(arrow)
                self.KLINE_SHORT_TERM_LIST_LIMIT_arrows.append(arrow)   
        last_x=-1  #上一个x
        last_y=-1  #上一个y   
        last_v=-1
        for i in range(len(self.KLINE_SHORT_TERM_LIST_LIMIT)):
            if  self.KLINE_SHORT_TERM_LIST_LIMIT[i] != 0 :
                if    last_x!=-1 and last_y!=-1 and  last_v!=self.KLINE_SHORT_TERM_LIST_LIMIT[i] and\
                    ((last_v == 1 and self.KLINE_SHORT_TERM_LIST_LIMIT[i] == 2) and self.KLINE_LOW[last_x]<self.KLINE_HIGH[i]) or\
                    ((last_v == 2 and self.KLINE_SHORT_TERM_LIST_LIMIT[i] == 1) and self.KLINE_HIGH[last_x]>self.KLINE_LOW[i]):
                        curve = pg.PlotCurveItem(x=np.array([last_x,i]),y=np.array([last_y,self.datas[i]['low'] if self.KLINE_SHORT_TERM_LIST_LIMIT[i]==1 else self.datas[i]['high']]),name='duo',pen=({'color': "228B22", 'width': 1}))                 
                        self.pwKL.addItem(curve)          
                        self.KLINE_SHORT_TERM_LIST_LIMIT_curves.append(curve)    
                last_x =i
                if  self.KLINE_SHORT_TERM_LIST_LIMIT[i]  ==1 :  
                    last_y=self.datas[i]['low']     
                elif self.KLINE_SHORT_TERM_LIST_LIMIT[i] ==2 :  
                    last_y=self.datas[i]['high']   
                last_v=self.KLINE_SHORT_TERM_LIST_LIMIT[i]
                
    #---------------------------------------------------------------------- 
Example #7
Source File: uiBasicWidget.py    From InplusTrader_Linux with MIT License 5 votes vote down vote up
def initplotKline(self):
        """Kline"""
        self.pw2 = pg.PlotWidget(name='Plot2')  # K线图
        self.vbl_2.addWidget(self.pw2)
        self.pw2.setDownsampling(mode='peak')
        self.pw2.setClipToView(True)

        self.curve5 = self.pw2.plot()
        self.curve6 = self.pw2.plot()

        self.candle = self.CandlestickItem(self.listBar)
        self.pw2.addItem(self.candle)
        ## Draw an arrowhead next to the text box
        # self.arrow = pg.ArrowItem()
        # self.pw2.addItem(self.arrow)

    #---------------------------------------------------------------------- 
Example #8
Source File: uiChanlunWidget.py    From chanlun with MIT License 5 votes vote down vote up
def initplotKline(self):
        """Kline"""
        s = self.data.index  #横坐标值
        print "numbers of KLine: ", len(s)
        xdict = dict(enumerate(s))
        self.__axisTime = MyStringAxis(xdict, orientation='bottom')
        self.pw2 = pg.PlotWidget(axisItems={'bottom': self.__axisTime})  # K线图
        pw2x = self.pw2.getAxis('bottom')
        pw2x.setGrid(150)  # 设置默认x轴网格
        pw2y = self.pw2.getAxis('left')
        pw2y.setGrid(150)  # 设置默认y轴网格
        self.vbl_1.addWidget(self.pw2)
        self.pw2.setMinimumWidth(1500)
        self.pw2.setMaximumWidth(1800)
        self.pw2.setDownsampling(mode='peak')
        self.pw2.setClipToView(True)

        self.curve5 = self.pw2.plot()
        self.curve6 = self.pw2.plot()

        self.candle = self.CandlestickItem(self.listBar)
        self.pw2.addItem(self.candle)
        ## Draw an arrowhead next to the text box
        # self.arrow = pg.ArrowItem()
        # self.pw2.addItem(self.arrow)


    # 从数据库读取一分钟数据画分钟线 
Example #9
Source File: uiBasicWidget修改.py    From chanlun with MIT License 5 votes vote down vote up
def initplotKline(self):
        """Kline"""
        self.pw2 = pg.PlotWidget(name='Plot2')  # K线图
        self.vbl_2.addWidget(self.pw2)
        self.pw2.setDownsampling(mode='peak')
        self.pw2.setClipToView(True)

        self.curve5 = self.pw2.plot()
        self.curve6 = self.pw2.plot()

        self.candle = self.CandlestickItem(self.listBar)
        self.pw2.addItem(self.candle)
        ## Draw an arrowhead next to the text box
        # self.arrow = pg.ArrowItem()
        # self.pw2.addItem(self.arrow)

    #---------------------------------------------------------------------- 
Example #10
Source File: base.py    From kite with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, model):
        pg.GraphicsWidget.__init__(self)
        pg.GraphicsWidgetAnchor.__init__(self)

        self.model = model

        self.arrow = pg.ArrowItem(
            parent=self,
            angle=0.,
            brush=(0, 0, 0, 180),
            pen=(255, 255, 255),
            pxMode=True)

        self.label = pg.LabelItem(
            'Towards Sat.',
            justify='right', size='8pt',
            parent=self)
        self.label.anchor(
            itemPos=(1., -1.),
            parentPos=(1., 0.))
        # self.label.setBrush(pg.mkBrush(255, 255, 255, 180))
        # self.label.setFont(QtGui.QFont(
        #     "Helvetica", weight=QtGui.QFont.DemiBold))

        self.orientArrow()
        self.model.sigSceneChanged.connect(self.orientArrow)
        self.setFlag(self.ItemIgnoresTransformations) 
Example #11
Source File: uiKLine.py    From uiKLine with MIT License 5 votes vote down vote up
def plot_GJR_SELL(self):
        """画攻击日卖出箭头"""
        # 检查是否有数据
        if len(self.KLINE_GJR_SELL)==0 :
            self.refresh()            
            return
        for arrow in self.KLINE_GJR_SELL_arrows:
            self.pwKL.removeItem(arrow)    
        for i in range(len(self.KLINE_GJR_SELL)):
            if  self.KLINE_GJR_SELL[i] == 1:
                arrow = pg.ArrowItem(pos=(i, self.datas[i]['high']+50), size=7,tipAngle=55,tailLen=3,tailWidth=4, angle=-90, brush=("C0FF3E"),pen=({'color': "C0FF3E", 'width': 1}))   
                self.pwKL.addItem(arrow)
                self.KLINE_GJR_SELL_arrows.append(arrow)    
    #---------------------------------------------------------------------- 
Example #12
Source File: uiKLine.py    From uiKLine with MIT License 5 votes vote down vote up
def plot_WAIBAORI(self):
        """画外包日箭头"""
        # 检查是否有数据
        if len(self.KLINE_WAIBAORI)==0 :
            self.refresh()            
            return
        for arrow in self.KLINE_WAI_BAO_RI_arrows:
            self.pwKL.removeItem(arrow)    
        for i in range(len(self.KLINE_WAIBAORI)):
            if  self.KLINE_WAIBAORI[i] == 1:
                arrow = pg.ArrowItem(pos=(i, self.datas[i]['low']-100), size=7,tipAngle=55,tailLen=3,tailWidth=4, angle=90, brush=(255, 255, 0),pen=({'color': "FF0000", 'width': 1}))   
                self.pwKL.addItem(arrow)
                self.KLINE_WAI_BAO_RI_arrows.append(arrow)     
    #---------------------------------------------------------------------- 
Example #13
Source File: uiKLine.py    From uiKLine with MIT License 5 votes vote down vote up
def plotIndex_FIRST (self):
        """画指标"""
        # 检查是否有数据
        if len(self.KLINE_SHORT_TERM_LIST_FIRST)==0 :
            self.refresh()   
            return
        for arrow in self.KLINE_SHORT_TERM_LIST_FIRST_arrows:
            self.pwKL.removeItem(arrow)     
        for curves in self.KLINE_SHORT_TERM_LIST_FIRST_curves:
            self.pwKL.removeItem(curves)              
        for i in range(len(self.KLINE_SHORT_TERM_LIST_FIRST)):
            if  self.KLINE_SHORT_TERM_LIST_FIRST[i] == 1:
                arrow = pg.ArrowItem(pos=(i, self.datas[i]['low']), size=7,tipAngle=55,tailLen=3,tailWidth=4, angle=90, brush=(225, 255, 0),pen=({'color': "FFFF00", 'width': 1}))   
                self.pwKL.addItem(arrow)
                self.KLINE_SHORT_TERM_LIST_FIRST_arrows.append(arrow)    
            if  self.KLINE_SHORT_TERM_LIST_FIRST[i] == 2:  
                arrow = pg.ArrowItem(pos=(i, self.datas[i]['high']),size=7,tipAngle=55,tailLen=3,tailWidth=4 ,angle=-90, brush=(225, 255, 0),pen=({'color': "FFFF00", 'width': 1}))
                self.pwKL.addItem(arrow)
                self.KLINE_SHORT_TERM_LIST_FIRST_arrows.append(arrow)   
        last_x=-1  #上一个x
        last_y=-1  #上一个y   
        last_v=-1
        for i in range(len(self.KLINE_SHORT_TERM_LIST_FIRST)):
            if  self.KLINE_SHORT_TERM_LIST_FIRST[i] != 0 :
                if    last_x!=-1 and last_y!=-1 and  last_v!=self.KLINE_SHORT_TERM_LIST_FIRST[i] and\
                    ((last_v == 1 and self.KLINE_SHORT_TERM_LIST_FIRST[i] == 2) and self.KLINE_LOW[last_x]<self.KLINE_HIGH[i]) or\
                    ((last_v == 2 and self.KLINE_SHORT_TERM_LIST_FIRST[i] == 1) and self.KLINE_HIGH[last_x]>self.KLINE_LOW[i]):
                        curve = pg.PlotCurveItem(x=np.array([last_x,i]),y=np.array([last_y,self.datas[i]['low'] if self.KLINE_SHORT_TERM_LIST_FIRST[i]==1 else self.datas[i]['high']]),name='duo',pen=({'color': "FFFF00", 'width': 1}))                 
                        self.pwKL.addItem(curve)          
                        self.KLINE_SHORT_TERM_LIST_FIRST_curves.append(curve)    
                last_x =i
                if  self.KLINE_SHORT_TERM_LIST_FIRST[i]  ==1 :  
                    last_y=self.datas[i]['low']     
                elif self.KLINE_SHORT_TERM_LIST_FIRST[i] ==2 :  
                    last_y=self.datas[i]['high']   
                last_v=self.KLINE_SHORT_TERM_LIST_FIRST[i]
    #---------------------------------------------------------------------- 
Example #14
Source File: uiKLine.py    From uiKLine with MIT License 5 votes vote down vote up
def plotIndex_ALL (self):
        """画指标"""
        # 检查是否有数据
        if len(self.KLINE_SHORT_TERM_LIST_ALL)==0 :
            self.refresh()            
            return
        for arrow in self.KLINE_SHORT_TERM_LIST_ALL_arrows:
            self.pwKL.removeItem(arrow)     
        for curves in self.KLINE_SHORT_TERM_LIST_ALL_curves:
            self.pwKL.removeItem(curves)              
        for i in range(len(self.KLINE_SHORT_TERM_LIST_ALL)):
            if  self.KLINE_SHORT_TERM_LIST_ALL[i] == 1:
                arrow = pg.ArrowItem(pos=(i, self.datas[i]['low']), size=7,tipAngle=55,tailLen=3,tailWidth=4, angle=90, brush=(225, 0, 225),pen=({'color': "FF00FF", 'width': 1}))   
                self.pwKL.addItem(arrow)
                self.KLINE_SHORT_TERM_LIST_ALL_arrows.append(arrow)    
            if  self.KLINE_SHORT_TERM_LIST_ALL[i] == 2:  
                arrow = pg.ArrowItem(pos=(i, self.datas[i]['high']),size=7,tipAngle=55,tailLen=3,tailWidth=4 ,angle=-90, brush=(225, 0, 225),pen=({'color': "FF00FF", 'width': 1}))
                self.pwKL.addItem(arrow)
                self.KLINE_SHORT_TERM_LIST_ALL_arrows.append(arrow)   
        last_x=-1  #上一个x
        last_y=-1  #上一个y   
        last_v=-1
        for i in range(len(self.KLINE_SHORT_TERM_LIST_ALL)):
            if  self.KLINE_SHORT_TERM_LIST_ALL[i] != 0 :
                if    last_x!=- 1 and last_y!=-1                              and                                                \
                    ((last_v == 1 and self.KLINE_SHORT_TERM_LIST_ALL[i] == 2) and self.KLINE_LOW[last_x]<self.KLINE_HIGH[i]) or  \
                    ((last_v == 2 and self.KLINE_SHORT_TERM_LIST_ALL[i] == 1) and self.KLINE_HIGH[last_x]>self.KLINE_LOW[i]) or  \
                    ((last_v == 1 and self.KLINE_SHORT_TERM_LIST_ALL[i] == 1))                                                or  \
                    ((last_v == 2 and self.KLINE_SHORT_TERM_LIST_ALL[i] == 2))                                                    :
                        curve = pg.PlotCurveItem(x=np.array([last_x,i]),y=np.array([last_y,self.datas[i]['low'] if self.KLINE_SHORT_TERM_LIST_ALL[i]==1 else self.datas[i]['high']]),name='duo',pen=({'color': "FF00FF", 'width': 1}))                 
                        self.pwKL.addItem(curve)          
                        self.KLINE_SHORT_TERM_LIST_ALL_curves.append(curve)    
                last_x =i
                if  self.KLINE_SHORT_TERM_LIST_ALL[i]  ==1 :  
                    last_y=self.datas[i]['low']     
                elif self.KLINE_SHORT_TERM_LIST_ALL[i] ==2 :  
                    last_y=self.datas[i]['high']   
                last_v=self.KLINE_SHORT_TERM_LIST_ALL[i]                
    #---------------------------------------------------------------------- 
Example #15
Source File: uiKLine.py    From vnpy_crypto with MIT License 4 votes vote down vote up
def add_signal(self, t_value, direction, offset, price, volume):
        """
        增加信号
        :param t_value:
        :param direction:
        :param offset:
        :param price:
        :param volume:
        :return:
        """
        # 找到信号时间最贴近的bar x轴
        x = self.axisTime.get_x_by_time(t_value)
        need_plot_arrow = False

        # 修正一下 信号时间,改为bar的时间
        if x not in self.x_t_trade_map:
            bar_time = self.axisTime.xdict.get(x, t_value)
        else:
            # 如果存在映射,就更新
            bar_time = self.x_t_trade_map[x]

        trade_node = self.t_trade_dict.get(bar_time, None)
        if trade_node is None:
            # 当前时间无交易信号
            self.t_trade_dict[bar_time] = {'x': x, 'signals': [{'direction': direction, 'offset':offset,'price': price,'volume': volume}]}
            self.x_t_trade_map[x] = bar_time
            need_plot_arrow = True
        else:
            #match_signals = [t for t in trade_node['signals'] if t['direction'] == direction and t['offset'] == offset]
            #if len(match_signals) == 0:
            need_plot_arrow = True
            trade_node['signals'].append({'direction': direction, 'offset':offset, 'price': price, 'volume': volume})
            self.x_t_trade_map[x] = bar_time

        # 需要显示图标
        if need_plot_arrow:
            arrow = None
            # 多信号
            if direction == DIRECTION_LONG:
                if offset == OFFSET_OPEN:
                    # buy
                    arrow = pg.ArrowItem(pos=(x, price), angle=135, brush=None, pen={'color':'r','width':1}, tipAngle=30, baseAngle=20, tailLen=10, tailWidth=2)
                else:
                    # cover
                    arrow = pg.ArrowItem(pos=(x, price), angle=0, brush=(255, 0, 0),pen=None, headLen=20, headWidth=20, tailLen=10, tailWidth=2)
            # 空信号
            elif direction == DIRECTION_SHORT:
                if offset == OFFSET_CLOSE:
                    # sell
                    arrow = pg.ArrowItem(pos=(x, price), angle=0, brush=(0, 255, 0),pen=None ,headLen=20, headWidth=20, tailLen=10, tailWidth=2)
                else:
                    # short
                    arrow = pg.ArrowItem(pos=(x, price), angle=-135, brush=None, pen={'color':'g','width':1},tipAngle=30, baseAngle=20, tailLen=10, tailWidth=2)
            if arrow:
                self.pi_main.addItem(arrow)
                self.list_trade_arrow.append(arrow) 
Example #16
Source File: uiKLine.py    From uiKLine with MIT License 4 votes vote down vote up
def plotMark(self):
        """显示开平仓信号"""
        # 检查是否有数据
        if len(self.datas)==0:
            return
        for arrow in self.arrows:
            self.pwKL.removeItem(arrow)
        for curve in self.curves:
            self.pwKL.removeItem(curve)
        # 画买卖信号
        lastbk_x=-1  #上一个买开的x
        lastbk_y=-1  #上一个买开的y
        lastsk_x=-1  #上一个卖开的x
        lastsk_y=-1  #上一个卖开的y        
        for i in range(len(self.listSig_deal_DIRECTION)):
            # 无信号
            if   cmp(self.listSig_deal_DIRECTION[i] , '-')== 0 or cmp(self.listSig_deal_OFFSET[i] , '-') == 0:
                continue
            # 买开信号
            elif cmp(self.listSig_deal_DIRECTION[i] , '多')==0 and cmp(self.listSig_deal_OFFSET[i] , '开仓')==0 :
                arrow = pg.ArrowItem(pos=(i, self.datas[i]['low']), size=7,tipAngle=55,tailLen=3,tailWidth=4, angle=90, brush=(255, 0, 0),pen=({'color': "r", 'width': 1}))
                lastbk_x = i
                lastbk_y = self.datas[i]['close']
            # 卖平信号
            elif cmp(self.listSig_deal_DIRECTION[i] , '空')==0  and cmp(self.listSig_deal_OFFSET[i] , '平仓')==0 :
                arrow = pg.ArrowItem(pos=(i, self.datas[i]['high']),size=7,tipAngle=55,tailLen=3,tailWidth=4 ,angle=-90, brush=(0, 0, 0),pen=({'color': "g", 'width': 1}))
                if lastbk_x !=-1:
                    curve = pg.PlotCurveItem(x=np.array([lastbk_x,i]),y=np.array([lastbk_y,self.datas[i][self.SP_signal]]),name='duo',pen=({'color': "r", 'width': 3})) 
                    self.pwKL.addItem(curve)          
                    self.curves.append(curve)  
                    lastbk_x = -1
            # 卖开信号
            elif cmp(self.listSig_deal_DIRECTION[i] , '空')==0  and cmp(self.listSig_deal_OFFSET[i] , '开仓')==0 :
                arrow = pg.ArrowItem(pos=(i, self.datas[i]['high']),size=7,tipAngle=55,tailLen=3,tailWidth=4,angle=-90, brush=(0, 255, 0),pen=({'color': "g", 'width': 1}))
                lastsk_x = i
                lastsk_y = self.datas[i]['close']                
            # 买平信号
            elif cmp(self.listSig_deal_DIRECTION[i] , '多')==0  and cmp(self.listSig_deal_OFFSET[i] , '平仓')==0 :
                arrow = pg.ArrowItem(pos=(i, self.datas[i]['low']),size=7,tipAngle=55,tailLen=3,tailWidth=4 ,angle=90, brush=(0, 0, 0),pen=({'color': "r", 'width': 1}))
                if lastsk_x !=-1:
                    curve = pg.PlotCurveItem(x=np.array([lastsk_x,i]),y=np.array([lastsk_y,self.datas[i][self.BP_signal]]),pen=({'color': "g", 'width': 3})) 
                    self.pwKL.addItem(curve)          
                    self.curves.append(curve)  
                    lastsk_x = -1
            self.pwKL.addItem(arrow)
            self.arrows.append(arrow)                
    #---------------------------------------------------------------------- 
Example #17
Source File: charts.py    From Quantdom with Apache License 2.0 4 votes vote down vote up
def add_signals(self):
        self.signals_group_text = QtGui.QGraphicsItemGroup()
        self.signals_group_arrow = QtGui.QGraphicsItemGroup()
        self.signals_text_items = np.empty(len(Quotes), dtype=object)

        for p in Portfolio.positions:
            x, price = p.id_bar_open, p.open_price
            if p.type == Order.BUY:
                y = Quotes[x].low * 0.99
                pg.ArrowItem(
                    parent=self.signals_group_arrow,
                    pos=(x, y),
                    pen=self.long_pen,
                    brush=self.long_brush,
                    angle=90,
                    headLen=12,
                    tipAngle=50,
                )
                text_sig = CenteredTextItem(
                    parent=self.signals_group_text,
                    pos=(x, y),
                    pen=self.long_pen,
                    brush=self.long_brush,
                    text=('Buy at {:.%df}' % self.digits).format(price),
                    valign=QtCore.Qt.AlignBottom,
                )
                text_sig.hide()
            else:
                y = Quotes[x].high * 1.01
                pg.ArrowItem(
                    parent=self.signals_group_arrow,
                    pos=(x, y),
                    pen=self.short_pen,
                    brush=self.short_brush,
                    angle=-90,
                    headLen=12,
                    tipAngle=50,
                )
                text_sig = CenteredTextItem(
                    parent=self.signals_group_text,
                    pos=(x, y),
                    pen=self.short_pen,
                    brush=self.short_brush,
                    text=('Sell at {:.%df}' % self.digits).format(price),
                    valign=QtCore.Qt.AlignTop,
                )
                text_sig.hide()

            self.signals_text_items[x] = text_sig

        self.chart.addItem(self.signals_group_arrow)
        self.chart.addItem(self.signals_group_text)
        self.signals_visible = True