K线形态识别_锤头线和吊颈线(绞刑线)

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

目录

解说

技术特征

技术含义

K线形态策略代码

结果


解说

        锤头线是K线实体很小,没有上影线或者上影线很短,下影线一般大于或等于实体两倍的小阴线和小阳线。锤头线因K线形状像一把锤头而得名。

        吊颈线又称绞刑线,它们的K线形状和锤头线完全相同。不同之处在于:出现在股价大幅下跌之后的位置就叫锤头线;出现在股价大幅上升之后的位置,就是吊颈线(绞刑线)。

         锤头线和吊颈线(绞刑线)都是很强的转势信号,其中锤头线是见底信号,吊颈线是见顶信号。

技术特征

1)锤头线出现在下跌途中,吊颈线(绞刑线)出现在上涨途中。

2)阳线或阴线实体很小,下影线一般大于或等于实体的两倍。

3)一般没有上影线,或上影线很短。

技术含义

1)股价或指数大幅下跌后出现锤头线,转跌为升的可能性较大。

2)股价或指数大幅上升后出现吊颈线(绞刑线),见顶回落的可能性较大。

K线形态策略代码

def excute_strategy(daily_file_path):
    '''
    名称:锤头线和吊颈线(绞刑线)
    识别:
    1. 锤头线是K线实体很小,没有上影线或上影线很短,下影线一般大于或等于实体两倍的小阴线和小阳线
    自定义:
    1. 实体很小的小阳线和小阴线=》实体长度超过上一交易日价格0.5%但不到1.5%的K线
    2. 影线很短 =》不超过上一交易日价格 0.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.loc[df['closePrice']>=df['openPrice'],'type'] = 1
    df.loc[df['closePrice']<df['openPrice'],'type'] = -1

    df['body_length'] = abs(df['closePrice'] - df['openPrice'])
    df.loc[df['type']==1,'top_shadow_length'] = df['highestPrice'] - df['closePrice']
    df.loc[df['type']==-1,'top_shadow_length'] = df['highestPrice'] - df['openPrice']
    df.loc[df['type']==1,'bottom_shadow_length'] = df['openPrice'] - df['lowestPrice']
    df.loc[df['type']==-1,'bottom_shadow_length'] = df['closePrice'] - df['lowestPrice']

    df['signal'] = 0
    df['signal_name'] = 0
    short_len = 0.005
    df.loc[(df['body_length']/df['closePrice'].shift(1)>0.005) & (df['body_length']/df['closePrice'].shift(1)<0.015) & (df['top_shadow_length']/df['closePrice'].shift(1)<short_len) & (df['top_shadow_length']/df['closePrice'].shift(1)<short_len) & (df['bottom_shadow_length']/df['body_length']>=2),'signal'] = 1
    df.loc[(df['body_length']/df['closePrice'].shift(1)>0.005) & (df['body_length']/df['closePrice'].shift(1)<0.015) & (df['top_shadow_length']/df['closePrice'].shift(1)<short_len) & (df['top_shadow_length']/df['closePrice'].shift(1)<short_len) & (df['bottom_shadow_length']/df['body_length']>=2),'signal_name'] = df['bottom_shadow_length']/df['body_length']
    df = df.round({'signal_name': 2})

    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':'line'
    }
    return line_data

结果

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值