3.70K 浏览
0
from tqsdk import TqApi, TqAccount, TargetPosTask, tafunc

'''
均线系统上穿建仓,下穿反手1.0版本
实现基础的开仓功能
'''
api = TqApi(TqAccount("simnow", "152405", 'AG801130'))

klines = api.get_kline_serial("DCE.m2001", 60)  # 引用m2001 1分钟K线
target_pos = TargetPosTask(api, "DCE.m2001")  # 创建 m2001的目标持仓 task

while True:
    api.wait_update()
    if api.is_changing(klines):
        ma20 = tafunc.ma(klines.close, 20)  # 定义MA20均线
        ma60 = tafunc.ma(klines.close, 60)  # 定义MA60均线

        if tafunc.crossup(ma20, ma60):  # 金叉
            print("金叉: 目标多头1手")
            # 设置目标持仓为多单
            target_pos.set_target_volume(1)

        elif tafunc.crossdown(ma20, ma60):  # 死叉
            print("死叉: 目标空头1手")
             # 设置目标持仓为空单
            target_pos.set_target_volume(-1)
报错ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
管理员 已回答的问题 2019年10月25日
1

tafunc.crossup 函数不是返回一个True/False, 而是返回一个序列,标记出所有的上穿点。您需要取这个序列的最后一项

管理员 已回答的问题 2019年10月25日
您正在查看1个答案中的1个,单击此处查看所有答案。