K线形态识别_红三兵(三个白色武士)

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

目录

解说

技术特征

技术含义

K线形态策略代码

结果


解说

        红三兵是在上涨行情初期或横盘之后,连续收出三根创新高的小阳线。

技术特征

1)出现在上涨行情初期或横盘之后。

2)由三根连续创新高的小阳线组合而成。

技术含义

        红三兵是买进信号,后市看涨。

        在股价见底回升或横盘之后出现红三兵,表明多方正在积蓄能量,准备发力大举上攻。如果在收出红三兵后股价上涨,同步伴随着成交量放大,说明该股有新资金介入,积蓄上涨的可能性就更大了。交易者可以及时跟进,适量买入。

K线形态策略代码

def excute_strategy(daily_file_path):
    '''
    名称:红三兵(三个白色武士)
    识别:连续收出三根创新高的小阳线
    前置条件:计算时间区间 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_body_yeah'] = 0
    df.loc[(df['type']==1) & (df['body_length']/df['closePrice'].shift(1)>0.005) & (df['body_length']/df['closePrice'].shift(1)<0.015),'small_body_yeah'] = 1

    df['three_position_yeah'] = 0
    df.loc[(df['small_body_yeah']==1) & (df['small_body_yeah'].shift(-1)==1) & (df['small_body_yeah'].shift(-2)==1),'three_position_yeah'] = 1

    df['signal'] = 0
    df['signal_name'] = ''
    df.loc[(df['three_position_yeah']==1) & (df['closePrice']<df['closePrice'].shift(-1)) & (df['closePrice'].shift(-1)<df['closePrice'].shift(-2)),'signal'] = 1


    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',
        'duration_len':[-1],
        'temp':len(df.loc[df['signal']==1])
    }
    return line_data

结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值