98 浏览
0
0条评论

请教老师,本人想在0轴下macd黄金交叉的情况下,如果收盘价是黄金交叉以来的新高,且一直要求红柱(macd>0),则计数加1,

LONG = 26
SHORT = 12
M = 9

klines = await api.get_kline_serial(SYMBOL, PERIOD * 60)
quote= await api.get_quote(SYMBOL)
async with api.register_update_notify() as update_chan:
async for _ in update_chan:
if api.is_changing(klines.iloc[-1], “datetime”):

diff = tafunc.ema(klines.close, SHORT) – tafunc.ema(klines.close, LONG)
dea = tafunc.ema(diff, M)
macd = round(2 * (diff – dea), 3)

#黄金交叉时间

t_crossup = barlast(tafunc.crossup(diff,dea) and dea<=0)
print(“t_crossup”,t_crossup)

#统计计数,    黄金交叉以来的新高,且一直要求红柱(macd>0),则计数加1

count_high = tafunc.count(klines.close == tafunc.hhv(klines.close,t_crossup+1) and tafunc.count( macd>0, t_crossup +1 ) =t_crossup +1)

print(“count_high”, count_high)

———-以下是运行输出的问题,摘了几条如下,是不是barslast函数及count函数写法是否有问题?—————–

return self._wait_update(deadline=deadline, _task=_task)

self._run_until_idle(async_run=False)

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Task was destroyed but it is pending!

chaos 已回答的问题 6天 前
0

报错上有提示,你可能将整个Series作为布尔值使用。官方没有提供检查代码逻辑的服务,但你可以试试用cursor之类的大模型来解答,准确率还可以

chaos 发表新评论 6天 前

欢迎加入官方群聊611806823一起讨论,也可以试试首页右边小助手答疑~