想判断均线金叉至现在的周期数,调用
<span class="kn">from</span> <span class="nn">tqsdk.tafunc</span> <span class="kn">import</span> <span class="n">barlast </span>提示调用错误,能协助看一下是什么问题吗?<img src="https://www.shinnytech.com/wp-content/uploads/anspress-temp/96356d03299e7ca28692adc6251322047310b388_596.png" />
这样写试试看
from tqsdk import TqApi from tqsdk.tafunc import ma,barlast,crossup #设置合约代码 SYMBOL = "SHFE.rb2005" api = TqApi() klines = api.get_kline_serial(SYMBOL, 60*15) ma5 = ma(klines.close,5) ma10 = ma(klines.close,10) x = barlast(crossup(ma5, ma10)==1) print(list(x)) print(x.iloc[-1]) # 获取最后一根k线的x api.close()
先前不能用是版本引用提示错误,
from tqsdk.tafunc import ma,barlast,crossup
ImportError: cannot import name ‘barlast’ from ‘tqsdk.tafunc’ (E:soft setuplibsite-packagestqsdktafunc.py)
更新到1.6.2提示这样