PTrade工具:分享一个与通达信计算结果一致的MACD函数

大观量化
大观量化 以大见小,以小入微

0 People liked this article · 3022 views

在ptrade中,很多计算MACD的方法都无法获得与通达信等常用软件一致的MACD计算结果,包括网上的代码、ptrade自带的get_MACD函数、tailib库等等(注:最新版ptrade的get_MACD经验证,计算结果已经准确)。


注意:下载文件建议使用电脑浏览器下载,勿用手机下载,否则可能会出现下载不了的情况。


在此分享一个MACD函数,可以获得与通达信一致的MACD计算结果,入参K线需要大于等于120根,计算结果才准确。有需要的可以自行取用。


首先需要将附件MACD函数.txt中的函数代码复制到策略末尾。


示例用法:

def initialize(context):
    pass

def handle_data(context, data):
    pass
    
def before_trading_start(context, data):
    dif,dea,macd=MACD(get_history(120, frequency='1d', security_list='600000.SS', fq='pre', field=['close'], include=True)['close'])
    log.info('dif:'+str(dif[-1]))
    log.info('dea:'+str(dea[-1]))
    log.info('macd:'+str(macd[-1]))

List of attachments

MACD函数.txt

1KB

0.99

线上付款

Published on 2025-02-07 14:10

Disclaimers:

This document is written by 大观量化 Original published on 百果量化交流平台 ,The copyright belongs to the author。

Log in,More exciting content waiting for you to find,Contribute wonderful answers,Participate in comment interaction

go Sign in! No accountgoregister

大观量化
2025-02-19 02:27
@yxm619 那你可以分享一下代码,并验证一下是不是跟通达信一致
yxm619
2025-02-19 02:24
没有必要这么复杂,DS写的很好用
广告

Included in the column

Recommended content