首页 > 编程语言 >python量化数据6:计算宁德时代macd金叉死叉红柱绿柱大小

python量化数据6:计算宁德时代macd金叉死叉红柱绿柱大小

时间:2024-10-13 10:47:59浏览次数:7  
标签:indicator EMA python 绿柱 df macd tdx close DEA

一、通达信公式


#行业业绩轮动公众号首发
DIFF:=EMA(CLOSE,12) - EMA(CLOSE,26);
DEA := EMA(DIFF,9);
MACD := 2*(DIFF-DEA);
金叉  cross(diff,dea)
死叉  cross(dea, diff)

二、代码

#行业业绩轮动公众号首发
#tdx_indicator 是1个通达信常用函数的封装库,下载可以从我的开源项目中拿到
#https://gitee.com/hytrader/hytrader/tree/master/data_tool/tdx_indicator.py

from mootdx.quotes import Quotes
import pandas as pd
import tdx_indicator
client = Quotes.factory(market='std')

# 获取实时行情
df = client.bars(symbol='300750', frequency=9, offset=200)  #获取最近200日宁德时代k线

close=df['close']
DIF,DEA,MACD=tdx_indicator.MACD(close)

jincha=tdx_indicator.CROSS(DIF,DEA)
sicha=tdx_indicator.CROSS(DEA, DIF)
last_signal = ""
for id in range(len(df)):
    # if  DEA>-1.0 and DEA<0.5
    if jincha[id]:
        print(df.iloc[id]['datetime'],jincha[id],"金叉")
        last_signal = "红柱"
    elif sicha[id]:
        print(df.iloc[id]['datetime'],sicha[id],"死叉")
        last_signal = "绿柱"
    else:
        print(df.iloc[id]['datetime'],last_signal,round(MACD[id],2))

三、运行

宁德时代8.20 macd金叉同花顺显示完全对应,并且macd红柱大小变大变小也能对应上

标签:indicator,EMA,python,绿柱,df,macd,tdx,close,DEA
From: https://blog.csdn.net/weixin_42661541/article/details/142895046

相关文章