The trading model based on the K-line chart is the mainstream in China, and many people use it in their daily transactions. So is there any way for us to study the winning percentage of these k-line charts? We can actually use Python to identify candlestick charts, but first we need to use one of the key packages, TA-Lib. This is an advanced library of Python financial quantification, covering more than 150 technical analysis indicators commonly used in stock and futures trading software, such as MACD, RSI, KDJ, momentum indicators, Bollinger Bands, etc. TA-Lib in Python is usually troublesome, but fortunately we have Anaconda, and the installation can be successfully completed using the following command:
conda install -c conda-forge ta-lib
The next thing to do is to use the data to verify. Here is an example of the Shanghai Stock Exchange Index:
data=get_ticker('SH#000001.txt',"2022","2022-08-25")
data.head()
TA-Lib comes with a lot of K-line shape functions, which need to take the opening, high, low and closing of the stock price as input:
open=data['open']
high=data['high']
low=data['low']
close=data['low']
Directly pass the corresponding parameters into the corresponding function of TA-Lib, and if the form is recognized, the return value 100/-100 will be output.
threeLineStrike = talib.CDL3LINESTRIKE(open,high,low,close)
threeBlackCrow = talib.CDL3BLACKCROWS(open,high,low,close)
eveningStar = talib.CDLEVENINGSTAR(open,high,low,close)
engulfing = talib.CDLENGULFING(open,high,low,close)
dragonflyDoji = talib.CDLDRAGONFLYDOJI(open,high,low,close)
gravestoneDoji = talib.CDLGRAVESTONEDOJI(open,high,low,close)
tasukigap = talib.CDLTASUKIGAP(open,high,low,close)
hammer = talib.CDLHAMMER(open,high,low,close)
darkCloudCover = talib.CDLDARKCLOUDCOVER(open,high,low,close)
piercingLine = talib.CDLPIERCING(open,high,low,close)
data['3 Line Strike'] = threeLineStrike
data['3 Black Crow'] = threeBlackCrow
data['Evening Star'] = eveningStar
data['Engulfing'] = engulfing
data['Dragonfly Doji'] = dragonflyDoji
data['Gravestone Doji'] = gravestoneDoji
data['Tasuki Gap'] = tasukigap
data['Hammer'] = hammer
data['DarkCloudCover'] = darkCloudCover
data['Piercing Line'] = piercingLine
Save the final identified data to get the results we need. After the K-line pattern is identified, the success rate of various K-line patterns can be easily counted. After the K-line pattern appears, it can be calculated. The stock price rises and falls within 2 to 5 days, and then a success rate is obtained.
Of course, you may still feel that these series of operations are very troublesome. We want to know which k-line pattern has a high success rate, which is nothing more than paving the way for our strategy formulation. In this case, we can consider the ready-made interface. There are some basic strategies available, and some advanced strategies can also be formulated through secondary development, which is more practical.