For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Upgrading from -> breaks things

  • Hello,

    I'm trying to upgrade from backtrader to a more recent release, and things break for me.

    First of all, I operate mostly on minute data and previously all of my charts would work on minute bars.

    Now, the data appears to be loading in a daily timeframe, even though it is clearly minute data.... How do I fix this?

    Then when I try to plot things, I get the following traceback:

      File "/home/xnox/ig/backtrader/backtrader/", line 739, in plot
        start=start, end=end)
      File "/home/xnox/ig/backtrader/backtrader/plot/", line 218, in plot
        self.plotdata(data, self.dplotsover[data])
      File "/home/xnox/ig/backtrader/backtrader/plot/", line 656, in plotdata
        color=color, label=datalabel)
      File "/home/xnox/ig/backtrader/backtrader/plot/", line 594, in plot_lineonclose
      File "/home/xnox/ig/backtrader/backtrader/plot/", line 534, in __init__
      File "/usr/lib/python3/dist-packages/matplotlib/axes/", line 1708, in add_line
      File "/usr/lib/python3/dist-packages/matplotlib/axes/", line 1730, in _update_line_limits
        path = line.get_path()
      File "/usr/lib/python3/dist-packages/matplotlib/", line 925, in get_path
      File "/usr/lib/python3/dist-packages/matplotlib/", line 632, in recache
        raise RuntimeError('xdata and ydata must be the same length')
    RuntimeError: xdata and ydata must be the same length

    Any idea how to work out which line / what is bombing out here?

  • Looking through latest threads on multi-frame data - it seems that you need compression param to be used for both .adddata and .resampledata.

  • @ab_trader


    TypeError: adddata() got an unexpected keyword argument 'compression'

    Adding compression to the BacktraderCSVData object, and resampledata call, still results in the inability to plot.

  • administrators

    @xnox said in Upgrading from -> breaks things:

    TypeError: adddata() got an unexpected keyword argument 'compression'

    @ab_trader meant to add timeframe and compressoin to data feed creation and not to adddata (a small typo)

    Releases have been tightening that, using those parameters more and more (and more with the addition of trading calendars). sessionend will now be needed more and more. In the code in your github report you can add:

    sessionend=datetime.time(17, 30),

    And things will plot. But they may easily break.

    The problem here being how the axes in matplotlib align if they have different lengths and things break easily.

  • administrators

    There was a pull request some time ago which added a calculation for aligning unequal (lengthwise) streams when plotting with multiple figures. The calculation was not 100% accurate, but it should be now with this commit.

Log in to reply