Skip to main content

Plotting package for Backtrader (Bokeh)

Project description


Library to add extended plotting capabilities to backtrader ( Currently the only available backend is Bokeh (


  • Interactive plots
  • Interactive backtrader optimization result browser (only supported for single-strategy runs)
  • Highly configurable
  • Different skinnable themes
  • Easy to use

Feel free to test it and play with it. I am happy about feedback, critics and ideas on backtrader forum (and also in GitHub issues):

Needs Python >= 3.6.



pip install backtrader_plotting


from backtrader_plotting import Bokeh
from backtrader_plotting.schemes import Tradimo

<your backtrader code>

b = Bokeh(style='bar', plot_mode='single', scheme=Tradimo())

Minimal Example

import datetime

import backtrader as bt

from backtrader_plotting import Bokeh

class TestStrategy(bt.Strategy):
    params = (
        ('buydate', 21),
        ('holdtime', 6),

    def next(self):
        if len( == self.p.buydate:
  [0], size=None)

        if len( == self.p.buydate + self.p.holdtime:
            self.sell(self.datas[0], size=None)

if __name__ == '__main__':
    cerebro = bt.Cerebro()

    cerebro.addstrategy(TestStrategy, buydate=3)

    data = bt.feeds.YahooFinanceCSVData(
        # Do not pass values before this date
        fromdate=datetime.datetime(2000, 1, 1),
        # Do not pass values after this date
        todate=datetime.datetime(2001, 2, 28),

    b = Bokeh(style='bar', plot_mode='single')

Plotting Optimization Results

Another way to use this package is to use the OptBrowser to browse a backtrader optimization result:

cerebro.optstrategy(TestStrategy, buydate=range(1, 10, 1))
res =
bo = Bokeh()
browser = OptBrowser(bo, result)

This will start a Bokeh application (standalone webserver) displaying all optimization results. Different results can be selected and viewed.

It is possible possible to add further user-provided columns. When dealing with huge amounts of optimization results the number of results can be limited and the remaining results can be sorted by a user-provided function to allow for simple selection of the best results.


Please refert to the Wiki for further documentation:

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for backtrader-plotting, version 1.1.0
Filename, size File type Python version Upload date Hashes
Filename, size backtrader_plotting-1.1.0-py3-none-any.whl (62.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size backtrader_plotting-1.1.0.tar.gz (31.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page