写在前面:
1. 本文中提到的“K线形态查看工具”的具体使用操作请查看该博文;
2. K线形体所处背景,诸如处在上升趋势、下降趋势、盘整等,背景内容在K线形态策略代码中没有体现;
3. 文中知识内容来自书籍《K线技术分析》by邱立波。
目录
跛脚阳线出现在涨势中,由三根阳线组成,其中前两根一般是大阳线或中阳线,后两根是低开阳线,第三根阳线实体很小,收盘价低于前一根阳线的收盘价。

1)出现在上涨趋势中。
2)由三根或三根以上阳线组成。
3)前两根是大阳线或中阳线。
4)后两根阳线都是低开。
5)第三根阳线的实体很小,且收盘价比前面一根阳线的收盘价低。
坡脚阳线是滞涨信号。
在涨势中出现坡脚阳线,说明多方遭遇到上方沉重的抛压,后市看淡。
- def excute_strategy(daily_file_path):
- '''
- 名称:跛脚阳线
- 识别:
- 1. 由三根阳线组成,前两根一般是大阳线或中阳线,后两根是低开阳线
- 2. 第三根阳线实体很小,收盘价低于前一个阳线的收盘价
- 前置条件:计算时间区间 2021-01-01 到 2022-01-01
- :param daily_file_path: 股票日数据文件路径
- :return:
- '''
- import pandas as pd
- import os
-
- start_date_str = '2013-01-01'
- end_date_str = '2014-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['three_yeah'] = 0
- df.loc[(df['type']==1) & (df['type'].shift(-1)==1) & (df['type'].shift(-2)==1),'three_yeah'] = 1
- df['ext_yeah'] = 0
- df.loc[(df['three_yeah']==1) & (df['body_length']/df['closePrice'].shift(1)>0.02) & (df['body_length'].shift(-1)/df['closePrice']>0.02) & (df['closePrice']
'closePrice'].shift(-1)) & (df['closePrice']>df['openPrice'].shift(-1)),'ext_yeah'] = 1 - df['ext_yeah0'] = 0
- df.loc[(df['ext_yeah']==1) & (df['closePrice'].shift(-1)>df['closePrice'].shift(-2)) & (df['body_length'].shift(-1)>df['body_length'].shift(-2)),'ext_yeah0'] = 1
- df['signal'] = 0
- df['signal_name'] = ''
- df.loc[df['ext_yeah0'] == 1, '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
