乐于分享
好东西不私藏

在自己的编辑器写大qmt策略

在自己的编辑器写大qmt策略

写一个转接的策略壳,在qmt运行,
这里指定的脚本路径可以是任意路径,如果用相对路径就是以 {qmt安装路径}/bin.x64/ 为起点,
这里我放到了 {qmt安装路径}/python/mylib/策略2.py,内容和qmt里脚本内容一样,
编码头(#coding)只要和文件实际情况一致就行,utf-8 或 gbk 都可以,遇到报错不会处理就换着试一下,
运行效果:
也支持在外边修改后保存,里边直接点运行,不用重启qmt就能看到变化,不需要 reload,效果:
代码:
在大qmt里边的壳:
#coding:gbkdef load_strategy(path):    import tokenize    # 从文件头读取 # coding: xxx 声明    with open(path, 'rb'as f:        encoding = tokenize.detect_encoding(f.readline)[0]    with open(path, encoding=encoding) as f:        code = f.read()    exec(compile(code, path, 'exec'), globals())    returnload_strategy(r'..\python\mylib\策略2.py')
外边的实际策略:
#coding:utf-8def init(C):    print('init')    returndef after_init(C):    print('after_init')    returndef handlebar(C):    if not C.is_last_bar():        return    print('handlebar: {}'.format(C.barpos))    return
相关推荐:
大qmt如何【阻塞】状态处理交易数据推送