mplfinance icon indicating copy to clipboard operation
mplfinance copied to clipboard

TypeError: object of type 'int' has no len() - renko with return_calculated_values and mav

Open camstuart opened this issue 4 years ago • 2 comments

Hello,

Firstly i'd like to say this is an excellent library, very very good indeed, and I really appreciate the work done here.

I am using the return_calculated_values feature so I can test (and hopefully add to the plot) my own studies that are based on the renko data.

I am using python 3.7 on Google Colab, the following code works perfectly, and retvals is populated:

retvals = {}
mpf.plot(df, type='renko', return_calculated_values=retvals,
         title=f'ADAUSDT / Renko Chart (1m base)',
         renko_params=dict(brick_size='atr', atr_length=10),
         style='yahoo', figratio=(35,12),figscale=1.8
)

However, adding mav=10 or mav=(10) generates an error:

retvals = {}
mpf.plot(df, type='renko', return_calculated_values=retvals, mav=(10),
         title=f'ADAUSDT / Renko Chart (1m base)',
         renko_params=dict(brick_size='atr', atr_length=10),
         style='yahoo', figratio=(35,12),figscale=1.8
)

TypeError                                 Traceback (most recent call last)
<ipython-input-72-29c81de85c1f> in <module>()
      5          title=f'ADAUSDT / Renko Chart (1m base)',
      6          renko_params=dict(brick_size='atr', atr_length=10),
----> 7          style='yahoo', figratio=(35,12),figscale=1.8
      8 )

/usr/local/lib/python3.7/dist-packages/mplfinance/plotting.py in plot(data, **kwargs)
    483         if config['mav'] is not None:
    484             mav = config['mav']
--> 485             if len(mav) != len(mavprices):
    486                 warnings.warn('len(mav)='+str(len(mav))+' BUT len(mavprices)='+str(len(mavprices)))
    487             else:

TypeError: object of type 'int' has no len()

Dependencies:

mplfinance in /usr/local/lib/python3.7/dist-packages (0.12.7a17)
pandas in /usr/local/lib/python3.7/dist-packages (from mplfinance) (1.1.5)
matplotlib in /usr/local/lib/python3.7/dist-packages (from mplfinance) (3.2.2)
numpy>=1.15.4 in /usr/local/lib/python3.7/dist-packages (from pandas->mplfinance) (1.19.5)
pytz>=2017.2 in /usr/local/lib/python3.7/dist-packages (from pandas->mplfinance) (2018.9)
python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas->mplfinance) (2.8.1)
pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mplfinance) (2.4.7)
kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mplfinance) (1.3.1)
cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mplfinance) (0.10.0)
six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.7.3->pandas->mplfinance) (1.15.0)

Thanks

camstuart avatar May 17 '21 13:05 camstuart

Looks like a bug plain and simple. Been there for a little less than a year, but only rears its head when mav is a single integer (instead of a list or typle) and return_calculated_values is in use.

As a work-around, until this is fixed, try making mav into a tuple with a single value. I think that will work:

retvals = {}
mpf.plot(df, type='renko', return_calculated_values=retvals, mav=(10,),
         title=f'ADAUSDT / Renko Chart (1m base)',
         renko_params=dict(brick_size='atr', atr_length=10),
         style='yahoo', figratio=(35,12),figscale=1.8
  • Notice the comma after the "10" in mav=(10,).

DanielGoldfarb avatar May 19 '21 15:05 DanielGoldfarb

Thanks @DanielGoldfarb that has got me out of trouble

camstuart avatar May 23 '21 11:05 camstuart