ta icon indicating copy to clipboard operation
ta copied to clipboard

IndexError: index 14 is out of bounds for axis 0 with size 12

Open mablue opened this issue 3 years ago • 5 comments

CTK/USDT
2021-04-15 11:23:21,685 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
  File "/home/mab/freqtrade/freqtrade/main.py", line 37, in main
    return_code = args['func'](args)
  File "/home/mab/freqtrade/freqtrade/commands/optimize_commands.py", line 86, in start_hyperopt
    hyperopt.start()
  File "/home/mab/freqtrade/freqtrade/optimize/hyperopt.py", line 378, in start
    preprocessed = self.backtesting.strategy.ohlcvdata_to_dataframe(data)
  File "/home/mab/freqtrade/freqtrade/strategy/interface.py", line 668, in ohlcvdata_to_dataframe
    return {pair: self.advise_indicators(pair_data.copy(), {'pair': pair})
  File "/home/mab/freqtrade/freqtrade/strategy/interface.py", line 668, in <dictcomp>
    return {pair: self.advise_indicators(pair_data.copy(), {'pair': pair})
  File "/home/mab/freqtrade/freqtrade/strategy/interface.py", line 685, in advise_indicators
    return self.populate_indicators(dataframe, metadata)
  File "/home/mab/freqtrade/user_data/strategies/GodStra.py", line 80, in populate_indicators
    dataframe = add_all_ta_features(
  File "/home/mab/freqtrade/.env/lib/python3.8/site-packages/ta/wrapper.py", line 559, in add_all_ta_features
    df = add_trend_ta(
  File "/home/mab/freqtrade/.env/lib/python3.8/site-packages/ta/wrapper.py", line 267, in add_trend_ta
    df[f"{colprefix}trend_adx"] = indicator_adx.adx()
  File "/home/mab/freqtrade/.env/lib/python3.8/site-packages/ta/trend.py", line 777, in adx
    adx_series[self._window] = directional_index[0 : self._window].mean()
IndexError: index 14 is out of bounds for axis 0 with size 12

mablue avatar Apr 15 '21 06:04 mablue

File "loadDailyStock.py", line 360, in loadDailyStock(strDate,db) File "loadDailyStock.py", line 247, in loadDailyStock dfSym = add_all_ta_features( File "C:\Users\Administrator\anaconda3\lib\site-packages\ta\wrapper.py", line 559, in add_all_ta_features df = add_trend_ta( File "C:\Users\Administrator\anaconda3\lib\site-packages\ta\wrapper.py", line 267, in add_trend_ta df[f"{colprefix}trend_adx"] = indicator_adx.adx() File "C:\Users\Administrator\anaconda3\lib\site-packages\ta\trend.py", line 777, in adx adx_series[self._window] = directional_index[0 : self._window].mean() IndexError: index 14 is out of bounds for axis 0 with size 7

bbsteps-system avatar Jun 08 '21 01:06 bbsteps-system

2021-08-09 19:24:47,300 - freqtrade - ERROR - Fatal exception! Traceback (most recent call last): File "/freqtrade/freqtrade/main.py", line 37, in main return_code = args'func' File "/freqtrade/freqtrade/commands/optimize_commands.py", line 54, in start_backtesting backtesting.start() File "/freqtrade/freqtrade/optimize/backtesting.py", line 596, in start min_date, max_date = self.backtest_one_strategy(strat, data, timerange) File "/freqtrade/freqtrade/optimize/backtesting.py", line 552, in backtest_one_strategy preprocessed = self.strategy.ohlcvdata_to_dataframe(data) File "/freqtrade/freqtrade/strategy/interface.py", line 744, in ohlcvdata_to_dataframe return {pair: self.advise_indicators(pair_data.copy(), {'pair': pair}) File "/freqtrade/freqtrade/strategy/interface.py", line 744, in return {pair: self.advise_indicators(pair_data.copy(), {'pair': pair}) File "/freqtrade/freqtrade/strategy/interface.py", line 761, in advise_indicators return self.populate_indicators(dataframe, metadata) File "/freqtrade/user_data/strategies/GodStra.py", line 102, in populate_indicators dataframe = add_all_ta_features( File "/home/ftuser/.local/lib/python3.9/site-packages/ta/wrapper.py", line 559, in add_all_ta_features df = add_trend_ta( File "/home/ftuser/.local/lib/python3.9/site-packages/ta/wrapper.py", line 267, in add_trend_ta df[f"{colprefix}trend_adx"] = indicator_adx.adx() File "/home/ftuser/.local/lib/python3.9/site-packages/ta/trend.py", line 777, in adx adx_series[self._window] = directional_index[0 : self._window].mean() IndexError: index 14 is out of bounds for axis 0 with size 1

Any solution to this? Or a workaround without having to change params?

Sshimaninja avatar Aug 09 '21 19:08 Sshimaninja

I recently solved this particular issue. You need a minimum of 28 sets of ticker features (open, high, low, close, volume) in order to properly calculate all of the TA features that are derived from the add_all_ta_features function, otherwise you'll get this error (and others if you go even lower). It's not shown anywhere in the documentation but I got this bug when adding fewer than 28 sets but it went away at 28 and higher. Hope that helps, this was driving me nuts.

legionnaire12 avatar Feb 04 '22 15:02 legionnaire12

Wow thanks @legionnaire12. I might check this out and see if I can get it to work with your workaround. I put this project on hold due to this issue months ago.

Sshimaninja avatar Feb 04 '22 16:02 Sshimaninja

I recently solved this particular issue. You need a minimum of 28 sets of ticker features (open, high, low, close, volume) in order to properly calculate all of the TA features that are derived from the add_all_ta_features function, otherwise you'll get this error (and others if you go even lower). It's not shown anywhere in the documentation but I got this bug when adding fewer than 28 sets but it went away at 28 and higher. Hope that helps, this was driving me nuts.

Confirming @legionnaire12 's comment. You need to have more than 28 rows in your dataframe to proceed.

Thuruv avatar Oct 16 '23 03:10 Thuruv