Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Translating Volume Oscillator for Market Collisions Algo

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))  
1 response

After further research, is the batch transform function something that needs to be included? I've found many posts where I think people have used this to create a data array but according to the debugger, this looks like a depreciated function and suggests using the data.history instead. Unfortunately, the part where it is calculating VxRatio has to be current.

Any help is much appreciated, I'm sure it's something you geniuses can help with!