Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
AssertionError: real has wrong dimensions

I am trying to get the MACD for the entire current day so that I can compare each minute to the 2 previous minutes. Right now my MACD looks like this:

prices = data.history(context.secshorted, 'close', 26, '1m')
macd, macdsignal, macdhist = talib.MACD(prices, 12, 26, 9)

This gives me the error AssertionError: real has wrong dimensions. I tried everything including previous solutions to no avail. Also prices is returning the values from the previous day not the current day which is another issue.

1 response

Try this:

import talib

def initialize(context):  
    pass

def handle_data(context, data):  
    stk = symbol('SPY')  
    fast, slow, sig =12, 26, 9  
    period = fast+slow+sig  
    prices = data.history(stk, 'price', period, '1m')  
    macd, signal, hist = talib.MACD(prices, fast, slow, sig)  
    MACD_Raw = macd[-1]  
    SIGNAL = signal[-1]  
    HIST = hist[-1]  
    record(MACD_Raw = MACD_Raw, signal = SIGNAL, hist = HIST)