backtrader2 / backtrader

Python Backtesting library for trading strategies
https://www.backtrader.com
GNU General Public License v3.0
238 stars 54 forks source link

TA-Lib functions which require inputs besides 'close' do not work properly #46

Closed lukeplausin closed 3 years ago

lukeplausin commented 3 years ago

Hi, I'm using backtrader with the ta-lib integration. It seems that if you try to use an indicator which requires more than just the 'close' input it will fail, because backtrader only supplies the 'close' column from OHLC datasets.

Some examples:

self.once(self._minperiod, self.buflen())
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/luke/.virtualenvs/myenv/lib/python3.8/site-packages/backtrader/talib.py", line 196, in once
    output = self._tafunc(*narrays, **self.p._getkwargs())
  File "/home/luke/.virtualenvs/myenv/lib/python3.8/site-packages/talib/__init__.py", line 27, in wrapper
    return func(*args, **kwargs)
  File "talib/_func.pxi", line 3703, in talib._ta_lib.MFI
TypeError: MFI() takes at least 4 positional arguments (1 given)

According to the documentation, the MFI indicator requires 4 inputs:

MFI(high, low, close, volume, timeperiod=14)