matplotlib / matplotlib/mplfinance

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

Open
#394 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
4.4k
Forks
678
PR merge metrics
No merged PRs in 30d

Description

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:

```python
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:

```python
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)
in ()
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Renko chart call with return_calculated_values and mav=10, then inspect plotting.py around line 485 where mav is passed to len(). Compare the scalar and tuple cases and verify that the corrected behavior still handles the reported Renko configuration without raising TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
matplotlib, python
Domain
data-visualization
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.