4.16 K 线分析 • 寻找夜空中最亮的星

来源:https://uqer.io/community/share/557c4527f9f06c6518ad1543

星蜡烛线(简称星线)的实体较小,并且在它的实体与它前面的蜡烛线的实体之间形成了价格跳空。只要星线的实体与前一个实体没有任何重叠,那么这个星蜡烛线就是成立的。星线对形态反转有着重要意义。

  • step 1. 获取股票池。
  • step 2. 股票池筛选:最近趋势为跌—>换手率>2%—>近两天出现过星线。
  • step 3. 输出这些股票的最近k线图。
  1. from lib.kbase import K
  2. def trend(closePrices, before=5):
  3. '''趋势
  4. @param closePrices: 收盘价格列表,由先到后顺序
  5. @return: 上涨趋势返回1,下跌趋势返回-1, 趋势不明返回0
  6. '''
  7. if len(closePrices) < before: return 0
  8. up = 0
  9. down = 0
  10. for i, price in enumerate(closePrices[-before:]):
  11. if i == 0:
  12. pre_price = price
  13. continue
  14. if pre_price < price:
  15. up += 1
  16. elif pre_price > price:
  17. down += 1
  18. pre_price = price
  19. if up > down and closePrices[-2] > closePrices[before-1]:
  20. return 1
  21. elif down > up and closePrices[-2] < closePrices[before-1]:
  22. return -1
  23. else:
  24. return 0
  25. def is_star_line(infos):
  26. '''
  27. @param infos: [(openPrice,lowestPrice,highestPrice,closePrice), ...]
  28. '''
  29. ks = [K(e) for e in infos]
  30. stars = []
  31. for k in ks[-3:]:
  32. if k.length > 0 and (k.entityLen/k.length) <= 0.1:
  33. stars.append(k)
  34. for star in stars:
  35. idx = ks.index(star)
  36. pre = ks[idx-1]
  37. if pre.isRed:
  38. if star.openPrice >= pre.closePrice and star.closePrice >= pre.closePrice:
  39. return True
  40. elif star.openPrice <= pre.openPrice and star.closePrice <= pre.openPrice:
  41. return True
  42. else:
  43. if star.openPrice >= pre.openPrice and star.closePrice >= pre.openPrice:
  44. return True
  45. elif star.openPrice <= pre.closePrice and star.closePrice <= pre.closePrice:
  46. return True
  47. return False
  1. def get_k_pic(tid, ecd):
  2. if ecd == 'XSHE':
  3. pic = '![%s](http://hqpick.eastmoney.com/EM_Quote2010PictureProducter/Index.aspx?ImageType=KXL&ID=%s%s&EF=&Formula=MACD)' % \
  4. (tid, tid, 2)
  5. else:
  6. pic = '![%s](http://hqpick.eastmoney.com/EM_Quote2010PictureProducter/Index.aspx?ImageType=KXL&ID=%s%s&EF=&Formula=MACD)' % \
  7. (tid, tid, 1)
  8. return pic
  1. from lib.kbase import K
  2. today = '20150612'
  3. beginDate = '20150601'
  4. def get_active_tickers():
  5. tickers = DataAPI.EquGet(equTypeCD="A", listStatusCD="L", field=['ticker', 'ListSector'])
  6. tickers = tickers[tickers['ListSector'] != '创业板']
  7. tickers = [val[0] for val in tickers.values]
  8. return tickers
  9. def get_last_with_star_line_tickers(count):
  10. tickers = []
  11. all_tickers = get_active_tickers()
  12. for ticker in all_tickers:
  13. infos = DataAPI.MktEqudAdjGet(ticker=ticker, beginDate=beginDate,
  14. field=["ticker", "secShortName", "exchangeCD", "tradeDate", "openPrice",
  15. "lowestPrice", "highestPrice", "closePrice"])
  16. infos = infos[infos['openPrice'] > 0]
  17. closePrices = [val[-1] for val in infos.values]
  18. if not closePrices: continue
  19. if trend(closePrices) != -1: continue
  20. vol5 = DataAPI.MktStockFactorsOneDayGet(tradeDate=today,ticker=infos.values[0][0],field=["ticker","VOL5"])
  21. vol5 = vol5.values[0][1]
  22. if vol5 < 0.02: continue
  23. _infos = [val[-4:] for val in infos.values]
  24. if is_star_line(_infos):
  25. tickers.append(infos)
  26. if len(tickers) >= count: break
  27. return tickers
  28. if __name__ == '__main__':
  29. tickers = get_last_with_star_line_tickers(1000)
  30. for t in tickers:
  31. print '###%s(%s)\n' % (t.values[0][1], t.values[0][0])
  32. print get_k_pic(t.values[0][0], t.values[0][2])
  33. print '\n'

锦龙股份(000712)

000712

中科金财(002657)

002657

克明面业(002661)

002661

龙洲股份(002682)

002682

麦趣尔(002719)

002719

浙能电力(600023)

600023

中新药业(600329)

600329

太平洋(601099)

601099

明星电缆(603333)

603333