布林线口诀的要点:
1、三线向上,中轨进,上轨出
2、三线向下,下轨进,中轨出
3、三轨走平,下轨进,上轨出

pip install mplfinance ;

python 安装使用 TA-lib 
安装主要在 http://www.lfd.uci.edu/~gohlke/pythonlibs/ 
这个网站找到
TA_Lib-0.4.24-cp310-cp310-win_amd64.whl

pip install /pypi/TA_Lib-0.4.24-cp310-cp310-win_amd64.whl
编写 mpf_kline_boll.py  如下

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os

import sys

import matplotlib.pyplot as plt

import mplfinance as mpf

import pandas as pd

import tushare as ts

import talib

if len(sys.argv) ==2:

code = sys.argv[1]

else:

print('usage: python mpf_kline_boll.py stockcode ')

sys.exit(1)

if len(code) !=6:

print('stock code length: 6')

sys.exit(2)

df = ts.get_k_data(code, start='2023-01-01')

if len(df) <30:

print(" len(df) <30 ")

sys.exit(2)

close = df['close'].values

df['upper'], df['mid20'], df['lower'] = talib.BBANDS(close,

timeperiod=20, nbdevup=2, nbdevdn=2, matype=0)

df.index = pd.to_datetime(df.date)

df2 = df[ df['date'] >'2023-05-01']

print(df2.tail(5))

my_color = mpf.make_marketcolors(up='red', down='green', edge='black', wick='black')

my_style = mpf.make_mpf_style(marketcolors=my_color, gridaxis='both', gridstyle='-.', y_on_right=True)

ap = mpf.make_addplot(df2[['upper','mid20','lower']])

mpf.plot(df2, type='candle', style='charles', addplot=ap, volume=True, title=code)

运行 python mpf_kline_boll.py 002594

参考:mplfinance最佳实践:动态交互式高级K线图(蜡烛图)