diff --git a/chan/__init__.py b/chan/__init__.py index da1e195ad93d67f82610c65e66d5292b63d7e9a6..b31e4b984f731d152e3b9017242c06b524735b09 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 9a0285d25c6e7ae6f386fe30a91fbbf6428b2efc..95def98e0893e0b124359b14ee4018ee81d9fbbe 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 b0a8c07934079caf2d378f595d26b0df845e7581..96616aac1af13e3786568d6f7388302f321b2993 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])