Exemple #1
0
    def atr_break(self, klines):
        if (self.lowrange_back_bar == 0):
            return

        h10_day_bar = 0
        l10_day_bar = 0

        flag = 0
        if (h10_day_bar >= self.lowrange_back_bar and l10_day_bar <=
                self.lowrange_back_bar + self.lowrange_bars + 1):
            flag = 1
        if (l10_day_bar >= self.lowrange_back_bar and l10_day_bar <=
                self.lowrange_back_bar + self.lowrange_bars + 1):
            flag = -1
        if (flag == 0):
            return
        #速度和高度

        h3_day = 0
        l3_day = 0
        avg5 = pplib.get_average(klines, 7)
        if (flag == -1):
            if (avg5 <= l3_day):
                # sell task
                task = TradeFactory.create_target_sell_task
                self.addTradeTask(task)

        if (flag == 1):
            if (avg5 >= h3_day):
                task = TradeFactory.create_target_buy_task
                self.addTradeTask(task)
Exemple #2
0
    def on_bar(self, klines):
        if (self.run_flag == False):
            return
        if (self.init_flag == False):
            self.mark_start_id = klines.iloc[-1].id
            self.init_flag = True

        StrategyBase.on_bar(self, klines)
        self.cur_bar = self.get_current_minute_bar()

        if (self.position == 0 and self.done_flag == False):
            if (self.level == 1):
                self.level_1(klines)
            elif (self.level == 2):
                self.level_2(klines)
            elif (self.level == 3):
                self.level_3(klines)
        '''
        lt = time.localtime(time.time())
        # 开仓时间
        if (lt.tm_hour == 9 and lt.tm_min < 30 or
            lt.tm_hour == 21 and lt.tm_min < 30):
            if(self.position == 0):
                self.open_time(klines, ask_price, bid_price)
            if (self.position != 0):
                hest_inday = self.indictor.get_hest_inday()
                lest_inday = self.indictor.get_lest_inday()
                open_inday = self.indictor.get_open_inday()
                if (open_inday-klines.iloc[-1].close - open_inday > 30):
                    self.stop()
        #  
        '''

        if (self.position != 0):
            self.done_flag = True
            #出场-时间、空间
            #cur_bar = self.get_current_minute_bar()
            hest_bar = pplib.get_highest_bar_today_fix(klines)
            #if ((self.cur_bar-self.entry_bar>90) or (self.cur_bar_id-hest_bar>30)):
            if ((self.cur_bar - self.entry_bar > 90)):
                l_checksum = pplib.get_checksum(klines, 17, 2)
                if (abs(l_checksum) < 4):
                    self.debug("持仓时间过长")
                    self.set_position(0)
            if (self.position != 0):
                atr_day = self.indictor.get_atr_daily()
                if (atr_day is None):
                    atr_day = 45
                else:
                    atr_day = atr_day - 10

                if (self.ask_price - self.entry_price > atr_day):
                    self.set_position(0)
                elif (self.ask_price - self.entry_price < -10):
                    avg_p = pplib.get_average(klines, 12)
                    if (avg_p - self.entry_price < -20):
                        self.set_position(0)
Exemple #3
0
 def out_trend(self, klines):
     if (self.ma5 > self.last_inrange_high):
         self.ma50 = pplib.get_average(klines, 50)
         if (self.ma50 > self.last_inrange_high):
             return 1
         elif (self.ma5 > self.last_inrange_high + 30):
             return 1
         else:
             return 0
     elif (self.ma5 > self.last_inrange_low):
         self.ma50 = pplib.get_average(klines, 50)
         if (self.ma50 < self.last_inrange_low):
             return -1
         elif (self.ma5 < self.last_inrange_low - 30):
             return -1
         else:
             return 0
     else:
         return 0
Exemple #4
0
    def find_breakout(self, klines):
        if (self.last_inrange_height > 2 * self.ATR_day
                or self.day_checksum_4 > self.ATR_day * 1.5):
            return 0
        '''
        ret = self.out_trend(klines)
        if (ret == 1):
            if (self.hh_inday_bar>45):
                ret = 0
        elif (ret == -1):
            if (self.ll_inday_bar>45):
                ret = 0
        return ret
        '''
        if (self.ma5 > self.last_inrange_high):
            self.ma50 = pplib.get_average(klines, 50)
            if (self.ma50 > self.last_inrange_high):
                self.info5("find breakout hh by height")
                return 1
            elif (self.ma5 > self.last_inrange_high + 20):
                self.info5("find breakout hh by height")
                return 1
            else:
                return 0
        elif (self.ma5 > self.last_inrange_low):
            self.ma50 = pplib.get_average(klines, 50)
            if (self.ma50 < self.last_inrange_low):
                self.info5("find breakout ll by height")
                return -1
            elif (self.ma5 < self.last_inrange_low - 30):
                self.info5("find breakout ll by height")
                return -1
            else:
                return 0
        else:
            return 0

        return 0
    def drive(self, klines):
        if (self.mark_price == 0):
            self.mark_price = klines.iloc[-1].close

        bar_pas = klines.iloc[-1].id - self.start_barid
        '''

        '''
        dif = self.target_pos - self.init_pos
        cksum_bar = 10
        c_sum = pplib.get_checksum(klines, cksum_bar, 1)
        ma10 = pplib.get_average(klines, 10)

        #监控损失 monitor_loss
        if (self.target_pos == self.position):
            self.run_flag = False
            print("%s finish....." % (self.name))

        #间隔限制
        if (klines.iloc[-1].id - self.exit_bar < 5):
            print("%s gap limit....." % (self.name))
            return
        slice_start = self.time_slice[self.cur_step]
        if (bar_pas < slice_start - 4):
            print("%s time slice limit....." % (self.name))
            return

        if (dif > 0):
            tmp_pos = 0
            if (ma10 > self.mark_price):
                tmp_pos = 1
            if (bar_pas > self.time_slice[self.cur_step][1]):  #超时
                tmp_pos = 1
            if (tmp_pos != 0):
                self.callback.task_callback(self.name, "adjust_position", 1)
                self.exit_bar = klines.iloc[-1].id
                self.position += 1
                self.doit()
        else:
            tmp_pos = 0
            if (ma10 > self.mark_price):
                tmp_pos = -1
            if (bar_pas > self.time_slice[self.cur_step][1]):  #超时
                tmp_pos = -1
            if (tmp_pos != 0):
                self.callback.task_callback(self.name, "adjust_position", -1)
                self.exit_bar = klines.iloc[-1].id
                self.position -= 1
                self.doit()
Exemple #6
0
    def on_bar(self, klines):
        if (self.run_flag == False):
            return
        if (self.mark_start_bar == 0):
            self.mark_start_bar = klines.iloc[-1].id
        StrategyBase.on_bar(self, klines)
        #self.cur_bar = self.get_current_minute_bar()

        if (self.position == 0 and self.done_flag == False):
            if (self.level == 1):
                self.level_1(klines)
            elif(self.level == 2):
                self.level_2(klines)
            elif(self.level == 3):
                self.level_3(klines)
        
        if (self.position != 0):
            #出场-时间、空间

            self.done_flag = True
            cur_bar = self.get_current_minute_bar()
            if ((cur_bar-self.entry_bar>90)):#不用替换_fix
                l_checksum = pplib.get_checksum(klines, 25, 2)
                if (abs(l_checksum) < 5):
                    self.set_position(0)
            if (self.position != 0):
                atr_day = self.indictor.get_atr_daily()
                if (atr_day is None):
                    atr_day = 45
                else:
                    atr_day = atr_day - 10
                
                if (self.entry_price - self.ask_price > atr_day):
                    self.debug("空止盈")
                    self.set_position(0)
                elif(self.ask_price-self.entry_price > 10):
                    avg_p = pplib.get_average(klines, 12)
                    if (avg_p-self.entry_price > 20):
                        self.debug("空止损")
                        self.set_position(0)
Exemple #7
0
    def on_bar(self, klines):
        StrategyBase.on_bar(self, klines)
        #if (self.run_flag == False or self.hh <= 0 or self.ll <= 0):
        if (self.run_flag == False):
            return
        #lt = time.localtime(time.time())
        self.cur_bar = self.get_current_minute_bar()
        lt = self.get_real_time()
        tmp_position = self.position
        if (self.inited == False):
            #init
            self.init()
        if (self.inited == False):
            self.debug("not init")
            return
        if (self.trade_dir != TradeDirection.BUYONLY
                and self.trade_dir != TradeDirection.SELLONLY):
            return
        #===============make==================#
        if (self.position == 0 and self.step == 0):
            if (self.trade_dir == TradeDirection.BUYONLY):
                tmp_position = 1
            elif (self.trade_dir == TradeDirection.SELLONLY):
                tmp_position = -1
        if (self.position == 0 and self.step == 1):
            if (self.trade_dir == TradeDirection.BUYONLY):
                if (self.entry_price - self.ask_price > 10):
                    tmp_position = 1
                else:
                    ck_sum10 = pplib.get_checksum(klines, 11, 1)
                    ma3 = pplib.get_average(klines, 4)
                    hh_20 = pplib.get_hest_in_range(klines, 1, 31)
                    if (abs(ck_sum10) < 5 and hh_20 - ma3 > 15):
                        tmp_position = 1

            elif (self.trade_dir == TradeDirection.SELLONLY):
                if (self.entry_price - self.ask_price > 10):
                    tmp_position = -1
                else:
                    ck_sum10 = pplib.get_checksum(klines, 11, 1)
                    ma3 = pplib.get_average(klines, 4)
                    ll_20 = pplib.get_lest_in_range(klines, 1, 31)
                    if (abs(ck_sum10) < 5 and ma3 - hh_20 > 15):
                        tmp_position = -1

        elif (self.position == 0 and self.step == 2):
            pass

        #==================exit===========================#
        if (self.position == 1):
            if (self.cur_bar - self.entry_bar > 5
                    and self.bid_price - self.entry_price >= self.MAX_EARN):
                tmp_position = 0
            '''
            my_avg_price = pplib.get_avg_price(klines, 10)
            if (self.entry_bar > 10 and my_avg_price < self.avg_price):
                tmp_position = 0
            '''
            if (self.hh != 0 and self.ask_price >= self.hh):
                tmp_position = 0
                self.hh += 20

        if (self.position == -1):
            if (self.cur_bar - self.entry_bar > 5
                    and self.entry_price - self.bid_price >=
                    self.MAX_EARN):  # 达到最大profit
                tmp_position = 0
            '''    
            my_avg_price = pplib.get_avg_price(klines, 10)
            if (self.entry_bar > 10 and my_avg_price > self.avg_price):
                tmp_position = 0
            '''
            if (self.ll != 0 and self.ask_price <= self.ll):
                tmp_position = 0
                self.ll -= 20

        if (tmp_position != self.position):
            self.set_position(tmp_position)

        #===================check==========================#
        if (self.cur_bar_id - self.start_bar_id > 10):  #// 不符合rush条件
            my_avg_price = pplib.get_avg_price(klines, 10)
            if (self.trade_dir == TradeDirection.SELLONLY
                    and my_avg_price > self.mark_price):
                self.stop()
            if (self.trade_dir == TradeDirection.BUYONLY
                    and my_avg_price < self.mark_price):
                self.stop()

        if (self.position != 0):
            self.monitor_position(klines)
Exemple #8
0
    def get_score_inday(self, klines):
        #======================================================#
        #计算得分
        open_score = 0
        trend_score = 0
        o_d_score = 0
        self.score = 0

        lt = self.get_real_time()
        cur_bar = self.get_current_minute_bar()
        #前日高低
        #开仓判断
        if (((lt.tm_hour == 21 or lt.tm_hour == 9) and lt.tm_min < 30
             and lt.tm_min > 5) or (self.open_score == 0 and cur_bar > 30)):
            #跳空 50
            if (cur_bar < 2):
                open_ma5 = klines.iloc[-1].close
            elif (cur_bar < 7):
                open_ma5 = pplib.get_average2(klines, 1, cur_bar - 1)
            else:
                open_ma5 = pplib.get_average2(klines, cur_bar - 6, 6)
            #================================#
            if (lt.tm_hour == 21 and lt.tm_min < 7):
                self.gap_height = open_ma5 - self.lastday_quote[1].close
            elif (lt.tm_hour == 9 and lt.tm_min < 7):
                pre_ma5 = pplib.get_average2(klines, cur_bar + 6, 6)
                self.gap_height = open_ma5 - pre_ma5

            if (self.open_score == 0 and cur_bar > 30):
                open_ma5 = pplib.get_average2(klines, cur_bar - 6, 6)
                self.gap_height = open_ma5 - self.lastday_quote[1].close

            gap_height = self.gap_height

            if (abs(gap_height) > 30):
                open_score = 50
                self.debug("gap_height=%d" % (gap_height))
            elif (abs(gap_height) > 20):
                open_score = 40
                self.debug("gap_height=%d" % (gap_height))
            elif (abs(gap_height) > 15):
                open_score = 25
                self.debug("gap_height=%d" % (gap_height))
            elif (abs(gap_height) > 5):
                open_score = 10
                self.debug("gap_height=%d" % (gap_height))
            elif (abs(gap_height) > 0):
                open_score = 5
                self.debug("gap_height=%d" % (gap_height))
            else:
                open_score = 0

            if (gap_height < 0):
                open_score = -open_score

            #================================#
            #冲高回落50
            hh = pplib.get_highest_price_today(klines)
            ll = pplib.get_lowest_price_today(klines)
            open_p = pplib.get_open_today(klines, 0)

            if (hh > open_p + 15 and hh - self.ask_price > 15):
                open_score = open_score - 30
            if (hh > open_p + 15 and hh - self.ask_price > 15):
                open_score = open_score - 30

            #连续性
            trend_score = 0
            ma5 = pplib.get_average(klines, 6)
            dif = ma5 - open_p
            d_v = int((abs(dif) / 35) * 50)
            if (dif > 0):
                trend_score = d_v
            else:
                trend_score = -d_v
            open_score += trend_score

            self.open_score = open_score
            return self.open_score
        else:
            pass
        #波峰、波谷计算趋势性
        if (cur_bar > 60):
            open_p = pplib.get_open_today(klines, 60)
            m_opens = pplib.get_M_opens(klines, 10)
            m_len = 0
            #===========向下开口得分==============#
            if (m_opens is not None):
                m_len = len(m_opens)
            m_difsum = 0
            if (m_len >= 2):
                for i in range(0, m_len - 1):
                    m_difsum += m_opens.loc[i].high - m_opens.loc[i + 1].high
            if (m_len >= 1):
                m_difsum += m_opens.loc[m_len - 1].high - open_p
            #==========向上开口得分===============#
            w_difsum = 0
            w_opens = pplib.get_W_opens(klines, 20)
            w_len = 0
            if (w_opens is not None):
                w_len = len(w_opens)
            if (w_len >= 2):
                for i in range(0, w_len - 1):
                    w_difsum += w_opens.loc[i].low - w_opens.loc[i + 1].low
            if (w_len >= 1):
                w_difsum += w_opens.loc[w_len - 1].low - open_p
            #=============综合计算===================#
            #是否一致性
            if (self.atr_daily < 40):
                self.atr_daily = 50
            if (w_difsum > 0 and m_difsum > 0):
                a_sum = w_difsum + m_difsum
                '''
                if (w_difsum+m_difsum > self.atr_daily):
                    trend_score = 70
                if (w_difsum+m_difsum > self.atr_daily/2):
                    trend_score = 40
                '''
                a_sum = w_difsum + m_difsum
                ret = abs(a_sum) / self.atr_daily
                if (ret > 1):
                    ret = 1
                trend_score = ret * 100
                trend_score = trend_score + 30
                if (trend_score > 100):
                    trend_score = 100
            elif (w_difsum < 0 and m_difsum < 0):
                a_sum = w_difsum + m_difsum
                ret = abs(a_sum) / self.atr_daily
                if (ret > 1):
                    ret = 1
                trend_score = -ret * 100
                trend_score = trend_score - 30
                if (trend_score < -100):
                    trend_score = -100
            else:
                a_sum = w_difsum + m_difsum
                ret = abs(a_sum) / self.atr_daily
                if (ret > 1):
                    ret = 1
                if (a_sum > 0):
                    trend_score = ret * 100
                else:
                    trend_score = -ret * 100

                if (trend_score < -100):
                    trend_score = -100
                if (trend_score > 100):
                    trend_score = 100

        if (trend_score == 0):  #未形成开口
            l_chsum = pplib.get_checksum(klines, cur_bar, 1)
            hour_pass = (cur_bar / 60) + 1
            d_v = int(abs(l_chsum) / hour_pass)
            if (d_v > 35):
                trend_score = 50
            elif (d_v > 20):
                trend_score = 40
            elif (d_v > 10):
                trend_score = 20
            elif (d_v > 5):
                trend_score = 10

            if (l_chsum < 0):
                trend_score = -trend_score

            self.info("get_score_inday: trend_score=%d" % (trend_score))
        # avg overs、Downs
        # 数量和占比得分
        if (self.avg_overs > self.avg_unders and self.cur_bar > 0):
            if (self.avg_overs > 110 and self.avg_unders < 9):
                o_d_score = 100
            elif (self.avg_overs - self.avg_unders < 20):
                o_d_score = 10
            elif (self.avg_overs / self.cur_bar > 0.9):
                o_d_score = 90
            elif (self.avg_overs / self.cur_bar > 0.8):
                o_d_score = 80
            elif (self.avg_overs / self.cur_bar > 0.7):
                o_d_score = 60
            elif (self.avg_overs / self.cur_bar > 0.6):
                o_d_score = 30
            elif (self.avg_overs / self.cur_bar > 0.5):
                o_d_score = 10
        elif (self.avg_overs < self.avg_unders and self.cur_bar > 0):
            if (self.avg_unders > 110 and self.avg_overs < 9):
                o_d_score = -100
            elif (self.avg_unders - self.avg_overs < 20):
                o_d_score = -10
            elif (self.avg_unders / self.cur_bar > 0.9):
                o_d_score = -90
            elif (self.avg_unders / self.cur_bar > 0.8):
                o_d_score = -80
            elif (self.avg_unders / self.cur_bar > 0.7):
                o_d_score = -60
            elif (self.avg_unders / self.cur_bar > 0.6):
                o_d_score = -30
            elif (self.avg_unders / self.cur_bar > 0.5):
                o_d_score = -10
        #bigbang_down
        if ((self.cur_bar - self.last_bigbang_down < 10)
                and (self.last_bigbang_down < self.last_bigbang_up)):
            #pass
            bar_len = self.get_current_minute_bar()
            if (bar_len > 100):
                bar_len = 100
            #break
            ll_100, ll_100_bar = pplib.get_lest_in_range2(klines, 1, bar_len)
            #高度
            height_100 = pplib.get_height_in_range(klines, 1, bar_len)
            param = ParamUnion()
            param.put_param("height", self.height_12)
            if (ll_100_bar < 10 or height_100 > 45):
                self.manager.drive_event(self.TAG, StgEvent.BigBangBreakDown,
                                         param)
            else:
                self.manager.drive_event(self.TAG, StgEvent.BigBangDown, param)

        if ((self.cur_bar - self.last_bigbang_up < 10)
                and (self.last_bigbang_up < self.last_bigbang_down)):
            #pass
            bar_len = self.get_current_minute_bar()
            if (bar_len > 100):
                bar_len = 100
            #break
            hh_100, hh_100_bar = pplib.get_hest_in_range2(klines, 1, bar_len)
            #高度
            height_100 = pplib.get_height_in_range(klines, 1, bar_len)
            param = ParamUnion()
            param.put_param("height", self.height_12)
            if (hh_100_bar < 10 or height_100 > 45):
                self.manager.drive_event(self.TAG, StgEvent.BigBangBreakUp,
                                         param)
            else:
                self.manager.drive_event(self.TAG, StgEvent.BigBangUp, param)

        #脱离顶底部得分
        distance_score = 0
        hh_inday, hh_inday_bar = pplib.get_highest_bar_today2(
            klines)  #不用替换成_fix
        ll_inday, ll_inday_bar = pplib.get_lowest_bar_today2(klines)
        self.debug("hh_inday=%d hh_inday_bar=%d cur_bar=%d" %
                   (hh_inday, hh_inday_bar, cur_bar))
        self.debug("ll_inday=%d ll_inday_bar=%d" % (ll_inday, ll_inday_bar))
        if (hh_inday_bar < ll_inday_bar and hh_inday_bar > 110):
            distance_score = -30
        elif (hh_inday_bar < ll_inday_bar):
            avg_p = pplib.get_average(klines, 6)
            if (hh_inday_bar < 20):
                if (hh_inday - avg_p < 15):
                    distance_score += 100
                else:
                    distance_score += 60
            elif (hh_inday_bar > 25 and hh_inday_bar < 55):

                if (hh_inday - avg_p < 15):
                    distance_score += 15
                elif (hh_inday - avg_p > 25):
                    distance_score -= 30
                elif (hh_inday - avg_p > 30):
                    distance_score -= 50
            else:
                distance_score -= 30
        elif (hh_inday_bar < ll_inday_bar and ll_inday_bar > 110):
            distance_score = 30
        else:
            avg_p = pplib.get_average(klines, 6)
            if (ll_inday_bar < 20):
                if (avg_p - ll_inday < 15):
                    distance_score -= 100
                else:
                    distance_score -= 60
            elif (ll_inday_bar > 25 and ll_inday_bar < 55):
                if (avg_p - ll_inday < 15):
                    distance_score -= 15
                elif (avg_p - ll_inday > 25):
                    distance_score += 30
                elif (avg_p - ll_inday > 30):
                    distance_score += 50
            else:
                distance_score += 30
            #新高

        #key hour
        if (lt.tm_hour == 9 and lt.tm_min < 20):
            self.key_hour_score = 0
            pass

        if (lt.tm_hour == 13 and lt.tm_min < 40):
            pass
        #根据运行过程
        self.debug(
            "open_score=%d trend_score=%d o_d_score=%d distance_score=%d" %
            (open_score, trend_score, o_d_score, distance_score))
        if (lt.tm_hour == 21):
            self.score = int(self.open_score * 0.3 + o_d_score * 0.6 +
                             distance_score * 0.1)
        else:
            self.score = int(self.open_score * 0.1 + trend_score * 0.3 +
                             o_d_score * 0.5 + distance_score * 0.2)
        self.kpi = self.score
Exemple #9
0
    def generate_hh_ll(self, klines):
        #开仓
        #排列
        swing_hh = self.hh
        swing_ll = self.ll
        hh_msg = "change swing_hh "
        ll_msg = "change swing_ll"
        if (self.m_size > 0 and self.w_size > 0):
            m_ret = self.check_open_queue("m_opens", self.m_opens)
            w_ret = self.check_open_queue("w_opens", self.w_opens)
            #swing_hh = self.m_opens.loc[0].high + 40
            #swing_ll = self.w_opens.loc[0].low - 40
            if (m_ret == 1 and w_ret == 1):
                #几浪
                if (self.m_size > 3):
                    swing_hh = self.m_opens.loc[0].high + 2
                    swing_ll = swing_hh - 30
                elif (self.m_size > 2):
                    swing_hh = self.m_opens.loc[0].high + 10
                    swing_ll = pplib.get_lest_in_range(klines, 1, 51)
                elif (self.m_size > 1):
                    swing_hh = self.m_opens.loc[0].high + 20
                    swing_ll = pplib.get_lest_in_range(klines, 1, 31)
                else:
                    swing_hh = self.m_opens.loc[0].high + 38
                    swing_ll = pplib.get_lest_in_range(klines, 1, 21)
                hh_msg = "排列多"
                ll_msg = "排列多"
            elif (m_ret == -1 and w_ret == -1):
                #几浪
                if (self.w_size > 3):
                    swing_ll = self.m_opens.loc[0].low - 2
                    swing_hh = swing_ll + 30
                elif (self.w_size > 2):
                    swing_ll = self.m_opens.loc[0].low - 10
                    swing_hh = pplib.get_hest_in_range(klines, 1, 51)
                elif (self.w_size > 1):
                    swing_ll = self.m_opens.loc[0].low - 20
                    swing_hh = pplib.get_hest_in_range(klines, 1, 31)
                else:
                    swing_ll = self.m_opens.loc[0].low - 38
                    swing_hh = pplib.get_hest_in_range(klines, 1, 21)
                hh_msg = "排列空"
                ll_msg = "排列空"
            else:
                #未突破
                hh_msg = "找swing_high"
                ll_msg = "找swing_low"
                range_heigh_8 = pplib.get_height_in_range(klines, 1, 8)
                l_cksum = pplib.get_checksum(klines, 10, 1)
                avg_price = pplib.get_average(klines, 6)
                if (self.w_opens.loc[0].lcount > 60):
                    #突破
                    '''
                    swing_hh = self.w_opens.loc[0].close + 20
                    if(self.w_size > 2):
                        swing_ll = self.w_opens.loc[0].low-15
                    if (self.w_size >= 1):
                        swing_ll = self.w_opens.loc[0].low-25
                    '''
                    if (abs(avg_price - self.w_opens.loc[0].low) < 3
                            and range_heigh_8 < 15 and l_cksum < 0
                            and l_cksum > -15):
                        swing_ll = avg_price
                        ll_msg = "在上一个swing_low附近形成震荡"
                    #突破
                    else:
                        #偏空
                        if (self.w_size > 2):
                            swing_ll = self.w_opens.loc[0].low - 8
                            ll_msg = "w_size>2 and ll=swing_low - 8"
                        if (self.w_size >= 1):
                            swing_ll = self.w_opens.loc[0].low - 15
                            ll_msg = "w_size>2 and ll=swing_low - 15"
                        if (self.get_kpi_daily() > 10):
                            swing_ll += int(self.get_kpi_daily() / 10) + 1
                            ll_msg += "调整%d" % (
                                int(self.get_kpi_daily() / 10) + 1)
                elif (self.w_opens.loc[0].lcount < 30
                      and self.w_opens.loc[0].lcount > 60):
                    if (avg_price < self.w_opens.loc[0].close - 8):
                        swing_hh = self.w_opens.loc[0].close
                        swing_ll = self.w_opens.loc[0].close - 28
                        ll_msg = "swing_low 大小桥 ll下移21"
                        hh_msg = "swing_low 大小桥 low变high 阻变支"
                    else:
                        swing_ll = self.w_opens.loc[0].close
                        ll_msg = "swing_low 大小桥 使用swing_low"
                    #突破跟进

                #突破
            if (self.m_opens.loc[0].lcount > 60):
                #突破
                '''
                    swing_hh = self.w_opens.loc[0].close + 20
                    if(self.w_size > 2):
                        swing_ll = self.w_opens.loc[0].low-15
                    if (self.w_size >= 1):
                        swing_ll = self.w_opens.loc[0].low-25
                    '''
                if (abs(avg_price - self.m_opens.loc[0].high) < 3
                        and range_heigh_8 < 15 and l_cksum > 0
                        and l_cksum < 15):
                    swing_hh = avg_price
                    hh_msg = "swing_high 使用swing_high附件avg_price"
                #突破
                else:
                    #偏空
                    if (self.m_size > 2):
                        swing_hh = self.m_opens.loc[0].high + 8
                        hh_msg = "m_size > 2 swing_high0+8"
                    if (self.m_size >= 1):
                        swing_hh = self.m_opens.loc[0].high + 15
                        hh_msg = "m_size >= 1 swing_high0+15"
                    if (self.get_kpi_daily() < -10):
                        swing_hh += int(self.get_kpi_daily() / 10) + 1
                        hh_msg += "调整%d" % (int(self.get_kpi_daily() / 10) + 1)
            elif (self.m_opens.loc[0].lcount < 30
                  and self.m_opens.loc[0].lcount > 60):
                if (avg_price > self.m_opens.loc[0].close + 5):
                    swing_ll = self.m_opens.loc[0].close - 5
                    swing_hh = self.m_opens.loc[0].close + 25
                    hh_msg = "swing_high 上移21"
                    ll_msg = "swing_high0-5 变ll"
                else:
                    swing_hh = self.m_opens.loc[0].high
                    hh_msg = "大小乔 使用swing_high"
        #
        elif (self.m_size > 0):
            #强升
            m_ret = self.check_open_queue("m_opens", self.m_opens)
            if (m_ret == 1 and self.cur_bar < 110
                    and self.get_kpi_daily() > 30):
                ll_10 = pplib.get_lest_in_range(klines, 1, 11)
                swing_ll = ll_10
                ll_msg = "强升,ll=ll_10"

        elif (self.w_size > 0):
            #强降
            m_ret = self.check_open_queue("w_opens", self.m_opens)
            if (m_ret == -1 and self.cur_bar < 110
                    and self.get_kpi_daily() < -30):
                hh_10 = pplib.get_hest_in_range(klines, 1, 11)
                swing_hh = hh_10
                hh_msg = "强降,hh=hh_10"
        elif (self.cur_bar > 50):
            avg_price = pplib.get_average(klines, 5)
            open_p = self.get_open_price()
            if (avg_price > open_p):
                swing_ll = pplib.get_lest_in_range(klines, 1, 11)
                ll_msg = "流畅上升,ll=ll_10"
            elif (open_p > avg_price):
                swing_hh = pplib.get_hest_in_range(klines, 1, 11)
                hh_msg = "流畅下降,hh=hh_10"
        elif (self.cur_bar < 50):
            ups = pplib.get_count_of_greater(klines, self.cur_bar)
            downs = pplib.get_count_of_less(klines, self.cur_bar)
            if (ups > self.ups_at_open):
                self.ups_at_open = ups
            if (downs > self.downs_at_open):
                self.downs_at_open = downs
            if (self.cur_bar > 25 and self.downs_at_open < 10):
                avg_price = pplib.get_average(klines, 9)
                ll_msg = "未形成swing前强升,ll=lavg9"
                swing_ll = avg_price
            if (self.cur_bar > 25 and self.downs_at_open < 10):
                avg_price = pplib.get_average(klines, 9)
                hh_msg = "未形成swing前强降,hh=avg9"
                swing_hh = avg_price
        if (self.hh == 0):
            swing_hh = self.get_open_price + self.get_atr_daily()
            hh_msg = "hh=0, hh=open+atr"
        elif (self.hh < self.ask_price - 10):
            #突破
            avg_price = pplib.get_average(klines, 15)
            if (avg_price > self.hh + 5):
                swing_ll = self.hh
                swing_hh = self.ask_price + 25
                hh_msg = "逃出区间, hh=cur_price+25"
                ll_msg = "逃出区间, ll = last_hh"

        if (self.ll == 0):
            swing_ll = self.get_open_price - self.get_atr_daily()
            ll_msg = "ll = 0, ll=open-atr"
        elif (self.ll > self.ask_price + 10):
            avg_price = pplib.get_average(klines, 15)
            if (avg_price < self.ll - 5):
                swing_hh = self.ll
                swing_ll = self.ask_price - 23
                hh_msg = "逃出区间, hh=swing+25"
                ll_msg = "逃出区间, ll = cur_price-23"

        if (swing_hh != self.hh):
            self.change_hh(swing_hh, hh_msg)
        if (swing_ll != self.ll):
            self.change_ll(swing_ll, ll_msg)