写在前面:
1. 本文中提到的“K线形态查看工具”的具体使用操作请查看该博文;
2. K线形体所处背景,诸如处在上升趋势、下降趋势、盘整等,背景内容在K线形态策略代码中没有体现;
3. 文中知识内容来自书籍《K线技术分析》by邱立波。
目录
解说
技术特征
技术含义
K线形态策略代码
结果
解说
红三兵是在上涨行情初期或横盘之后,连续收出三根创新高的小阳线。
技术特征
1)出现在上涨行情初期或横盘之后。
2)由三根连续创新高的小阳线组合而成。
技术含义
红三兵是买进信号,后市看涨。
在股价见底回升或横盘之后出现红三兵,表明多方正在积蓄能量,准备发力大举上攻。如果在收出红三兵后股价上涨,同步伴随着成交量放大,说明该股有新资金介入,积蓄上涨的可能性就更大了。交易者可以及时跟进,适量买入。
K线形态策略代码
def excute_strategy(daily_file_path):'''名称:红三兵(三个白色武士)识别:连续收出三根创新高的小阳线前置条件:计算时间区间 -01-01 到 -01-01:param daily_file_path: 股票日数据文件路径:return:'''import pandas as pdimport osstart_date_str = '-01-01'end_date_str = '-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'] = 0df.loc[df['closePrice'] >= df['openPrice'], 'type'] = 1df.loc[df['closePrice'] < df['openPrice'], 'type'] = -1df['body_length'] = abs(df['closePrice']-df['openPrice'])df['small_body_yeah'] = 0df.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'] = 1df['three_position_yeah'] = 0df.loc[(df['small_body_yeah']==1) & (df['small_body_yeah'].shift(-1)==1) & (df['small_body_yeah'].shift(-2)==1),'three_position_yeah'] = 1df['signal'] = 0df['signal_name'] = ''df.loc[(df['three_position_yeah']==1) & (df['closePrice']<df['closePrice'].shift(-1)) & (df['closePrice'].shift(-1)<df['closePrice'].shift(-2)),'signal'] = 1file_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