写在前面:
1. 本文中提到的“K线形态查看工具”的具体使用操作请查看该博文;
2. K线形体所处背景,诸如处在上升趋势、下降趋势、盘整等,背景内容在K线形态策略代码中没有体现;
3. 文中知识内容来自书籍《K线技术分析》by邱立波。
目录
揉搓线是由一正一反两根T字线组成的K线组合,比喻股价像洗衣一样,被人反复揉搓。
揉搓线表明多空双方经过两个交易日的对决,最终握手言和。单根的T字线和倒T字线已经富含操控之意,何况一前一后收出两个收盘价相同或非常接近的T字线和倒T字线呢!仅仅用巧合来解释,恐怕难以令人信服。主力在一定程度上控制开盘价和收盘价以及几日的走势,因此只有主力才可以做到收放自如。交易者见到揉搓线,一定要引起足够重视。
1)多数出现在涨势当中。
2)由一根T字线和一根倒T字线组成,影线可长可短。
1)在上涨初期出现揉搓线是买入信号,后市继续看涨。
2)上涨途中出现揉搓线,后市继续看涨,是持仓信号。
3)在上涨趋势末端出现揉搓线是卖出信号。
4)股价下跌,反弹过程中出现揉搓线,是卖出信号。
- def excute_strategy(daily_file_path):
- '''
- 名称:揉搓线
- 识别:由一根T字线和一根倒T字线组成
- 自定义:
- 1. 影线很短=》不超过上一交易日价格 0.5%
- 2. 影线长 =》超过上一交易日价格 2%
- 前置条件:计算时间区间 2021-01-01 到 2022-01-01
- :param daily_file_path: 股票日数据文件路径
- :return:
- '''
- import pandas as pd
- import os
-
- start_date_str = '2015-01-01'
- end_date_str = '2016-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']
'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']
-
- short_len = 0.005
- long_len = 0.02
- window_len = 2
- # T
- df['ext_t'] = 0
- df.loc[(df['body_length']==0) & (df['top_shadow_length']/df['closePrice'].shift(1)
'bottom_shadow_length']/df['closePrice'].shift(1)>long_len),'ext_t'] = 1 - # 倒T
- df.loc[(df['body_length'] == 0) & (df['bottom_shadow_length'] / df['closePrice'].shift(1) < short_len) & (
- df['top_shadow_length'] / df['closePrice'].shift(1) > long_len), 'ext_t'] = 2
-
- df['ext_0'] = df['ext_t'].rolling(window=window_len).sum()
- df['signal'] = 0
- df.loc[df['ext_0']==3,'signal'] = 1
- df['signal_name'] = ''
- df.loc[(df['ext_0']==3) & (df['ext_t']==2),'signal_name'] = 'T 倒T'
- df.loc[(df['ext_0']==3) & (df['ext_t']==1),'signal_name'] = '倒T T'
-
- 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':[2]
- }
- return line_data