Hi all!
I'm attempting to translate a strategy I employ on another trading platform and I am running into some troubles with running talib.wma on a computed variable. I think what is happening (with my non-existent python background) is that talib is looking for multiple values in VolUp/VolDn but it is only returning a single number. Any tips on how I can solve this issue? Also, I've been trying to follow the new documentation as best a possible so if you have any other tips on the way I am going about this or something cool that I'm missing, I'd love to hear it!
VxPlus = talib.WMA(VolUp, timeperiod=10)[-1]
VxMinus = talib.WMA(VolDn, timeperiod=10)[-1]
Very much appreciated and looking forward to learning a bunch!
The error I am getting - TypeError: Argument 'real' has incorrect type (expected numpy.ndarray, got float)
import talib
def initialize(context):
context.stock = sid(8554)
def handle_data(context, data):
stock = context.stock
stock_data = data[stock]
price_hist = data.history(stock, 'volume', 10, '1d')
VolSlowAvg = price_hist.mean()
price_hist2 = data.history(stock, 'volume', 50, '1d')
VolFastAvg = talib.WMA(price_hist2, timeperiod=50)[-1]
O = data.current(stock, 'open')
C = data.current(stock, 'close')
rang = data.current(stock, 'high') - data.current(stock, 'low')
if C > O and rang <> 0:
VolUp = stock_data.volume
elif C < O and rang <> 0:
VolUp = ((rang + C - O) / (2 * rang + C - O)) * data.current(stock, 'volume')
else:
VolUp = 0.5 * data.current(stock, 'volume')
VolDn = data.current(stock, 'volume') - VolUp
VxPlus = talib.WMA(VolUp, timeperiod=10)[-1]
VxMinus = talib.WMA(VolDn, timeperiod=10)[-1]
VxNetRaw = VxPlus - VxMinus
VxRatio = 100 * VxNetRaw/VolFastAvg
if data[VxRatio].stddev(10) <> None:
record(Price=data[context.stock].price, \
MA=data[VxRatio].mavg(10), \
Lower=data[VxRatio].mavg(10) - 2 * data[VxRatio].stddev(10), \
Upper=data[VxRatio].mavg(10) + 2 * data[VxRatio].stddev(10))