Esempio n. 1
0
 def find_down_mode(self, klines):
     mode_type = 0
     down_idx1 = self.find_event(RecordEvent.Down, 1)
     down_idx2 = self.find_event(RecordEvent.Down, 2)
     down_up_idx1 = self.find_event(RecordEvent.UpAfterDown, 1)
     up_idx1 = self.find_event(RecordEvent.Up, 1)
     sr_event1 = self.get_event_iloc(down_idx1)
     down1 = int(sr_event1.param)
     sr_event2 = self.get_event_iloc(down_idx2)
     down2 = int(sr_event2.param)
     sr_event3 = self.get_event_iloc(up_idx1)
     ups = int(sr_event3.param)
     if (down1>110 and down2>110 and down_idx1-down_idx2<20):
         #if (up_down_idx1 > ):
         self.debug("strong_down_mode")
         mode_type = -2
         
     if (down1>110 and down2>10 and down_idx1-down_idx2<50):
         start_bar = self.cur_bar_id - down_idx1
         end_bar = self.cur_bar_id - down_idx2
         range_height = pplib.get_height_in_range(klines, start_bar, end_bar)
         if (range_height < 15):
             self.debug("strong_down_mode")
             mode_type = -2
         else:
             self.debug("rushup_and_down_mode")
             mode_type = 1
     elif (down1>110 and ups>30 and up_idx1>down_idx1):
         start_bar = self.cur_bar_id - down_idx1
         end_bar = self.cur_bar_id - down_idx2
         range_height = pplib.get_height_in_range(klines, start_bar, end_bar)
         if (range_height > 20):
             self.debug("rushdown_and_up")
             mode_type = 1
Esempio n. 2
0
    def generate_indicator_event(self, klines):
        if (self.cur_bar < 2):
            return
        idor_list = []

        idor_list.append([Indicator.SCheckSum, self.s_checksum])
        idor_list.append([Indicator.CurPrice, self.cur_price])
        idor_list.append([Indicator.CurBar, self.cur_bar])
        #idor_list.append([Indicator.SCheckSum, self.s_checksum])
        idor_list.append([Indicator.LCheckSum, self.l_checksum])
        idor_list.append(
            [Indicator.GreaterContinuousCount, self.overs_of_this])
        idor_list.append([Indicator.LessContinuousCount, self.downs_of_this])
        idor_list.append([Indicator.Ups,
                          self.overs_of_this])  # 和GreaterContinuousCount重复
        idor_list.append([Indicator.Downs, self.downs_of_this])

        idor_list.append([Indicator.UndersAvg, self.avg_unders])
        idor_list.append([Indicator.OversAvg, self.avg_overs])
        avg_overs_per = int((self.avg_overs / self.cur_bar) * 100)
        avg_unders_per = int((self.avg_unders / self.cur_bar) * 100)
        idor_list.append([Indicator.UndersAvgPer, avg_unders_per])
        idor_list.append([Indicator.OversAvgPer, avg_overs_per])
        idor_list.append([Indicator.AvgLine, self.avg_price])

        idor_list.append([Indicator.HestInDay, self.hest_inday])
        idor_list.append([Indicator.LestInDay, self.lest_inday])

        idor_list.append([Indicator.CheckSum12, self.csum_12])
        csum6 = pplib.get_checksum(klines, 6, 1)
        idor_list.append([Indicator.CheckSum5, csum6])
        csum12 = pplib.get_checksum(klines, 12, 1)
        idor_list.append([Indicator.CheckSum12, csum12])
        csum15 = pplib.get_checksum(klines, 16, 1)
        idor_list.append([Indicator.CheckSum15, csum15])
        csum45 = pplib.get_checksum(klines, 45, 1)
        idor_list.append([Indicator.LCheckSum, csum45])
        idor_list.append([Indicator.SCheckSum, csum15])

        height_8 = pplib.get_height_in_range(klines, 1, 8)
        idor_list.append([Indicator.RangeHeight8, height_8])
        height_10 = pplib.get_height_in_range(klines, 1, 11)
        idor_list.append([Indicator.RangeHeight10, height_10])
        height_15 = pplib.get_height_in_range(klines, 1, 16)
        idor_list.append([Indicator.RangeHeight15, height_15])
        height_30 = pplib.get_height_in_range(klines, 1, 30)
        idor_list.append([Indicator.RangeHeight30, height_30])
        height_50 = pplib.get_height_in_range(klines, 1, 50)
        idor_list.append([Indicator.RangeHeight50, height_50])

        idor_list.append([Indicator.OpenPrice, self.open_price])
        idor_list.append([Indicator.LestInDay, self.lest_inday])
        idor_list.append([Indicator.HestInDay, self.hest_inday])

        idor_list.append([Indicator.HestBarInDay, self.hest_bar_inday])
        idor_list.append([Indicator.LestBarInDay, self.lest_bar_inday])

        for idor in idor_list:
            self.manager.drive_indicator(idor[0], idor[1])
Esempio n. 3
0
    def on_day_bar(self, dklines):
        start_id = 2
        #low range and break
        height_3 = pplib.get_height_in_range(dklines, start_id, start_id + 4)
        open_close_3 = 0
        oc_sum = 0
        for i in range(start_id, start_id + 2):
            oc_sum += dklines.iloc[-i].open - dklines.iloc[-i].close
        open_close_3 = int(oc_sum / 2)
        if (height_3 < 60 or abs(open_close_3) < 20):
            self.low_range_flag = True

        self.hh_3day = pplib.get_hest_in_range2(dklines, start_id,
                                                start_id + 3)
        self.ll_3day = pplib.get_lest_in_range2(dklines, start_id,
                                                start_id + 3)

        hh_10day_bar = pplib.get_hest_in_range2(dklines, 2, 2 + 4)
        if (hh_10day_bar >= 2):  #2 是昨天,1 是今
            self.continue_flag = False
        elif (hh_10day_bar == 2):
            self.continue_flag = True

        if (dklines.iloc[-start_id].open > dklines.iloc[-start_id].open):
            self.last_red_or_green = -1
        else:
            self.last_red_or_green = 1

        self.lastday_close = dklines.iloc[-start_id].close
        self.lastday_high = dklines.iloc[-start_id].high

        if (dklines.iloc[-1].open - dklines.iloc[-2].close > 15):
            self.skip_flag = True
Esempio n. 4
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()
Esempio n. 5
0
 def on_bar5(self, klines):
     #低波动
     cur_bar = self.get_current_minute_bar()
     if (self.get_current_minute_bar() > 120):
         height = pplib.get_height_in_range(klines, 1, cur_bar)
         if (height <= 35):
             self.count_for_checksum = 15  # low range z这个值需要调整
             self.low_range_flag = True
         else:
             #self.count_for_checksum = 15 #15好像太大了
             self.count_for_checksum = 8
             self.low_range_flag = False
     #监控行情情况,不断更新cond_up_count, cond_down_count
     if (self.ups > 210):
         if (self.low_range_flag == False):
             self.cond_down_count = 45
             self.cond_up_count = 60
         else:
             self.cond_down_count = 60
             self.cond_up_count = 60
         self.debug("change cond_down_count=%d cond_up_count=%d" %
                    (self.cond_down_count, self.cond_up_count))
     if (self.downs > 210):
         if (self.low_range_flag == False):
             self.cond_down_count = 60
             self.cond_up_count = 45
         else:
             self.cond_down_count = 60
             self.cond_up_count = 60
         self.debug("change cond_down_count=%d cond_up_count=%d" %
                    (self.cond_down_count, self.cond_up_count))
Esempio n. 6
0
    def parse_trend(self, start_day, dklines):
        reds = pplib.get_reds_candle2(dklines, start_day, start_day + 6)
        greens = pplib.get_greens_candle2(dklines, start_day, start_day + 6)
        height_7 = pplib.get_height_in_range(dklines, start_day, start_day + 7)
        cksum_8 = pplib.get_checksum2(dklines, start_day, 5, 1)
        last_crosdwn_bar = pplib.get_crossdown_ma_bar2(dklines, start_day, 10)
        last_crosovr_bar = pplib.get_crossover_ma_bar2(dklines, start_day, 10)
        hh_60, hh_60_bar = pplib.get_hest_in_range2(dklines, start_day,
                                                    start_day + 60)
        ll_60, ll_60_bar = pplib.get_lest_in_range2(dklines, start_day,
                                                    start_day + 60)
        self.debug("height_7=%d cksum_8=%d" % (height_7, cksum_8))
        self.debug("reds=%d green=%d" % (reds, greens))
        self.debug("ll_60_bar=%d hh_60_bar=%d" % (ll_60_bar, hh_60_bar))
        trend_type = 0
        if ((reds >= 4) or (ll_60_bar >= 2 and reds >= 2)):
            trend_type += 1
        if (cksum_8 > 50 and height_7 > 70):
            trend_type += 1
        if (last_crosovr_bar > start_day + 3):
            trend_type = 1

        if ((greens >= 4) or (hh_60_bar >= 2 and greens >= 2)):
            trend_type -= 1
        if (cksum_8 < -50 and height_7 > 70):
            trend_type -= 1
        if (last_crosdwn_bar > start_day + 3):
            trend_type -= 1

        self.debug("trend_type score=%d" % (trend_type))
        self.trend_status = TrendStatus.Unkown
        if (trend_type >= 2):
            self.debug("......trend up......")
            hh_12, hh_12_bar = pplib.get_hest_in_range2(
                dklines, start_day, start_day + 12)
            if (hh_12_bar == 1):
                self.trend_status = TrendStatus.UpInUp
            if (hh_12_bar > start_day and hh_12_bar < start_day + 5):
                self.trend_status = TrendStatus.WaveInUp

        elif (trend_type <= -2):
            ll_12, ll_12_bar = pplib.get_lest_in_range2(
                dklines, start_day, start_day + 12)
            if (ll_12_bar == 1):
                self.trend_status = TrendStatus.DownInDown
            if (ll_12_bar > start_day and ll_12_bar < start_day + 5):
                self.trend_status = TrendStatus.WaveInDown

        if (self.trend_status == TrendStatus.Unkown):
            hh_22, hh_22_bar = pplib.get_hest_in_range2(
                dklines, start_day, start_day + 22)
            ll_22, ll_22_bar = pplib.get_lest_in_range2(
                dklines, start_day, start_day + 22)
            if (hh_22_bar < ll_22_bar):
                self.trend_status = TrendStatus.WaveTop
            else:
                self.trend_status = TrendStatus.WaveBottom

        self.debug("trend_status=%s" % (self.trend_status))
Esempio n. 7
0
 def find_lowrange(self, klines):
     if (self.cur_bar < 20):
         return
     l_checksum = pplib.get_checksum(klines, 2, 30)
     if (abs(l_checksum) < 10):
         range_len = 50
         if (self.cur_bar < 50):
             range_len = self.cur_bar
         recent_height = pplib.get_height_in_range(klines, 1, range_len)
         if (recent_height < 25):
             self.debug("find lowrange")
Esempio n. 8
0
    def find_bigbang2(self, klines):
        reds = pplib.get_reds_candle(klines, 20)
        greens = pplib.get_greens_candle(klines, 20)
        height = pplib.get_height_in_range(klines, 1, 20)
        if (reds>15 or height>20):
            self.bigbang_up_height = height
            tmp, self.bigbang_up_bar_start = pplib.get_lest_in_range2(klines, 1, 20)
            self.bigbang_up_bar_start = self.cur_bar - self.bigbang_up_bar_start
            tmp, self.bigbang_up_bar_end = pplib.get_hest_in_range2(klines, 1, 20)
            self.bigbang_up_bar_end = self.cur_bar - self.bigbang_up_bar_end

        elif (greens>15 or height<-20):# 
            self.bigbang_up_height = height
            tmp, self.bigbang_down_bar_start = pplib.get_hest_in_range2(klines, 1, 20)
            self.bigbang_down_bar_start = self.cur_bar - self.bigbang_down_bar_start
            tmp, self.bigbang_down_bar_end = pplib.get_lest_in_range2(klines, 1, 20)
            self.bigbang_down_bar_end = self.cur_bar - self.bigbang_down_bar_end
Esempio n. 9
0
    def find_bigbang(self, klines):
        #速度
        ck_sum_10 = pplib.get_checksum(klines, 11, 1)
        if (abs(ck_sum_10) > 10):
            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
        if (ck_sum_10 < self.min_ck_sum):
            self.min_ck_sum = ck_sum_10
        '''
        # 高度
        # cksum 和 height有重复
        height_10 = pplib.get_height_in_range(klines, 1, 11)
        if (height_10 > 20):
            msg = "height_10=%d" % (height_10)
            self.info(msg)
            self.debug("bigbang")

        if (ck_sum_10 > 20 or (height_10 > 20 and ck_sum_10 > 10)):
            self.last_bigbang_up = self.get_current_minute_bar()
        if (ck_sum_10 < -20 or (height_10 > 20 and ck_sum_10 < -10)):
            self.last_bigbang_down = self.get_current_minute_bar()
Esempio n. 10
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))
Esempio n. 11
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
Esempio n. 12
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
Esempio n. 13
0
    def on_bar(self, klines):
        StrategyBase.on_bar(self, klines)
        #if (self.run_flag == False or self.hh <= 0 or self.ll <= 0):
        self.generate_indicator(klines)

        if (self.run_flag == False):
            return
        if (self.cur_bar < 10):
            return

        height8 = pplib.get_height_in_range(klines, 1, 10)
        cksum = pplib.get_checksum(klines, 10, 1)

        l_height = pplib.get_height_in_range(klines, 1, 30)
        l_cksum = pplib.get_checksum(klines, 30, 1)

        pre_height8 = pplib.get_height_in_range(klines, 4, 4+8)

        overs = self.get_avg_overs()
        unders = self.get_avg_unders()
        greaters = pplib.get_count_of_greater(klines, self.cur_bar)
        lesses = pplib.get_count_of_less(klines, self.cur_bar)
        self.greaters = greaters
        self.lesses = lesses

        if (height8 < 15 and abs(cksum) < 3):
            self.debug("height8=%d cksum=%d"%(height8, cksum))
        if (l_height< 20 and abs(l_cksum) < 5):
            self.debug("l_height=%d l_cksum=%d"%(l_height, l_cksum))
        '''
        if (greaters > 30):
            self.last_greaters = overs
        else:
            if (self.last_greaters > 60):
                self.last_lesses = lesses
                if (self.last)
                self.add_event()

        if (downs > 30):
            self.last_downs = downs
        else:
            if (self.last_downs>60 and overs > 5):
                self.last_downs = 
        
        if (overs > 2 and self.last_downs > 30):
            pass
        if (downs > 2 and self.last_overs > 30):
            pass
        '''

        lt = self.get_real_time()
        tmp_position = self.position
        
        #===============make==================#
        #一、根据均线上线
        if (self.ask_price<self.avg_price and self.position <= 0):
            kpi_daily = self.get_kpi_daily()
            cond = False
            if (unders > 15 and overs/unders > 1.3):
                cond = True
            if (kpi_daily > 10):
                cond = True
            else:
                cond = False

            if (abs(cksum) < 4 and self.avg_price-self.ask_price<20):
                if (cond == True):
                    self.debug("under avg open......")
                    tmp_position = 1
                    self.make_type = 1
                    self.hh = self.ask_price + self.RUSH_PROFIT
                elif(self.position<0):
                    tmp_position = 0 #有漏洞
        elif (self.ask_price > self.avg_price and self.position >=0):
            kpi_daily = self.get_kpi_daily()
            cond = False
            if (unders > 15 and overs/unders > 1.3):
                cond = True
            if (kpi_daily < -10):
                cond = True
            else:
                cond = False

            if (abs(cksum) < 4 and self.ask_price-self.avg_price<20):
                if (cond == True):
                    self.debug("over avg open......")
                    tmp_position = -1
                    self.make_type = 1
                    self.ll = self.ask_price - self.RUSH_PROFIT
                elif(self.position>0):
                    tmp_position = 0 #有漏洞

        #二、根据突破
        last_cru_avg = self.get_last_avg_crossdown()
        last_cro_avg = self.get_last_avg_crossover()
        kpi_daily = self.get_kpi_daily()
        if (((last_cro_avg > 38 and last_cro_avg<last_cru_avg) 
            or(kpi_daily > 35 and greaters > 120))
            and self.position <=0):
            if (self.last_greaters > 60 and greaters > 4 and self.cur_bar_id - self.last_greaters_mark_bar < 30):
                
                my_kpi = self.get_kpi_myself()
                dist = self.cur_bar_id - self.last_greaters_mark_bar
                #短 连续
                if (kpi_daily > 35 and greaters>self.last_greaters and dist>3 and dist<10):
                    self.hh = self.ask_price + self.BREAK_PROFIT2
                    tmp_position = 1
                    self.make_type = 2
                    self.debug("连续。。。。")
                if (tmp_position != 1 and kpi_daily>30 and dist>15):
                    height12 = 100
                    rang = self.cur_bar_id - self.last_greaters_mark_bar
                    if (rang > 2):
                        height12 = pplib.get_height_in_range(klines, 1, 15)
                    if (height12<14 and abs(cksum)<3):
                        self.hh = self.ask_price + self.BREAK_PROFIT1
                        tmp_position = 1
                        self.make_type = 2
                        self.debug("横盘 等待 break...")
                if (tmp_position != 1 and self.last_greaters > 240):
                    if (greaters > self.last_greaters and greaters > 5 and greaters < 30):
                        tmp_position = 1
                        self.make_type = 2
                        self.debug("长突破。。")
                        
        if (((last_cro_avg > 38 and last_cro_avg<last_cru_avg) #条件1
            or (kpi_daily<-35 and lesses > 120))
            and self.position >=0):
            if (self.last_lesses > 60 and lesses > 4 and self.cur_bar_id - self.last_lesses_mark_bar < 30):
                
                my_kpi = self.get_kpi_myself()
                dist = self.cur_bar_id - self.last_lesses_mark_bar
                #短 连续
                if (kpi_daily < -35 and lesses>self.last_lesses and dist>3 and dist<10):
                    self.ll = self.ask_price - self.BREAK_PROFIT2
                    tmp_position = -1
                    self.make_type = 2
                    self.debug("连续。。。。")
                if (tmp_position != 1 and kpi_daily>30 and dist>15):
                    height12 = 100
                    rang = self.cur_bar_id - self.last_greaters_mark_bar
                    if (rang > 2):
                        height12 = pplib.get_height_in_range(klines, 1, 15)
                    if (height12<14 and abs(cksum)<3):
                        self.ll = self.ask_price - self.BREAK_PROFIT1
                        tmp_position = -1
                        self.make_type = 2
                        self.debug("横盘 等待 break...")
                if (tmp_position != 1 and self.last_lesses > 240):
                    if (lesses > self.last_greaters and greaters > 5 and greaters < 30):
                        tmp_position = -1
                        self.make_type = 2
                        self.debug("长突破。。")
                        self.ll = self.ask_price - self.BREAK_PROFIT1
                
                #长 高度小

        #三、出现长横盘

        #四、开盘来一发
        if (self.cur_bar < 30):
            if (kpi_daily > 35 and self.position <=0):
                open_p = self.get_open_price()

                if (open_p-self.ask_price >= 10):
                    tmp_position = 1
                    self.make_type = 4
                    self.debug("开盘  enter.....")
                    self.hh = self.ask_price+self.RUSH_PROFIT
                elif (self.cur_bar>10 and lesses > 9):
                    tmp_position = 1
                    self.make_type = 4
                    self.debug("开盘  超时enter.....")
                    self.hh = self.ask_price+self.RUSH_PROFIT
            if (kpi_daily < -35 and self.position >=0):
                open_p = self.get_open_price()

                if (self.ask_price- open_p>= 10):
                    tmp_position = -1
                    self.make_type = 4
                    self.ll = self.ask_price - self.RUSH_PROFIT
                    self.debug("开盘  enter.....")
                elif (self.cur_bar>10 and lesses > 9):
                    tmp_position = -1
                    self.make_type = 4
                    self.ll = self.ask_price - self.RUSH_PROFIT
                    self.debug("开盘  超时enter.....")
        #==================exit===========================#
        if (self.position > 0 and self.ask_price>=self.hh):
            tmp_position = 0
            self.debug("arrive hh")
        if (self.position < 0 and self.ask_price<=self.ll):
            tmp_position = 0
            self.debug("arrive ll")

        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
        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
        
        if (self.position !=0 and self.make_type == 0):
            self.monitor_position(klines, 30)
        elif (self.position !=0 and self.make_type == 1):
            self.monitor_position(klines, 40)
        elif (self.position !=0 and self.make_type == 2):
            self.monitor_position(klines, 50)
        elif (self.position !=0 and self.make_type == 2):
            self.monitor_position(klines, 30)
        
        #===============================================#
        #更新放后
        if (self.last_greaters>40):
            if (greaters == 0):
                self.add_event(RecordEvent.Up, self.last_greaters, self.cur_bar_id, self.cur_bar_time)
            if (self.cur_bar_id - self.last_greaters_mark_bar < 20 and lesses >5):
                self.add_event(RecordEvent.DownAfterUp, lesses, self.cur_bar_id, self.cur_bar_time)
        if (self.last_lesses>40):
            if (lesses == 0):
                self.add_event(RecordEvent.Down, self.last_lesses, self.cur_bar_id, self.cur_bar_time)
            if (self.cur_bar_id - self.last_lesses_mark_bar < 20 and greaters > 5):
                self.add_event(RecordEvent.UpAfterDown, greaters, self.cur_bar_id, self.cur_bar_time)

        if (greaters > 30):
            self.last_greaters = greaters
            if (greaters > 60):
                self.last_greaters_mark_bar = self.cur_bar_id

        if (lesses > 30):
            self.last_lesses = lesses
            if (lesses > 60):
                self.last_lesses_mark_bar = self.cur_bar_id

        #===================================#
        if (tmp_position != self.position):
            if (self.check_order(5)):
                self.set_position(tmp_position)
            else:
                self.debug("间隔检测 false")
Esempio n. 14
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)