一、环境准备
pip install pandas
pip install mootdx
下载tdx_indicator.py通达信函数封装 https://etf.cpolar.cn/file/
公众号:行业业绩轮到首发
二、代码
#RSI金叉条件,RSI6上穿RSI12数值金叉看多,相反看空
#也就是比较 RSI6[-1],RSI12[-1] 大小即可
from mootdx.quotes import Quotes
import pandas as pd
import tdx_indicator
client = Quotes.factory(market='std')
df = client.bars(symbol="600519", frequency=9, offset=300) #获取最近300日贵州茅台k线
close=df['close']
high=df['high']
low=df['low']
RSI6,RSI12,RSI24=tdx_indicator.RSI(close)
print(df.iloc[-1]['datetime'],RSI6[-1],RSI12[-1],RSI24[-1])
三、运行
贵州茅台2024.10.8 13:30左右RSI信号 RSI6 88.58 RSI12 80.67 RSI24 71.25,和程序运行一致,小数点round(xx,2)保留小数点2位就可以
2024-10-08 15:00 86.80772433856602 79.55223304977464 70.44790443035811