From 3b9affee79b2b3e8cd0d47253eab2d74a514149f Mon Sep 17 00:00:00 2001 From: zengbin93 Date: Fri, 29 May 2020 19:08:06 +0800 Subject: [PATCH] =?UTF-8?q?0.3.3=20=E4=BC=98=E5=8C=96=E4=B8=AD=E6=9E=A2?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chan/__init__.py | 2 +- chan/analyze.py | 20 ++++++++++++-------- test/test_analyze.py | 21 +++++++++++---------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/chan/__init__.py b/chan/__init__.py index da1e195..b31e4b9 100644 --- a/chan/__init__.py +++ b/chan/__init__.py @@ -7,7 +7,7 @@ from .solid import SolidAnalyze from .solid import is_in_tolerance, is_first_buy, is_first_sell, is_second_buy, \ is_second_sell, is_third_buy, is_third_sell, is_xd_buy, is_xd_sell -__version__ = "0.3.2" +__version__ = "0.3.3" __author__ = "zengbin93" __email__ = "zeng_bin8888@163.com" diff --git a/chan/analyze.py b/chan/analyze.py index 9a0285d..95def98 100644 --- a/chan/analyze.py +++ b/chan/analyze.py @@ -461,27 +461,31 @@ class KlineAnalyze(object): zs_xd = [] for i in range(len(k_xd)): - if len(zs_xd) < 3: + if len(zs_xd) < 5: zs_xd.append(k_xd[i]) continue xd_p = k_xd[i] - zs_d = max([x['xd'] for x in zs_xd[:3] if x['fx_mark'] == 'd']) - zs_g = min([x['xd'] for x in zs_xd[:3] if x['fx_mark'] == 'g']) + zs_d = max([x['xd'] for x in zs_xd[1:5] if x['fx_mark'] == 'd']) + zs_g = min([x['xd'] for x in zs_xd[1:5] if x['fx_mark'] == 'g']) + if zs_g <= zs_d: + zs_xd.append(k_xd[i]) + zs_xd.pop(0) + continue if xd_p['fx_mark'] == "d" and xd_p['xd'] > zs_g: # 线段在中枢上方结束,形成三买 k_zs.append({'zs': (zs_d, zs_g), "zs_xd": deepcopy(zs_xd)}) - zs_xd = deepcopy(k_xd[i - 2:i + 1]) + zs_xd = deepcopy(k_xd[i: i+1]) elif xd_p['fx_mark'] == "g" and xd_p['xd'] < zs_d: # 线段在中枢下方结束,形成三卖 k_zs.append({'zs': (zs_d, zs_g), "zs_xd": deepcopy(zs_xd)}) - zs_xd = deepcopy(k_xd[i - 2:i + 1]) + zs_xd = deepcopy(k_xd[i: i+1]) else: zs_xd.append(deepcopy(xd_p)) - if len(zs_xd) >= 4: - zs_d = max([x['xd'] for x in zs_xd if x['fx_mark'] == 'd']) - zs_g = min([x['xd'] for x in zs_xd if x['fx_mark'] == 'g']) + if len(zs_xd) >= 5: + zs_d = max([x['xd'] for x in zs_xd[1:5] if x['fx_mark'] == 'd']) + zs_g = min([x['xd'] for x in zs_xd[1:5] if x['fx_mark'] == 'g']) k_zs.append({'zs': (zs_d, zs_g), "zs_xd": deepcopy(zs_xd)}) return k_zs diff --git a/test/test_analyze.py b/test/test_analyze.py index b0a8c07..96616aa 100644 --- a/test/test_analyze.py +++ b/test/test_analyze.py @@ -15,21 +15,21 @@ def test_bei_chi(): ka = KlineAnalyze(df) # 线段背驰 - zs1 = ['2018-07-26 15:00:00', '2018-10-19 15:00:00'] - zs2 = ['2018-01-29 15:00:00', '2018-07-06 15:00:00'] - assert is_bei_chi(ka, zs1, zs2, direction='down', mode='xd', adjust=0.9) + zs1 = {"start_dt": '2018-07-26 15:00:00', "end_dt": '2018-10-19 15:00:00', "direction": "down"} + zs2 = {"start_dt": '2018-01-29 15:00:00', "end_dt": '2018-07-06 15:00:00', "direction": "down"} + assert is_bei_chi(ka, zs1, zs2, mode='xd', adjust=0.9) - zs1 = ['2013-12-10 15:00:00', '2014-01-20 15:00:00'] - zs2 = ['2013-09-12 15:00:00', '2013-11-14 15:00:00'] - assert not is_bei_chi(ka, zs1, zs2, direction='down', mode='xd', adjust=0.9) + zs1 = {"start_dt": '2013-12-10 15:00:00', "end_dt": '2014-01-20 15:00:00', "direction": "down"} + zs2 = {"start_dt": '2013-09-12 15:00:00', "end_dt": '2013-11-14 15:00:00', "direction": "down"} + assert not is_bei_chi(ka, zs1, zs2, mode='xd', adjust=0.9) # 笔背驰 - zs1 = ['2019-05-17 15:00:00', '2019-06-10 15:00:00'] - zs2 = ['2019-04-08 15:00:00', '2019-05-10 15:00:00'] + zs1 = {"start_dt": '2019-05-17 15:00:00', "end_dt": '2019-06-10 15:00:00'} + zs2 = {"start_dt": '2019-04-08 15:00:00', "end_dt": '2019-05-10 15:00:00'} assert is_bei_chi(ka, zs1, zs2, mode='bi', adjust=0.9) - zs1 = ['2018-09-28 15:00:00', '2018-10-19 15:00:00'] - zs2 = ['2018-08-28 15:00:00', '2018-09-12 15:00:00'] + zs1 = {"start_dt": '2018-09-28 15:00:00', "end_dt": '2018-10-19 15:00:00'} + zs2 = {"start_dt": '2018-08-28 15:00:00', "end_dt": '2018-09-12 15:00:00'} assert not is_bei_chi(ka, zs1, zs2, mode='bi', adjust=0.9) @@ -44,5 +44,6 @@ def test_kline_analyze(): # 测试背驰识别 assert not ka.bi_bei_chi() assert not ka.xd_bei_chi() + print(ka.zs[-2]) -- GitLab