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

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\\egg\backtrader_plotting\bokeh\ to bokeh.cpython-35.pyc
      File "build\\egg\backtrader_plotting\bokeh\", 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?



    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:


    and your PYTHONPATH environment variable currently contains:


    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:

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

  • I uploaded a wheel to pypi. Could you give it a try?

  • 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/ 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 "", line 257, in <module>
    File "", line 244, in runstrat
    File "/Users/kevin/anaconda2/envs/py36/lib/python3.6/site-packages/backtrader/", line 991, in plot
    start=start, end=end, use=use)
    File "/Users/kevin/anaconda2/envs/py36/lib/python3.6/site-packages/backtrader_plotting/bokeh/", 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/", 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/", line 163, in plot
    self.plot_observer(obj, master)
    File "/Users/kevin/anaconda2/envs/py36/lib/python3.6/site-packages/backtrader_plotting/bokeh/", line 188, in plot_observer
    self.plot_indicator(obj, master)
    File "/Users/kevin/anaconda2/envs/py36/lib/python3.6/site-packages/backtrader_plotting/bokeh/", 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/ 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/ 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
    ---> 23 es.runstrat(args)

    ~/Dropbox/quantiacs/InteractiveBroker/PyBackTrader/ 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)
    255 def analyseDefaultArguments(args):

    ~/anaconda2/envs/py36/lib/python3.6/site-packages/backtrader/ 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)

    ~/anaconda2/envs/py36/lib/python3.6/site-packages/backtrader_plotting/bokeh/ in plot(self, obj, figid, numfigs, iplot, start, end, use, **kwargs)
    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/ in _blueprint_strategy(self, strategy, start, end, **kwargs)
    243 strat_figures.append(bf)
    --> 245 bf.plot(master, strat_clk, None)
    247 for s in slaves:

    ~/anaconda2/envs/py36/lib/python3.6/site-packages/backtrader_plotting/bokeh/ 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)}")
    168 self.datas.append(obj)

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

  • First of all, I want to say thank you! The interactivity of these plots is exactly what I was looking for. I am having an issue with custom indicators plotting on the same subplot. I am attempting to plot three "custom indicators" on the same subplot. However, when using Bokeh, the indicators plot on a seperate axis with the plotmaster param set.

    Here is the code:

    def init(self):
    self.iv30 = self.datas[0].iv30
    self.iv30_90p = self.datas[0].iv30_90p
    self.iv30_10p = self.datas[0].iv30_10p
    iv30 = bt.indicators.SMA(self.iv30, period=1, plotname = 'iv30', subplot=True)
    bt.indicators.SMA(self.iv30_90p, period=1, plotname = '90th', subplot=True, plotmaster=iv30)
    bt.indicators.SMA(self.iv30_10p, period=1, plotname = '10th', subplot=True, plotmaster=iv30)

    When I plot it with the standard cerebro.plot(), it plots as desired (all indicators on same subplot).


    However, plotting the strategy with Bokeh provides:


    Even with messing with the SMA params (setting subplot = False for SMAs with plotmaster set to iv30) I cannot get the subplots to plot on the same axis using Bokeh.

    Please excuse me if it is something simple. I am still very much an amateur in python.

    Thank you!

  • @vbs Have you stopped developing backtrader_plotting? The interactive plots are very nice and helpful. Can you please fix the plotmaster issue? Thanks!

  • Actually I am still planning to get back to this at some point but I got constantly distracted by other things in the last months. It is not dead but I can't make any promises.

  • In my experience visualisation thtough Bokeh is very promising, yet unusable. The plotnames are just too long, see my example:

    Anyone have some advice?

    Much appreciated.

  • I recently found time to work on this a bit again and finally reached something I call now version 1.0.0. I did alot of polishing and cleaning up the code base. All open issues on GitHub are fixed with this as far as I know.

    Some additions include:

    • being able to configure plotting completely independent from strategy code (which bothered me)
    • configurable hover tooltip
    • much easier optimization result browser
    • etc.

    It was not possible to edit the first post of this thread but the project is still available on GitHub :)

    I also tried my best to document the core components:

    I am very happy to hear your feedback and critics. Feel free to use also the issue tracker on GitHub:

    I know the generated pages to not look very great as I am bad at designing. I would be happy if someone of you who is maybe good with css could give it a try spice it a visually. I would be happy to include an updated css scheme!

  • Awesome! I've used this daily for the last year. Much appreciated.

  • It's possible to hide "Meta" tab? Also, how add another datas (timeframes) below main? Thx!

Log in to reply