K线形态识别_稳步上涨

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

 

目录

解说

技术特征

技术含义

K线形态策略代码

结果


解说

        稳步上涨是指上涨行情中,股价或指数收出若干夹着一些小阴线的阳线,整体走势呈向上倾斜的形态。

技术特征

1)出现在上涨行情中。

2)众多阳线中夹着较少的小阴线。

3)整个K线排列呈向上倾斜状态。

技术含义

        稳步上涨是买进信号,后市看涨。

        和冉冉上升相比,稳步上涨显示多方已经按奈不住内心的躁动,交易者可以买入。

K线形态策略代码

def excute_strategy(daily_file_path):
    '''
    名称:稳步上涨
    识别:
    1. 众多阳线中夹着较少的小阴线
    2. 整个K线排列呈向上倾斜状态
    自定义:
    1. 略向上倾斜 =》
        1)第一根与后面的K线斜率为正的占比要大于三分之二
        2)第一根与最后一根斜率要大于前面所有的斜率
    2. 较少的小阴线 =》占比小于五分之一
    3. 众多阳线 =》至少5根
    前置条件:计算时间区间 2021-01-01 到 2022-01-01
    :param daily_file_path: 股票日数据文件路径
    :return:
    '''
    import pandas as pd
    import os

    start_date_str = '2021-01-01'
    end_date_str = '2022-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['small_type'] = 0
    df.loc[(df['type']==-1) & (df['body_length']/df['closePrice'].shift(1)<0.015),'small_type'] = 1

    df['similar_position_yeah'] = 0
    df.loc[df['type']==1,'similar_position_yeah'] = 1
    df.loc[df['small_type']==1,'similar_position_yeah'] = 1

    df['ext_0'] = df['similar_position_yeah'] - df['similar_position_yeah'].shift(1)
    df['ext_1'] = df['similar_position_yeah'] - df['similar_position_yeah'].shift(-1)
    df.reset_index(inplace=True)
    df['i_row'] = [i for i in range(0, len(df))]
    df_m_s = df.loc[df['ext_0'] == 1].copy()
    df_m_e = df.loc[df['ext_1'] == 1].copy()
    i_row_s = df_m_s['i_row'].values.tolist()
    i_row_e = df_m_e['i_row'].values.tolist()

    i_row_two = i_row_s + i_row_e
    i_row_two.sort()

    df['signal'] = 0
    df['signal_name'] = ''
    for s, e in zip(i_row_s, i_row_e):
        if e - s < 5:
            continue
        enter_yeah = True
        last_smaller = False
        rate_p_num = 0
        negative_num = 0
        last_chg = df.iloc[e]['closePrice'] - df.iloc[s]['closePrice']
        for i in range(e,s,-1):
            cur_chg = df.iloc[i]['closePrice'] - df.iloc[s]['closePrice']
            if cur_chg > last_chg:
                last_smaller = True
                break
            if cur_chg>0:
                rate_p_num += 1
            if df.iloc[i]['type']==-1:
                negative_num += 1
            pass
        if last_smaller:
            continue
        if float(negative_num)/(e-s) > 0.2:
            continue
        if float(rate_p_num)/(e-s) < 0.66:
            enter_yeah = False
        if enter_yeah:
            df.loc[(df['i_row'] >= s) & (df['i_row'] <= e), 'signal'] = 1
            df.loc[(df['i_row'] >= s) & (df['i_row'] <= e), 'signal_name'] = str(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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值