3

Code:

   def macd(prices):
        print "Running MACD"
        prices = np.asarray(prices)
        print prices
        macd, macdsignal, macdhist = MACD(prices, fastperiod=12, slowperiod=26, signalperiod=9)
        print "MACD "+macd

Explanation:

Im trying to run some analysis on a Python list containing closing prices.

I understand that I must convert the list before handing it over to TA-Lib, since I have seen all examples doing that.

However this is met by a only length-1 arrays can be converted to Python scalars

1 Answers1

8

I was importing the talib module like so, just like in TA-Libs website:

from talib.abstract import MACD

However, this is frowned upon in the community and today I found out why. One modules namespace was clobbering the other modules namespace, leading to the error. This is well put here.

So I just imported talib cleanly:

import talib

The final code that works is:

def macd(prices):
        print "Running MACD"
        prices = np.array(prices, dtype=float)
        print prices
        macd, macdsignal, macdhist = talib.MACD(prices, fastperiod=12, slowperiod=26, signalperiod=9)
        print "MACD "+macd
Community
  • 1
  • 1