K线形态识别_向上加速度线

写在前面:
1. 本文中提到的“K线形态查看工具”的具体使用操作请查看该博文
2. K线形体所处背景,诸如处在上升趋势、下降趋势、盘整等,背景内容在K线形态策略代码中没有体现;
3. 文中知识内容来自书籍《K线技术分析》by邱立波。

目录

解说

技术特征

技术含义

K线形态策略代码

结果​


解说

        向上加速度线是指上涨过程中股价或指数涨幅越来越大的K线组合形态。

技术特征

1)出现在上涨趋势中。

2)股价期初缓慢爬升,然后上涨速度越来越快,连续收出中阳线、大阳线。

技术含义

        向上加速度是见顶信号。

        向上加速度线和向下加速度线形态相同,只是方向和技术含义相反。另外,向上加速度线的见顶信号比向下加速度线的见底信号更加强烈和可靠。

        向上加速度线就像长跑,临近终点就会发起冲刺,不再吝啬体力。但冲刺过后,人也就精疲力尽,比赛也随之结束,所以向上加速度线是见顶信号。交易者可根据情况减仓或清仓,也可以继续持股,等待其他见顶和看跌的技术信号。

K线形态策略代码

def excute_strategy(daily_file_path):
    '''
    名称:向上加速度线
    识别:股价或指数涨幅越来越大的K线组合
    自定义:
    1. 至少5根
    2. 每连续两根K线,后一根开盘价高于前一根开盘价,收盘价高于前一根收盘价
    3. 从前到后,涨幅越来越大
    4. 最后一根为长阳线,倒数第二根为中阳线
    前置条件:计算时间区间 2021-01-01 到 2022-01-01
    :param daily_file_path: 股票日数据文件路径
    :return:
    '''
    import pandas as pd
    import os

    start_date_str = '2020-01-01'
    end_date_str = '2021-01-01'
    df = pd.read_csv(daily_file_path,encoding='utf-8')
    # 删除停牌的数据
    df = df.loc[df['openPrice'] > 0].copy()
    df['o_date'] = df['tradeDate']
    df['o_date'] = pd.to_datetime(df['o_date'])
    df = df.loc[(df['o_date'] >= start_date_str) & (df['o_date']<=end_date_str)].copy()
    # 保存未复权收盘价数据
    df['close'] = df['closePrice']
    # 计算前复权数据
    df['openPrice'] = df['openPrice'] * df['accumAdjFactor']
    df['closePrice'] = df['closePrice'] * df['accumAdjFactor']
    df['highestPrice'] = df['highestPrice'] * df['accumAdjFactor']
    df['lowestPrice'] = df['lowestPrice'] * df['accumAdjFactor']

    # 开始计算
    df['type'] = 0
    df.loc[df['closePrice']>df['openPrice'],'type'] = 1
    df.loc[df['closePrice']<df['openPrice'],'type'] = -1

    df['body_length'] = abs(df['closePrice']-df['openPrice'])

    df['big_body_yeah'] = 0
    df.loc[(df['type']==1) & (df['body_length']/df['closePrice'].shift(1)>0.04),'big_body_yeah'] = 1
    df['median_body_yeah'] = 0
    df.loc[(df['type']==1) & (df['body_length']/df['closePrice'].shift(1)>0.02),'median_body_yeah'] = 1

    df['close_pct'] = df['closePrice'] - df['closePrice'].shift(1)

    df['target_yeah'] = 0
    df.loc[df['type']==1,'target_yeah'] = 1

    df['ext_0'] = df['target_yeah'] - df['target_yeah'].shift(1)
    df['ext_1'] = df['target_yeah'] - df['target_yeah'].shift(-1)

    df.reset_index(inplace=True)
    df['i_row'] = [i for i in range(len(df))]
    df_s = df.loc[df['ext_0']==1].copy()
    df_e = df.loc[df['ext_1']==1].copy()
    s_row_list = df_s['i_row'].values.tolist()
    e_row_list = df_e['i_row'].values.tolist()

    two_row = s_row_list + e_row_list
    two_row.sort()
    s_list = []
    e_list = []
    start_yeah = False
    for i in two_row:
        if start_yeah:
            if i in s_row_list:
                s_list.append(i)
            if i in e_row_list:
                e_list.append(i)
        else:
            if i in s_row_list:
                start_yeah = True
                s_list.append(i)

    df['signal'] = 0
    df['signal_name'] = ''
    for s,e in zip(s_list,e_list):
        if e-s < 5:
            continue
        temp_e = None
        temp_s = None
        for i in range(e,s,-1):
            if df.iloc[i]['big_body_yeah'] == 1 and df.iloc[i-1]['median_body_yeah']==1:
                if i-s<5:
                    break
                for j in range(i-2,s,-1):
                    if df.iloc[j]['closePrice']>df.iloc[j-1]['closePrice'] and df.iloc[j]['openPrice']>df.iloc[j-1]['openPrice']:
                        temp_s = j
                    else:
                        break
                    pass
                if temp_s is None or i - temp_s < 5:
                    break
                temp_e = i
                break
            pass
        if temp_s is None or temp_e is None:
            continue
        df.loc[(df['i_row']>=temp_s) & (df['i_row']<=temp_e),'signal'] = 1
        df.loc[(df['i_row']>=temp_s) & (df['i_row']<=temp_e),'signal_name'] = str(temp_e-s)
        pass

    file_name = os.path.basename(daily_file_path)
    title_str = file_name.split('.')[0]

    line_data = {
        'title_str':title_str,
        'whole_header':['日期','收','开','高','低'],
        'whole_df':df,
        'whole_pd_header':['tradeDate','closePrice','openPrice','highestPrice','lowestPrice'],
        'start_date_str':start_date_str,
        'end_date_str':end_date_str,
        'signal_type':'duration_detail',
        'duration_len':[],
        'temp':len(df.loc[df['signal']==1])
    }
    return line_data

结果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值