import talibclass CommonTactics:
@classmethod
def talib_MACD(cls, df_close_data, fastperiod=12, slowperiod=26):
"""
talib官方默认参数 fastperiod=12, slowperiod=26,signalperiod=9
参数:
fastperiod:快线【短周期均线】
slowperiod:慢线【长周期均线】
signalperiod:计算signalperiod天的macd的EMA均线【默认是9,无需更改】
返回参数:
macd【DIF】 = 12【fastperiod】天EMA - 26【slowperiod】天EMA
macdsignal【DEA或DEM】 = 计算macd的signalperiod天的EMA
macdhist【MACD柱状线】 = macd - macdsignal
"""
macd, macdsignal, macdhist = getattr(talib, "MACD")(
df_close_data,
fastperiod=fastperiod,
slowperiod=slowperiod,
signalperiod=9)
return macd, macdsignal, macdhist
对照表:
TA-lib的macd函数计算macd值,函数输出3个值,
macd(对应diff)
macdsignal(对应dea)
macdhist(对应macd)
然后按照下面的原则判断买入还是卖出。
1.DIFF、DEA均为正,DIFF向上突破DEA,买入信号。
2.DIFF、DEA均为负,DIFF向下跌破DEA,卖出信号。
3.DEA线与K线发生背离,行情反转信号。
4.分析MACD柱状线,由正变负,卖出信号;由负变正,买入信号。
参考:blog.csdn.net/faiy0000/ar…