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

Bokeh Integration - Interactive Webbrowser Plotting



  • Thank you, happy to hear!



  • @vbs I'm not sure if this is something I'm doing, but is there a way to set the precision? I'm using this to backtest FX which needs more than 2/3 decimal places.



  • Not possible at the moment but I will try to add it.



  • Hi,

    thanks for the hard work here.

    when installing I get the error:

    byte-compiling build\bdist.win-amd64\egg\backtrader_plotting\bokeh\bokeh.py to bokeh.cpython-35.pyc
      File "build\bdist.win-amd64\egg\backtrader_plotting\bokeh\bokeh.py", line 41
        self.figures: List[Figure] = []
                    ^
    SyntaxError: invalid syntax
    
    
    

    Any ideas what I am doing wrong pls?



  • I guess the problem is your Python version. You need at least Python 3.6.



  • Many thanks! got it working now - great work.



  • It needs python 3.6 to run. Your problem curre



  • Hello

    I can't get the "develop" version installed. I am running Anaconda python 3.6 and at the end there's an error. Could you help advise how I can fix this?

    Thanks,

    Kevin

    Finished processing dependencies for backtrader-plotting==0.1
    running develop
    Checking .pth file support in build/bdist.macosx-10.7-x86_64
    /Users/kevin/anaconda2/envs/py36/bin/python -E -c pass
    TEST FAILED: build/bdist.macosx-10.7-x86_64 does NOT support .pth files
    error: bad install directory or PYTHONPATH

    You are attempting to install a package to a directory that is not
    on PYTHONPATH and which Python does not read ".pth" files from. The
    installation directory you specified (via --install-dir, --prefix, or
    the distutils default setting) was:

    build/bdist.macosx-10.7-x86_64
    

    and your PYTHONPATH environment variable currently contains:

    './build/bdist.macosx-10.7-x86_64/egg/'
    

    Here are some of your options for correcting the problem:

    • You can choose a different installation directory, i.e., one that is
      on PYTHONPATH or supports .pth files

    • You can add the installation directory to the PYTHONPATH environment
      variable. (It must then also be on PYTHONPATH whenever you run
      Python and want to use the package(s) you are installing.)

    • You can set up the installation directory to support ".pth" files by
      using one of the approaches described here:

      https://setuptools.readthedocs.io/en/latest/easy_install.html#custom-installation-locations

    Please make the appropriate changes for your system and try again.



  • I uploaded a wheel to pypi. Could you give it a try?
    https://pypi.org/project/backtrader-plotting/



  • Thanks for the quick response! The pip install works fine but when the code run, there is some error as shown below. I seemed to remember having seen similar errors when I played with Bokeh mixing different resampled indicators. I am using 3 datas, data0 is 1 minute data, and data1 and data2 are resampled 15 mins and 1 hour data respectively. Could the resampled data be an issue?

    /Users/kevin/anaconda2/envs/py36/lib/python3.6/site-packages/bokeh/models/sources.py:137: BokehUserWarning:

    ColumnDataSource's columns must be of the same length. Current lengths: ('112040348808', 7905), ('4447201432close', 7906), ('4447201432colors_bars', 7906), ('4447201432colors_outline', 7906), ('4447201432colors_wicks', 7906), ('4447201432high', 7906), ('4447201432low', 7906), ('4447201432open', 7906), ('4447201432volume', 7906), ('4447201432volume_colors', 7906), ('datetime', 7906), ('index', 7906)

    Traceback (most recent call last):
    File "ES_bracketXover.py", line 257, in <module>
    runstrat(args)
    File "ES_bracketXover.py", line 244, in runstrat
    cerebro.plot(b)
    File "/Users/kevin/anaconda2/envs/py36/lib/python3.6/site-packages/backtrader/cerebro.py", line 991, in plot
    start=start, end=end, use=use)
    File "/Users/kevin/anaconda2/envs/py36/lib/python3.6/site-packages/backtrader_plotting/bokeh/bokeh.py", line 404, in plot
    self._blueprint_strategy(obj, start, end, **kwargs)
    File "/Users/kevin/anaconda2/envs/py36/lib/python3.6/site-packages/backtrader_plotting/bokeh/bokeh.py", line 248, in _blueprint_strategy
    bf.plot(s, strat_clk, master)
    File "/Users/kevin/anaconda2/envs/py36/lib/python3.6/site-packages/backtrader_plotting/bokeh/figure.py", line 163, in plot
    self.plot_observer(obj, master)
    File "/Users/kevin/anaconda2/envs/py36/lib/python3.6/site-packages/backtrader_plotting/bokeh/figure.py", line 188, in plot_observer
    self.plot_indicator(obj, master)
    File "/Users/kevin/anaconda2/envs/py36/lib/python3.6/site-packages/backtrader_plotting/bokeh/figure.py", line 253, in plot_indicator
    '3': self.figure.hex,
    AttributeError: 'Figure' object has no attribute 'hex'



  • I can just guess that you have an outdated Bokeh version. For a better guess you will need to add information what you are using and what you did in the first place to get to that error.



  • @vbs Hi, thanks for the response. Good news: I upgraded Bokeh to 0.13 and tried your minimised example with some yahoo csv daily data, and it did work in a notebook environment!

    Bad news: my own strategy code still didn't work : ( There's some new error information from the notebook though, please refer to the bottom of below message. Any guess of the issue? Is there something wrong with 2 resampled data? I am using minute data (data0) and two resampled datas 15-minutes, 60 minutes. Could this have caused some mess?

    /Users/kevin/anaconda2/envs/py36/lib/python3.6/site-packages/bokeh/models/sources.py:110: BokehUserWarning:

    ColumnDataSource's columns must be of the same length. Current lengths: ('4440411776close', 8475), ('4440411776colors_bars', 8475), ('4440411776colors_outline', 8475), ('4440411776colors_wicks', 8475), ('4440411776high', 8475), ('4440411776low', 8475), ('4440411776open', 8475), ('4440411776volume', 8475), ('4440411776volume_colors', 8475), ('4440443984', 8474), ('datetime', 8475), ('index', 8475)

    /Users/kevin/anaconda2/envs/py36/lib/python3.6/site-packages/bokeh/models/sources.py:110: BokehUserWarning:

    ColumnDataSource's columns must be of the same length. Current lengths: ('4440411776close', 8475), ('4440411776colors_bars', 8475), ('4440411776colors_outline', 8475), ('4440411776colors_wicks', 8475), ('4440411776high', 8475), ('4440411776low', 8475), ('4440411776open', 8475), ('4440411776volume', 8475), ('4440411776volume_colors', 8475), ('4440443984', 8474), ('4440444096', 8474), ('datetime', 8475), ('index', 8475)


    Exception Traceback (most recent call last)
    <ipython-input-5-fb7d00ce15b9> in <module>()
    21 args.plot=True
    22
    ---> 23 es.runstrat(args)

    ~/Dropbox/quantiacs/InteractiveBroker/PyBackTrader/ES_bracketXover.py in runstrat(args)
    251 #cerebro.plot(style='candle',iplot=False,volume=False)
    252 b = Bokeh(style='bar', plot_mode='single', )# scheme=Tradimo())
    --> 253 cerebro.plot(b)
    254
    255 def analyseDefaultArguments(args):

    ~/anaconda2/envs/py36/lib/python3.6/site-packages/backtrader/cerebro.py in plot(self, plotter, numfigs, iplot, start, end, width, height, dpi, tight, use, **kwargs)
    989 rfig = plotter.plot(strat, figid=si * 100,
    990 numfigs=numfigs, iplot=iplot,
    --> 991 start=start, end=end, use=use)
    992 # pfillers=pfillers2)
    993

    ~/anaconda2/envs/py36/lib/python3.6/site-packages/backtrader_plotting/bokeh/bokeh.py in plot(self, obj, figid, numfigs, iplot, start, end, use, **kwargs)
    402
    403 if isinstance(obj, bt.Strategy):
    --> 404 self._blueprint_strategy(obj, start, end, **kwargs)
    405 elif isinstance(obj, bt.OptReturn):
    406 if not hasattr(obj, 'strategycls'):

    ~/anaconda2/envs/py36/lib/python3.6/site-packages/backtrader_plotting/bokeh/bokeh.py in _blueprint_strategy(self, strategy, start, end, **kwargs)
    243 strat_figures.append(bf)
    244
    --> 245 bf.plot(master, strat_clk, None)
    246
    247 for s in slaves:

    ~/anaconda2/envs/py36/lib/python3.6/site-packages/backtrader_plotting/bokeh/figure.py in plot(self, obj, strat_clk, master)
    164 height_set = self._scheme.plot_height_observer
    165 else:
    --> 166 raise Exception(f"Unsupported plot object: {type(obj)}")
    167
    168 self.datas.append(obj)

    Exception: Unsupported plot object: <class 'backtrader.feed.DataClone'>