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))
def on_day_bar(self, dklines): lastday_bar = 2 hh_30, to_hh_30_bar = pplib.get_hest_in_range2(dklines, 2, 30) ll_30, to_ll_30_bar = pplib.get_lest_in_range2(dklines, 2, 30) self.hh_30 = hh_30 self.ll_30 = ll_30 self.to_hh_30_bar = to_hh_30_bar self.to_ll_30_bar = to_ll_30_bar self.d_hh_3, self.d_hh_3_bar = pplib.get_hest_in_range2( dklines, 2, 2 + 3) self.d_ll_3, self.d_ll_3_bar = pplib.get_lest_in_range2( dklines, 2, 2 + 3)
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
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
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))
def make_prediction(self, start_day, dklines): self.watch_hh = dklines.iloc[-start_day].high + self.ATR_day self.watch_ll = dklines.iloc[-start_day].low - self.ATR_day walkpath = WalkPath.InRange if (self.trend_status.value >= TrendStatus.UpInUp.value): walkpath = WalkPath.Up self.watch_hh = dklines.iloc[-start_day].close + self.ATR_day self.watch_ll = (dklines.iloc[-start_day].low + dklines.iloc[-start_day].close) / 2 self.debug("WalkPath.Up1") elif (self.trend_status.value <= TrendStatus.DownInDown.value): walkpath = WalkPath.Down self.watch_ll = dklines.iloc[-start_day].close - self.ATR_day self.watch_hh = (dklines.iloc[-start_day].high + dklines.iloc[-start_day].close) / 2 self.debug("WalkPath.Down1") elif (self.trend_status.value >= TrendStatus.WaveBottom.value): ll_10, to_ll_bar = pplib.get_lest_in_range2( dklines, start_day, start_day + 10) to_ll_height = dklines.iloc[-start_day].low - ll_10 if (to_ll_bar >= start_day + 2 and to_ll_bar < start_day + 6 and to_ll_height < self.ATR_day): # bar_id = start_day + 1 if (dklines.iloc[-bar_id].open > dklines.iloc[-bar_id].close): walkpath = WalkPath.Up self.debug("WalkPath.Up2") self.watch_hh = pplib.get_avg_high2(dklines, start_day, 3) + 10 self.watch_ll = pplib.get_avg_low2(dklines, start_day, 3) else: walkpath = WalkPath.Down self.watch_hh = pplib.get_avg_high2(dklines, start_day, 3) - 10 self.watch_ll = pplib.get_avg_low2(dklines, start_day, 3) - 10 self.debug("WalkPath.Down2") else: walkpath = WalkPath.InRange self.debug("WalkPath.InRange2") boll = BOLL(dklines, 6, 1.5) self.watch_ll = list(boll["bottom"])[-start_day] self.watch_hh = list(boll["top"])[-start_day] elif (self.trend_status.value <= TrendStatus.WaveTop.value): hh_10, to_hh_bar = pplib.get_hest_in_range2( dklines, start_day, start_day + 10) to_hh_height = hh_10 - dklines.iloc[-start_day].high if (to_hh_bar >= start_day + 2 and to_hh_bar < start_day + 6 and to_hh_height < self.ATR_day): # bar_id = start_day + 1 if (dklines.iloc[-bar_id].open > dklines.iloc[-bar_id].close): walkpath = WalkPath.Up self.debug("WalkPath.Up3") else: walkpath = WalkPath.Down self.watch_hh = pplib.get_avg_high2(dklines, start_day, 3) + 10 self.watch_ll = pplib.get_avg_low2(dklines, start_day, 3) self.debug("WalkPath.Down3") else: walkpath = WalkPath.InRange self.debug("WalkPath.InRange3") boll = BOLL(dklines, 6, 1.5) self.watch_ll = list(boll["bottom"])[-start_day] self.watch_hh = list(boll["top"])[-start_day] else: self.debug("WalkPath.InRange4") walkpath = WalkPath.InRange self.watch_hh = pplib.get_avg_high2(dklines, start_day, 3) self.watch_ll = pplib.get_avg_low2(dklines, start_day, 3) self.predict_walkpath = walkpath self.debug("forecast walkpath=%s self.watch_hh=%d self.watch_ll=%d" % (walkpath, self.watch_hh, self.watch_ll))
def on_day_bar(self, dklines): self.dklines = dklines max_short_pos = 0 max_long_pos = 0 last_close = dklines.iloc[-1].close lastday_bar = self.lastday_bar price_flag = 0 bigbang_flag = 0 #控制仓位 hh_50, to_hh_50_bar = pplib.get_hest_in_range2(dklines, 2, 50) ll_50, to_ll_50_bar = pplib.get_lest_in_range2(dklines, 2, 50) #顶不追,底不追 to_hh_50 = dklines.iloc[-lastday_bar].high - hh_50 if (to_hh_50_bar >= 4 and to_hh_50 < 30): price_flag = 1 self.to_hh_50_bar = self.lastday_bar to_ll_50 = dklines.iloc[-lastday_bar].low - ll_50 if (to_ll_50_bar >= 4 and to_ll_50 < 30): price_flag = -1 self.to_ll_50_bar = self.lastday_bar self.hh_50 = hh_50 self.ll_50 = ll_50 self.to_hh_50_bar = to_hh_50_bar self.to_ll_50_bar = to_ll_50_bar #大涨、大跌后不追 if (dklines.iloc[-lastday_bar].close - dklines.iloc[-lastday_bar].open > 45): # big up self.last_bigbang_up_id = lastday_bar bigbang_flag = 1 elif (dklines.iloc[-lastday_bar].open - dklines.iloc[-lastday_bar].close > 45): # big down self.last_bigbang_down_id = lastday_bar bigbang_flag = -1 if (bigbang_flag == 1 and price_flag == 1): if (to_hh_50_bar > 6): max_long_pos = 2 else: max_long_pos = 1 elif (bigbang_flag == -1 and price_flag == -1): if (to_ll_50_bar > 6): max_short_pos = 2 else: max_short_pos = 1 elif (bigbang_flag == -1 and price_flag == 1): max_long_pos = 1 elif (bigbang_flag == 1 and price_flag == -1): max_short_pos = 1 elif (price_flag == 1): max_long_pos = 1 elif (price_flag == -1): max_short_pos = -1 elif (bigbang_flag == 1): max_long_pos = 1 elif (bigbang_flag == -1): max_short_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)) if (max_short_pos > 0 and self.manager.get_cfg_max_short_pos() > max_short_pos): self.manager.set_max_short_pos(max_short_pos) self.debug("set_max_short_pos(%d)" % (max_short_pos)) #关键价格 self.kp.on_bar(dklines) #如果key_hh存在,代表是阻力线 self.key_ll = self.kp.get_last_key_ll_price(dklines.iloc[-1].close, 3) #如果key_ll存在,代表是支撑线 self.key_hh = self.kp.get_last_key_hh_price(dklines.iloc[-1].close, 3)
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