예제 #1
0
    def make_level(self, klines, open_wait, open_end, open_out, wait_price1, wait_price2):
        if (self.position <= -1):
            return
        '''
        open_wait = 10
        open_end = 30
        open_out = 50
        #monitor_bar = 20
        #wait_price1 = 10
        wait_price2 = 20
        '''

        #lt = self.get_real_time()
        #start_time = tool_utils.datetime_to_localtime(self.mark_start_time)
        min_passed = self.cur_bar_id - self.mark_start_bar
        open_inday = self.get_open_price()
        self.debug("min_passed=%d"%(min_passed))
        # 开仓时间
        if (min_passed > open_wait and min_passed < open_end):
            hh = pplib.get_hest_in_range(klines, 1, open_wait)
            if (hh - open_inday > wait_price1):
                self.set_position(1)
        elif (min_passed > open_end and min_passed < open_out):
            bars = open_end - open_wait
            bars = int(bars/2)
            if (bars < 6):
                bars = 6
            c_sum = pplib.get_checksum(klines, bars, 1)
            hh = pplib.get_hest_in_range(klines, 1, self.cur_bar)
            if (abs(c_sum) < 6 and hh-open_inday> wait_price2):
                self.set_position(-1)
        elif (min_passed > open_out and min_passed < open_out + 120):
            c_sum = pplib.get_checksum(klines, int(open_out/2), 1)
            if (abs(c_sum) < 5):
                self.set_position(-1)
예제 #2
0
 def on_bar_10(self, klines):
     self.range_height_30 = pplib.get_height_in_range(klines, 1, 31)
     if (self.range_height_30 < 20):
         hh = pplib.get_hest_in_range(klines, 1, 30)
         ll = pplib.get_lest_in_range(klines, 1, 30)
         bars = pplib.get_continus_bars_in_height(klines, 1, self.cur_bar,
                                                  hh, ll)  #在区间范围内的bar数
         range_inday = self.hest_inday - self.lest_inday
         if (range_inday > 30):
             # todo: 排除个别
             param = ParamUnion()
             param.put_param("bars", bars)
             param.put_param("height", self.range_height_30)
             avg_10 = pplib.get_avg_price(klines, 11)
             if (self.hest_inday - avg_10 < (avg_10 - self.lest_inday)):
                 self.manager.drive_event(self.TAG, StgEvent.LowRangeAtTop,
                                          range_inday)
             else:
                 self.manager.drive_event(self.TAG,
                                          StgEvent.LowRangeAtBottom,
                                          range_inday)
         else:
             self.manager.drive_event(self.TAG, StgEvent.LowRange,
                                      range_inday)
     self.generate_price_action()
예제 #3
0
    def find_bigbang(self, klines):
        #速度
        ck_sum_10 = pplib.get_checksum(klines, 11, 1)
        if (abs(ck_sum_10) > 10):
            pass
        '''
            msg = "ck_sum_10=%d"%(ck_sum_10)
            self.info(msg)
        '''

        if (ck_sum_10 > self.max_ck_sum):
            self.max_ck_sum = ck_sum_10
            msg = "max_ck_sum_10=%d"%(ck_sum_10)
            self.info(msg)
        if (ck_sum_10 < self.min_ck_sum):
            self.min_ck_sum = ck_sum_10
            msg = "min_ck_sum_10=%d"%(ck_sum_10)
            self.info(msg)

        # 高度
        # cksum 和 height有重复
        height_10 = pplib.get_hest_in_range(klines, 1, 11)
        if (ck_sum_10 > 20 or (height_10> 20 and ck_sum_10>10)):
            self.last_big_up_bang = self.get_current_minute_bar()
            if (height_10 > 25):
                self.strong_level = 2
        if (ck_sum_10 < -20 or (height_10> 20 and ck_sum_10<-10)):
            self.last_big_down_bang = self.get_current_minute_bar()
            if (height_10 > 25):
                self.strong_level = -2
예제 #4
0
 def find_break2(self, klines):
     region_hh = pplib.get_hest_in_range(klines, 10, 10+30)
     region_ll = pplib.get_lest_in_range(klines, 10, 10+30)
     # 标记
     if (klines.iloc[-1].close > region_hh):
         self.break_region_bar = 1
     elif (klines.iloc[-1].close < region_ll):
         self.break_region_bar = -1
예제 #5
0
    def risk_monitor(self, klines):
        #关键时刻
        hh_inday = self.get_highest_today()
        hh_inday_bar = self.get_highest_bar_today()
        if (self.hh_50 - hh_inday < 30 and hh_inday_bar < 60):
            if (self.to_hh_50_bar < 6):
                max_long_pos = 2
            else:
                max_long_pos = 1
            if (max_long_pos > 0
                    and self.manager.get_cfg_max_long_pos() > max_long_pos):
                self.manager.set_max_long_pos(max_long_pos)
                self.debug("set_max_long_pos(%d)" % (max_long_pos))

        ll_inday = self.get_lowest_today()
        ll_inday_bar = self.get_lowest_bar_today()
        if (ll_inday - self.ll_50 < 30 and ll_inday_bar < 60):
            if (self.to_ll_50_bar < 6):
                max_short_pos = 2
            else:
                max_short_pos = 1
            if (max_short_pos > 0
                    and self.manager.get_cfg_max_short_pos() > max_short_pos):
                self.manager.set_max_long_pos(max_short_pos)
                self.debug("set_max_short_pos(%d)" % (max_short_pos))

        #tm_hour = 9 or 13:30
        #关键位置
        if (self.key_hh != 0):
            if (self.key_mark_flag == 0):
                hh_5 = pplib.get_hest_in_range(klines, 1, 6)
                if (hh_5 >= self.key_hh):
                    self.key_mark_bar = self.cur_bar_id
                    self.key_mark_flag = 1
                    self.position -= 1
                    self.set_position(self.position)
            elif (self.key_mark_flag == 1):
                if (self.cur_bar_id - self.key_mark_bar > 25):
                    self.key_mark_flag = 2
            elif (self.key_mark_bar == 2):
                self.position += 1
                self.set_position(self.position)

        if (self.key_ll != 0):
            if (self.key_mark_flag == 0):
                ll_5 = pplib.get_lest_in_range(klines, 1, 6)
                if (ll_5 <= self.key_ll):
                    self.key_mark_bar = self.cur_bar_id
                    self.key_mark_flag = 1
                    self.position += 1
                    self.set_position(self.position)
            elif (self.key_mark_flag == 1):
                if (self.cur_bar_id - self.key_mark_bar > 25):
                    self.key_mark_flag = 2
            elif (self.key_mark_bar == 2):
                self.position -= 1
                self.set_position(self.position)
예제 #6
0
 def init_data(self, klines):
     self.init_flag = True
     cur_bar = self.get_current_minute_bar()
     if (cur_bar > 2):
         self.open_price = pplib.get_open_today(klines, 1)
         self.lest_inday = pplib.get_lest_in_range(klines, 1, cur_bar)
         self.hest_inday = pplib.get_hest_in_range(klines, 1, cur_bar)
     else:
         self.open_price = klines.iloc[-1].open
         self.lest_inday = klines.iloc[-1].open
         self.hest_inday = klines.iloc[-1].open
예제 #7
0
    def get_daybar_score(self, klines, id):
        self.debug("======analyze [%s] daybar=========" %
                   (tafunc.time_to_str(klines.iloc[-id].datetime)))
        self.debug("当日:open=%d close=%d" %
                   (klines.iloc[-1].open, klines.iloc[-1].close))
        self.debug("昨日:open=%d close=%d" %
                   (klines.iloc[-id].open, klines.iloc[-id].close))
        #突破+40
        #Bigbang30
        #连续+10
        #震荡上一个绿+10
        #底部+10
        BreakScore = 30
        BigBangScore = 20
        CheckSumScore = 20
        ContinueScore = 10
        InRangeAdjust = 10
        TopBomScore = 10
        RED_GREEN_SCORE = 10

        self.kpi = 0
        self.cur_day_bar = id
        if (self.cur_price == 0):
            self.cur_price = klines.iloc[-id].close
        #常用数据
        atr = ATR(klines, 30)
        self.ATR_day = int(atr.atr.iloc[-id])
        print("[%s] self.ATR_day=%d" % (self.TAG, self.ATR_day))

        # big bang find
        self.last_big_green_candle, self.last_big_green_candle_hight = pplib.find_big_green_candle(
            klines, 1, id, id + 20, atr.atr.iloc[-id] * 1.5)
        self.last_big_red_candle, self.last_big_red_candle_height = pplib.find_big_red_candle(
            klines, 1, id, id + 20, atr.atr.iloc[-id] * 1.5)
        # big bang score
        if (self.last_big_red_candle - id < 10
                and self.last_big_red_candle < self.last_big_green_candle):
            self.kpi = self.kpi + (11 - (self.last_big_red_candle - id)) * (
                BigBangScore / 10) + int(
                    (self.last_big_red_candle - atr.atr.iloc[-id] * 1.5) /
                    50) * 5
        if (self.last_big_green_candle - id < 10
                and self.last_big_red_candle < self.last_big_green_candle):
            self.kpi = self.kpi - (11 - (self.last_big_green_candle - 1)) * (
                BigBangScore / 10) - int(
                    (self.last_big_red_candle - atr.atr.iloc[-id] * 1.5) /
                    50) * 5
        print(
            "[%s] self.last_big_red_candle=%d, self.last_big_green_candle=%d" %
            (self.TAG, self.last_big_red_candle, self.last_big_green_candle))
        print("[%s] kpi=%d" % (self.TAG, self.kpi))

        #continue find
        self.last_continue_up_bar = 999
        self.last_continue_down_bar = 999
        for i in range(id, id + 6):
            count = 0
            for j in range(0, 3):
                if (klines.iloc[-(i + j)].open < klines.iloc[-(i + j)].close):
                    count = count + 1
                else:
                    count = count - 1
            if (count >= 3):
                self.last_continue_up_bar = i
                break
            elif (count <= -3):
                self.last_continue_down_bar = i
                break
        #连续
        if (self.last_continue_up_bar - id <= 1):
            self.kpi = self.kpi + ContinueScore
        if (self.last_continue_down_bar - id <= 1):
            self.kpi = self.kpi - ContinueScore
        print(
            "[%s] self.last_continue_up_bar=%d self.last_continue_down_bar=%d"
            %
            (self.TAG, self.last_continue_up_bar, self.last_continue_down_bar))
        print("[%s] kpi=%d after ContinueScore" % (self.TAG, self.kpi))
        #checksum
        self.day_checksum_4 = pplib.get_checksum(klines, 5, 1)
        cks_ret = abs(self.day_checksum_4) / self.ATR_day
        print("[%s] self.day_checksum_4=%d cks_ret=%f" %
              (self.TAG, self.day_checksum_4, cks_ret))
        cks_score = 0
        cks_weight = 0.2
        if (cks_ret > 1.5):
            cks_weight = 1
        elif (cks_ret > 1):
            cks_weight = 0.7
        elif (cks_ret > 0.5):
            cks_weight = 0.5
        else:
            cks_weight = 0.2
        if (self.day_checksum_4 > 0):
            cks_score = int(CheckSumScore * cks_weight)
        if (self.day_checksum_4 < 0):
            cks_score = -int(CheckSumScore * cks_weight)
        print("[%s] cks_score=%d" % (self.TAG, cks_score))
        # inrange find
        heightest = 1000
        heightest_bar = 1
        '''
        for i in range(id, id+2):
            height = pplib.get_height_in_range(klines, i, i+3)
            if (height > heightest):
                heightest = height
                heightest_bar = i
        '''
        heightest = pplib.get_height_in_range(klines, id, id + 5)
        result = heightest / atr.atr.iloc[-i]
        print("[%s] result=%f" % (self.TAG, result))
        if (result < 1.5):
            self.last_inrange_bar = heightest_bar
        self.last_inrange_height = heightest
        self.last_inrange_high = pplib.get_hest_in_range(klines, id, id + 5)
        self.last_inrange_low = pplib.get_lest_in_range(klines, id, id + 5)

        #inrange score
        if (self.last_inrange_bar - id < 2
                and self.last_continue_up_bar - id > 3
                and self.last_continue_down_bar - id > 3):
            if (klines.iloc[-id].close > klines.iloc[-id].open):
                self.kpi = self.kpi - InRangeAdjust
            else:
                self.kpi = self.kpi - InRangeAdjust
        print("[%s] last_inrange_bar=%d" % (self.TAG, self.last_inrange_bar))
        self.debug(
            "last_inrange_high=%d last_inrange_low=%d last_inrange_height=%d" %
            (self.last_inrange_high, self.last_inrange_low,
             self.last_inrange_height))
        print("[%s] kpi=%d" % (self.TAG, self.kpi))
        #===================================================#
        # break find
        self.last_break_up_bar = 999
        self.last_break_down_bar = 999
        for i in range(id, id + 6):
            tmp = pplib.get_hest_in_range(klines, i + 1, i + 1 + 4)
            if (klines.iloc[-i].close > tmp):
                self.last_break_up_bar = i
                break
        for i in range(id, id + 6):
            tmp = pplib.get_lest_in_range(klines, i + 1, i + 1 + 4)
            if (klines.iloc[-i].close < tmp):
                self.last_break_down_bar = i
                break
        #break
        if (self.last_break_up_bar - id == 0):
            self.kpi = self.kpi + BreakScore
        elif (self.last_break_up_bar - id == 1):
            self.kpi = self.kpi + int(BreakScore / 2)
        elif (self.last_break_up_bar - id == 2):
            self.kpi = self.kpi + int(BreakScore / 3)
        if (self.last_break_down_bar - id == 0):
            self.kpi = self.kpi - BreakScore
        elif (self.last_break_down_bar - id == 1):
            self.kpi = self.kpi - int(BreakScore / 2)
        elif (self.last_break_down_bar - id == 2):
            self.kpi = self.kpi - int(BreakScore / 3)
        print("[%s] self.last_break_up_bar=%d self.last_break_down_bar=%d " %
              (self.TAG, self.last_break_up_bar, self.last_break_down_bar))
        print("[%s] kpi=%d" % (self.TAG, self.kpi))
        #=====================================#
        # price pos find
        self.hh_100, self.hh_100_bar = pplib.get_hest_in_range2(
            klines, id, id + 100)
        self.ll_100, self.ll_100_bar = pplib.get_lest_in_range2(
            klines, id, id + 100)
        price_pos_ratio = (self.cur_price - self.ll_100) / (self.hh_100 -
                                                            self.ll_100)
        if (price_pos_ratio <= 0.5):
            self.kpi = self.kpi + (5 - int(price_pos_ratio * TopBomScore)) * 2
        else:
            self.kpi = self.kpi - (int(price_pos_ratio * TopBomScore) - 5) * 2
        print("[%s] price_pos_ratio=%f" % (self.TAG, price_pos_ratio))
        print("[%s] kpi=%d" % (self.TAG, self.kpi))
        #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#

        #修正
        if (self.last_break_up_bar - id <= 2
                and self.last_big_red_candle - id < 6):
            print("last_break_up_bar=%d last_big_red_candle=%d  " %
                  (self.last_break_up_bar - id <= 2,
                   self.last_big_red_candle - id))
            self.kpi += 20
        if (self.last_break_down_bar - id <= 2
                and self.last_big_green_candle - id < 6):
            self.kpi -= 20
        if (self.last_break_up_bar - id <= 2 and price_pos_ratio < 0.6):
            self.kpi += 20
            print("last_break_up_bar=%d price_pos_ratio=%d  " %
                  (self.last_break_up_bar - id <= 2, price_pos_ratio))
        if (self.last_break_down_bar - id <= 2
                and self.last_big_green_candle - id < 6):
            self.kpi -= 20
        #print ("height=%d atr=%d wave ratio=%f "%(height, atr.atr.iloc[-i], height/atr.atr.iloc[-i]))
        print("[%s] kpi=%d" % (self.TAG, self.kpi))
        #=====================================================================#
        # 距离底、顶的距离
        self.hh_20, self.hh_20_bar = pplib.get_hest_in_range2(
            klines, id, id + 20)
        self.ll_20, self.ll_20_bar = pplib.get_lest_in_range2(
            klines, id, id + 20)
        self.hh_10, self.hh_10_bar = pplib.get_hest_in_range2(
            klines, id, id + 10)
        self.ll_10, self.ll_10_bar = pplib.get_lest_in_range2(
            klines, id, id + 10)
        self.hh_5, self.hh_5_bar = pplib.get_hest_in_range2(klines, id, id + 6)
        self.ll_5, self.ll_5_bar = pplib.get_lest_in_range2(klines, id, id + 6)
        dif = self.hh_10_bar - id
        if (dif == 0):
            self.kpi += TopBomScore
        if (dif == 1):
            self.kpi += int(TopBomScore / 2)
        elif (dif == 2):
            self.kpi -= TopBomScore
        elif (dif == 3):
            self.kpi += TopBomScore
        elif (dif > 3 and dif <= 5):
            self.kpi -= TopBomScore
        self.to_top = dif

        dif = self.ll_10_bar - id
        if (dif == 0):
            self.kpi -= TopBomScore
        if (dif == 1):
            self.kpi -= int(TopBomScore / 2)
        elif (dif == 2):
            self.kpi += TopBomScore
        elif (dif == 3):
            self.kpi -= TopBomScore
        elif (dif > 3 and dif <= 5):
            self.kpi += TopBomScore
        self.to_bottom = dif
        print("[%s] to top=%d, to bottom=%d " %
              (self.TAG, self.hh_10_bar - id, self.ll_10_bar - id))
        print("[%s] kpi=%d" % (self.TAG, self.kpi))
        #==============================================================#
        # 红绿数量
        red_gre_score = 0
        self.reds = pplib.get_reds_candle(klines, 6)
        self.greens = pplib.get_greens_candle(klines, 6)
        if (self.greens > 0):
            red_gre_score -= self.greens * 20
        if (self.reds > 0):
            red_gre_score += self.reds * 20
        self.kpi += red_gre_score * (RED_GREEN_SCORE / 100)
        #跳空
        print("[%s] greens=%d reds=%d" % (self.TAG, self.greens, self.reds))
        gap_v = klines.iloc[-id].open - klines.iloc[-(id + 1)].close
        if (gap_v > 10):
            print("[%s] 高跳" % (self.TAG))
            self.manager.drive_event(self.TAG, StgEvent.GapUp, gap_v)
            self.kpi += 10
        gap_v = klines.iloc[-(id + 1)].close - klines.iloc[-id].open
        if (gap_v > 10):
            print("[%s] 低跳" % (self.TAG))
            self.manager.drive_event(self.TAG, StgEvent.GapDown, gap_v)
            self.kpi -= 10

        print("[%s] kpi=%d" % (self.TAG, self.kpi))
예제 #8
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)
예제 #9
0
    def on_bar(self, klines):
        if (self.run_flag == False or self.key_price == 0):
            return
        StrategyBase.on_bar(self, klines)

        if (abs(self.ask_price - self.key_price) > 30 and self.mark_bar == 0):
            return
            #lt = self.get_real_time()
        if (self.mark_bar != 0 and self.init_price_state == 1):  #上云盖
            cur_bar = self.get_current_minute_bar()
            hh = pplib.get_hest_in_range(self, 1, 30)
            #阻击
            if (cur_bar - self.mark_bar < 30 and self.position != -1):
                #c_sum_10 = pplib.get_checksum(klines, 10, 1)
                #avg_10 = pplib.get_avg_price(klines, 10)
                if (cur_bar - self.mark_bar < 5 and hh - self.ask_price < 20):
                    avg_6 = pplib.get_avg_price(klines, 6)
                    c_sum_8 = pplib.get_checksum(klines, 8, 1)
                    if (abs(avg_6 - self.key_price) < 10):
                        self.set_position(-1)
                elif (cur_bar - self.mark_bar > 5
                      and hh - self.ask_price < 20):
                    avg_6 = pplib.get_avg_price(klines, 6)
                    c_sum_10 = pplib.get_checksum(klines, 10, 1)
                    if (self.key_price - avg_6 > -5
                            and self.key_price - avg_6 < 14
                            and abs(c_sum_10) < 4):
                        self.set_position(-1)
            #顺势
            elif (cur_bar - self.mark_bar > 30 and self.position != 1):
                c_sum_10 = pplib.get_checksum(klines, 10, 1)
                avg_10 = pplib.get_avg_price(klines, 10)
                if (avg_10 > self.key_price and abs(c_sum_10) < 4):
                    self.set_position(1)

        if (self.mark_bar != 0 and self.init_price_state == -1):  #上云盖
            cur_bar = self.get_current_minute_bar()
            ll = pplib.get_lest_in_range(self, 1, 30)
            #阻击
            if (cur_bar - self.mark_bar < 30 and self.position != 1):
                #c_sum_10 = pplib.get_checksum(klines, 10, 1)
                #avg_10 = pplib.get_avg_price(klines, 10)
                if (cur_bar - self.mark_bar < 5 and ll - self.ask_price < 20):
                    avg_6 = pplib.get_avg_price(klines, 6)
                    c_sum_8 = pplib.get_checksum(klines, 8, 1)
                    if (abs(avg_6 - self.key_price) < 10 and abs(c_sum_8) < 4):
                        self.set_position(1)
                elif (cur_bar - self.mark_bar > 5
                      and ll - self.ask_price < 20):
                    avg_6 = pplib.get_avg_price(klines, 6)
                    c_sum_10 = pplib.get_checksum(klines, 10, 1)
                    if (avg_6 - self.key_price > -5
                            and avg_6 - self.key_price < 14
                            and abs(c_sum_10) < 4):
                        self.set_position(1)
            #顺势
            elif (cur_bar - self.mark_bar > 30 and self.position != -1):
                c_sum_10 = pplib.get_checksum(klines, 10, 1)
                avg_10 = pplib.get_avg_price(klines, 10)
                if (avg_10 < self.key_price and abs(c_sum_10) < 4):
                    self.set_position(1)

        if (self.cur_bar > 10):
            self.check_key_price(klines)
예제 #10
0
    def preparse_dayline_trend(self, d_klines):
        back_count = 6
        red_count = 0
        checksum = 0
        atr = ATR(d_klines, 30)
        self.atr_daily = int(atr.atr.iloc[-1])
        #print(self.TAG, self.atr_daily)  # 平均真实波幅
        for i in range(1, back_count):
            if (d_klines.iloc[-i].open - d_klines.iloc[-i].close > 0):
                red_count = red_count + 1
            checksum = checksum + (d_klines.iloc[-i].close -
                                   d_klines.iloc[-i].open)

        weight = tafunc.abs(checksum) / atr.atr.iloc[-i]
        print("[%s] parse_dayline_trend checksum=%d weight=%f " %
              (self.TAG, checksum, weight))
        #if (checksum > 0 and checksum > back_count*atr.atr):

        self.day_trend = red_count - (back_count - red_count)
        if (float(weight) > float(0.001) and checksum > 0):
            self.day_trend = self.day_trend + weight
        if (float(weight) > float(0.001) and checksum < 0):
            self.day_trend = self.day_trend - weight

        # 关键

        #range_H = tafunc.hhv(klines.high, 5)
        #range_L = tafunc.llv(klines.low, 5)
        self.Long_HH = pplib.get_hest_in_range(d_klines, 1, 50)
        self.Long_LL = pplib.get_lest_in_range(d_klines, 1, 50)
        self.range_HH, self.hh_day_bar = get_hh_price_bar(d_klines, 5)
        self.range_LL, self.ll_day_bar = get_ll_price_bar(d_klines, 5)
        print("[%s] Long_HH=%d Long_LL=%f " %
              (self.TAG, self.Long_HH, self.Long_LL))
        # 大小口 配合
        self.support_line = get_support_line(d_klines, 1, 2, 10)
        self.resistance_line = get_resistance_line(d_klines, 1, 2, 10)
        # 敏感价格基于前长周期的波峰波谷,后期被打破或形成支撑阻力
        self.sensitive_hh_bar, self.sensitive_hh = get_sensitive_hh(
            d_klines, 2)
        self.sensitive_ll_bar, self.sensitive_ll = get_sensitive_ll(
            d_klines, 2)

        self.debug("support_line=%d resistance_line=%d" %
                   (self.support_line, self.resistance_line))

        self.debug(
            "sensitive_hh_bar=%d sensitive_hh=%d sensitive_ll_bar=%d sensitive_ll=%d"
            % (self.sensitive_hh_bar, self.sensitive_hh, self.sensitive_ll_bar,
               self.sensitive_ll))

        if (self.sensitive_hh != 0):
            self.set_indor_value(Indicator.RangeHDaily, self.sensitive_hh)
        if (self.sensitive_ll != 0):
            self.set_indor_value(Indicator.RangeLDaily, self.sensitive_ll)
        # 关键,需手动录入
        '''
        self.key_hh = 
        self.key_ll = 
        '''
        '''
        日线级别的均线值
        '''
        self.ma10 = 0
        self.ma20 = 0
        '''
        预估
        '''
        self.forecast = 0

        for i in range(1, 5):
            self.lastday_quote.append(d_klines.iloc[-i])

        self.debug("last_day: open=%d close=%d high=%d low=%d" %
                   (self.lastday_quote[1].open, self.lastday_quote[1].close,
                    self.lastday_quote[1].high, self.lastday_quote[1].low))

        return self.day_trend
예제 #11
0
 def update_record_daily(self, dklines):
     self.ll_100_daily = pplib.get_lest_in_range(dklines, 1, 100)
     self.hh_100_daily = pplib.get_hest_in_range(dklines, 1, 100)
     self.debug("ll_100_daily=%d hh_100_daily=%d" %
                (self.ll_100_daily, self.hh_100_daily))
예제 #12
0
    def on_bar(self, klines):
        StrategyBase.on_bar(self, klines)
        lt = self.get_real_time()
        self.cur_bar_time = klines.iloc[-1].datetime
        self.cur_bar = self.get_current_minute_bar()
        #==================================#
        if (self.init_flag == False):
            self.init_data(klines)
        #================test==============#
        '''
        self.debug("cur_bar=%d"%(self.cur_bar))
        if (klines.iloc[-1].id - klines.iloc[-33].id > 30):
            self.debug(">30")
        else:
            self.debug("<30")
        '''
        self.avg_overs = self.avg_recorder.bars_of_over(klines)
        self.avg_unders = self.avg_recorder.bars_of_under(klines)
        tmp_last_crossdown_bar = self.last_crossdown_bar
        self.last_crossdown_bar = self.avg_recorder.get_last_cross_under(
            klines, 2)
        if (tmp_last_crossdown_bar != self.last_crossdown_bar):
            kp = KPCrossUnderAvgLine()
            kp.bar = self.cur_bar
            kp.score = self.last_crossover_bar
        tmp_last_crossover_bar = self.last_crossover_bar
        self.last_crossover_bar = self.avg_recorder.get_last_cross_over(
            klines, 2)
        if (tmp_last_crossover_bar != self.last_crossover_bar):
            kp = KPCrossOverAvgLine()
            kp.bar = self.cur_bar
            kp.score = self.last_crossdown_bar
        self.s_checksum = get_checksum(klines, self.short_term, 1)
        self.l_checksum = get_checksum(klines, self.long_term, 1)
        self.hh_long = get_hest_in_range(klines, 0, 60)  #长期的高
        self.hh_shor = get_hest_in_range(klines, 0, 30)  #短期的高
        self.ma5 = pplib.get_avg_price(klines, 5)

        #更新 最高最低
        if (klines.iloc[-1].close > self.hest_inday):
            self.hest_inday = klines.iloc[-1].close
            self.hest_bar_inday = self.get_current_minute_bar()
        if (klines.iloc[-1].close < self.lest_inday):
            self.lest_inday = klines.iloc[-1].close
            self.lest_bar_inday = self.get_current_minute_bar()

        if (self.open_price == 0 and self.cur_bar > 1):
            self.open_price = pplib.get_open_today(klines, 1)

        if (self.UpdateTradeInterval >= 1
                and lt.tm_min % self.UpdateTradeInterval == 0):
            self.update_trand_indictor()
        elif (self.UpdateTradeInterval == 0):
            self.update_trand_indictor()

        self.count_of_nearest_less = pplib.get_count_of_nearest_less(
            klines, 5, 50)
        self.count_of_nearest_greater = pplib.get_count_of_nearest_greater(
            klines, 5, 50)
        self.downs_of_this = pplib.get_count_of_less(klines, self.cur_bar)
        self.overs_of_this = pplib.get_count_of_greater(klines, self.cur_bar)

        if (self.hest_bar_inday < 60):  #近期新高
            if (self.Long_HH < self.hest_inday):
                self.trade_worning = 0

        if (lt.tm_min % 4 == 0 and lt.tm_sec == 0):
            self.my_print("kpi=%d" % (self.score))

        #==============================================#
        self.generate_indicator_event(klines)

        #==============================================#
        if (lt.tm_min % 5 == 0 and self.cur_bar > 0):
            self.on_bar_5(klines)

        if (self.cur_bar_id % 10 == 0 and self.cur_bar > 0):
            self.on_bar_10(klines)

        if (lt.tm_min % 30 == 0 and lt.tm_min == 1 and self.cur_bar > 60):
            self.on_bar_30(klines)
예제 #13
0
    def find_strong(self, klines):
        #===============================================#
        if (self.downs_of_this > 100):
            self.last_fit_less_bar = self.get_current_minute_bar()
        if (self.overs_of_this > 100):
            self.last_fit_greater_bar = self.get_current_minute_bar()

        #range break
        #last 5 break last 120
        #
        hh_5 = pplib.get_hest_in_range(klines, 1, 6)
        ll_5 = pplib.get_lest_in_range(klines, 1, 6)
        range_width = 120
        if (self.cur_bar < 120):
            range_width = self.cur_bar
        if (range_width <= 6):
            return
        hh_120 = pplib.get_hest_in_range(klines, 6, range_width)
        ll_120 = pplib.get_lest_in_range(klines, 6, range_width)

        bk_last_break_down_bar = self.last_break_down_bar
        bk_last_break_up_bar = self.last_break_up_bar
        if (hh_120 - ll_120 < 30):
            if (ll_120 - ll_5 > 10):
                self.last_break_down_bar = self.get_current_minute_bar()
                self.last_after_break_ll = ll_5
            elif (hh_5 - hh_120 > 10):
                self.last_break_up_bar = self.get_current_minute_bar()
                self.last_after_break_hh = hh_5
            self.last_inrange_end_bar = self.get_current_minute_bar() - 5

        #突破、拉回、反向创新高
        #突破,判断回调、再突破
        if (self.last_break_down_bar < 150
                and self.cur_bar - self.last_break_down_bar < 20 + 6
                and self.ma5 > self.last_inrange_ll):  # 折回
            pass
        elif (self.last_break_down_bar > 10
              and self.ma5 < self.last_after_break_ll):  # 连续突破
            self.strong_result = -1
            self.strong_direction = -1
        # 多
        if (self.last_break_up_bar < 150
                and self.cur_bar - self.last_break_up_bar < 20 + 6
                and self.ma5 > self.last_inrange_hh):  # 折回
            self.strong_result = 1
            self.strong_direction = 1
        elif (self.last_break_down_bar > 10
              and self.ma5 < self.last_after_break_ll):  # 连续突破
            self.strong_result = 1
            self.strong_direction = 1

        #突破、反向创新高
        if (self.cur_price > hh_120
                and (self.cur_bar - self.last_break_up_bar < 30 + 6)
                and (self.cur_bar - self.last_break_down_bar < 120
                     and self.last_break_down_bar > 20)):
            self.strong_result = 2
            self.strong_direction = 2
        if (self.cur_price < ll_120
                and self.cur_bar - self.last_break_down_bar < 30 + 6
                and (self.last_break_up_bar > 20
                     and self.cur_bar - self.last_break_up_bar < 120)):
            self.strong_result = -2
            self.strong_direction = -2

        height_12 = pplib.get_height_in_range(klines, 1, 13)
        csum = pplib.get_checksum(klines, 13, 1)
        if (csum > 25 or (csum > 0 and height_12 > 18)):
            self.debug("strong up chsum=%d height_12=%d" % (csum, height_12))
            self.info("strong up chsum=%d height_12=%d" % (csum, height_12))
            self.csum_12 = csum
            self.height_12 = height_12
            self.last_bigbang_up = self.cur_bar
        if (csum < -25 or (csum < 0 and height_12 > 18)):
            self.debug("strong down chsum=%d height_12=%d" % (csum, height_12))
            self.info("strong down chsum=%d height_12=%d" % (csum, height_12))
            self.csum_12 = csum
            self.height_12 = height_12
            self.last_bigbang_down = self.cur_bar
예제 #14
0
    def on_day_bar(self, dklines):
        start_id = 2
        #find_range
            #自然波动区间
            #强势后整理波动区间
        #find_strong_price

        self.support_ll = 0
        self.resistance_hh = 0
        self.range_hh = 0
        self.range_ll = 0
        self.boll_top = 0
        self.boll_bottom = 0
        self.trade_ll = 0
        self.trade_hh = 0

        atr = ATR(dklines, 30)
        self.atr_daily = int(atr.atr.iloc[-1])

        #如果区间线和强势线重合,确定方向
        inrange_result = self.find_inrange_daily(start_id, dklines)
        #支撑、阻力
        strong_result = self.find_strong_daliy(start_id, dklines)
        # boll
        self.find_boll_daily(start_id, dklines)

        if (inrange_result == True or strong_result == True):
            if (self.support_ll!=0 and self.range_ll!=0):
                self.trade_ll = int((self.range_ll + self.support_ll)/2)
            elif(self.support_ll != 0):
                self.trade_ll = self.support_ll
            elif(self.range_ll != 0):
                self.trade_ll = self.range_ll

            if (self.resistance_hh!=0 and self.range_hh!=0):
                self.trade_hh = int((self.range_hh + self.resistance_hh)/2)
            elif(self.resistance_hh != 0):
                self.trade_hh = self.resistance_hh
            elif(self.range_hh != 0):
                self.trade_hh = self.range_hh
            
            self.trend_type_daily = TrendType.WAVE
            if (self.support_ll!=0 and self.resistance_hh!=0):
                self.set_trade_direction(TradeDirection.BUYSELL)
            elif (self.support_ll != 0):
                self.set_trade_direction(TradeDirection.BUYONLY)
            elif(self.resistance_hh != 0):
                self.set_trade_direction(TradeDirection.SELLONLY)
            
            if (self.trade_hh == 0):
                self.trade_hh = self.boll_top
            if (self.trade_ll == 0):
                self.trade_ll = self.boll_bottom
        else:
            self.trend_type_daily = TrendType.TREND
            self.trade_ll = self.boll_bottom
            self.trade_hh = self.boll_top
        
        self.debug("on_day_bar trade_hh=%d trade_ll=%d"%(self.trade_hh, self.trade_ll))
        self.hh_3day = pplib.get_hest_in_range(dklines, start_id, start_id+3)
        self.ll_3day = pplib.get_lest_in_range(dklines, start_id, start_id+3)
        self.debug("on_day_bar hh_3day=%d ll_3day=%d"%(self.hh_3day, self.ll_3day))
        self.hh_50day = pplib.get_hest_in_range(dklines, start_id, start_id+50)
        self.ll_50day = pplib.get_lest_in_range(dklines, start_id, start_id+50)
예제 #15
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)
예제 #16
0
    def on_bar(self, klines):
        #self.debug("====1111======")
        #print(self.TAG, self.run_flag)
        if (self.run_flag == False):
            return
        StrategyBase.on_bar(self, klines)

        lt = self.get_real_time()
        if (lt.tm_hour == 21 and lt.tm_min < 5):
            return
        # update
        last_crossdown_bar = self.avg_recorder.get_last_cross_under(klines, 2)
        last_crossover_bar = self.avg_recorder.get_last_cross_over(klines, 2)
        overs = self.avg_recorder.bars_of_over(klines)
        downs = self.avg_recorder.bars_of_under(klines)
        s_checksum = get_checksum(klines, self.short_term, 1)
        l_checksum = get_checksum(klines, self.long_term, 1)
        cur_bar = self.get_current_minute_bar()

        # 弱势 提前
        hh_inday, hh_bar_inday = pplib.get_highest_bar_today2(
            klines)  #不用替换_fix
        ll_inday, ll_bar_inday = pplib.get_lowest_bar_today2(klines)

        tmp_position = self.position

        if (last_crossover_bar > 20):
            self.cross_avg_run_flag = 1
        elif (last_crossdown_bar > 20):
            self.cross_avg_run_flag = -1
        else:
            self.cross_avg_run_flag = 0

        if (lt.tm_min % 10 == 0):
            msg = "[last_crossdown_bar=%d, last_crossover_bar=%d, overs=%d, downs=%d, s_checksum=%d, l_checksum=%d" % (
                last_crossdown_bar, last_crossover_bar, overs, downs,
                s_checksum, l_checksum)
            self.info(msg)
            self.debug(msg)
        #过滤
        #中途运行的情况
        if (overs + downs < 20):
            return
        #开

        if (self.position == 0 and lt.tm_hour <= 13):
            ma10 = pplib.get_avg_price(klines, 10)
            #用于区间突破 全程在线的一边
            if (last_crossover_bar < last_crossdown_bar
                    and last_crossover_bar > 50 and ma10 > self.d_hh_3
                    and self.position <= 0):
                self.debug("overs avg and over hh_3")
                tmp_position = 1
            elif (last_crossover_bar > last_crossdown_bar
                  and last_crossdown_bar > 50 and ma10 < self.d_ll_3
                  and self.position >= 0):
                self.debug("downs avg and down ll_3")
                tmp_position = -1
            degree = self.manager.get_market_prediction()
            #degree =
            #数量
            dif = self.avg_price - self.ask_price
            if (abs(dif) <= 12 and downs / cur_bar < 0.1
                    and abs(s_checksum) < 5 and degree > 20):
                if (last_crossover_bar < 15 and degree < 35):
                    tmp_position = 1
                    print("[%s] 多开 条件1 " % (self.TAG))
                if (last_crossdown_bar < 20 and degree > 35):  #均线以下
                    tmp_position = 1
                    print("[%s] 多开 条件2 " % (self.TAG))
            elif (abs(dif) <= 12 and overs / cur_bar < 0.1
                  and abs(s_checksum) < 5 and degree < -20):
                if (last_crossdown_bar < 15 and degree > -35):
                    tmp_position = -1
                    print("[%s] 空开 条件1 " % (self.TAG))
                if (last_crossover_bar < 20 and degree < -35):  #均线以下
                    tmp_position = -1
                    print("[%s] 空开 条件2 " % (self.TAG))
            #峰度
            if (overs < downs / 5 and degree < -50):
                if (l_checksum < -20 and last_crossdown_bar < 5):
                    tmp_position = -1
                    print("[%s] 空开 条件3 " % (self.TAG))
            elif (downs < overs / 5 and degree > 35):
                if (l_checksum > 20 and last_crossover_bar < 5):
                    tmp_position = 1
                    print("[%s] 多开 条件3 " % (self.TAG))
            #趋向
            if (overs < downs / 2 and degree < -35 and self.position >= 0):
                if (self.cross_avg_run_flag == -1 and abs(l_checksum) < 5):
                    #if (self.cross_avg_run_flag == -1)<5):
                    tmp_position = -1
                    self.debug("趋向 修正")
                    #ups = pplib.get_count_of_greater(klines, 50)
                    #if (ups > 30):
            elif (downs < overs / 2 and degree > 35 and self.position <= 0):
                if (self.cross_avg_run_flag == 1 and abs(l_checksum) < 5):
                    tmp_position = 1
                    self.debug("趋向 修正")

            #修正
            #或者根据degree来修正
            #if (cur_bar - hh_bar_inday > 60 and ll_bar_inday < hh_bar_inday and tmp_position >0):
            if (hh_bar_inday > 60 and tmp_position > 0):
                tmp_position = 0
                print("[%s] degree来修正 " % (self.TAG))

            #if (cur_bar - ll_bar_inday > 60 and ll_bar_inday > hh_bar_inday and tmp_position<0):
            if (ll_bar_inday > 60 and tmp_position < 0):
                tmp_position = 0
                print("[%s] degree来修正 " % (self.TAG))

        #===========================================#
        #*******************************************#
        # 对应20200601
        kpi_daily = self.get_kpi_daily()
        if (kpi_daily > 35 and self.position <= 0 and overs > downs):
            if (last_crossdown_bar > 3 and last_crossdown_bar < 30):
                ups = pplib.get_count_of_greater(klines, 30)
                if (ups >= 5):
                    tmp_position = 1
                    self.debug("kpi_daily > 35 and crossdown")
        if (kpi_daily < -35 and self.position >= 0 and overs < downs):
            if (last_crossover_bar > 3 and last_crossover_bar < 30):
                donws = pplib.get_count_of_less(klines, 30)
                if (downs >= 5):
                    tmp_position = -1
                    self.debug("kpi_daily < -35 and crossover")
        #===========================================#
        #*******************************************#
        #平
        #时间过长
        if (self.cur_bar - self.entry_bar >= self.MAX_HOLD
                and self.position != 0):
            m_checksum = get_checksum(klines, 10, 1)  # short
            if (self.position > 0 and abs(m_checksum) < 2):
                ups = pplib.get_count_of_greater(klines, 60)
                if (ups > 30):
                    tmp_position = 0
                    print("[%s] 多平 时间过长 " % (self.TAG))
            if (self.position < 0 and abs(m_checksum) < 2):
                downs = pplib.get_count_of_less(klines, 60)
                if (downs > 30):
                    tmp_position = 0
                    print("[%s] 空平 时间过长 " % (self.TAG))

        if (self.position > 0 and last_crossdown_bar < last_crossover_bar
                and self.cur_bar - self.entry_bar > 30):
            ups = pplib.get_count_of_greater(klines, 50)
            if (ups > 29):
                tmp_position = 0
        # 前高点
        if (self.cur_bar - self.entry_bar > 20 and self.position > 0):
            long_hh = pplib.get_hest_in_range(klines, 0, 60)  #长期的高
            short_hh = pplib.get_hest_in_range(klines, 0, 30)  #短期的高
            m_checksum = get_checksum(klines, 20, 1)  # short
            if (long_hh == short_hh and abs(m_checksum) <= 3):
                tmp_position = 0
                print("[%s] 多平 前高点 " % (self.TAG))
        if (self.position > 0 and self.ask_price - self.entry_price > 48):
            tmp_position = 0
            self.debug("最大盈...")

        if (self.position < 0 and last_crossdown_bar > last_crossover_bar
                and self.cur_bar - self.entry_bar > 30):
            downs = pplib.get_count_of_less(klines, 50)
            if (downs > 29):
                tmp_position = 0
        # 前低点
        if (self.cur_bar - self.entry_bar > 20 and self.position < 0):
            long_ll = pplib.get_lest_in_range(klines, 0, 60)  #长期的高
            short_ll = pplib.get_lest_in_range(klines, 0, 30)  #短期的高
            m_checksum = get_checksum(klines, 20, 1)  # short
            if (long_ll == short_ll and abs(m_checksum) <= 3):
                tmp_position = 0
                print("[%s] 空平 前低点 " % (self.TAG))
        if (self.position < 0 and self.entry_price - self.ask_price > 39):
            tmp_position = 0
            self.debug("最大盈...")

        if (tmp_position != self.position):
            if (tmp_position > 0):
                if (self.check_open_order(1, 10)):
                    self.set_position(tmp_position)
            elif (tmp_position < 0):
                if (self.check_open_order(-1, 10)):
                    self.set_position(tmp_position)
            else:
                self.set_position(tmp_position)