Skip to main content

Plotting package for Backtrader (Bokeh)

Project description


Plotting addon for backtrader to support Bokeh (and maybe more).

This is in an early development state. Expect bugs, heavy restructuring and commit reordering. Currently this is Python >=3.6 only.

Feel free to test it and play with it. I am happy about feedback, critics and ideas:



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 invoke Bokeh.plot_result. This function also supports passing a cerebro result object as it is generated in optimization:

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

This will start a Bokeh application (standalone webserver) displaying all optimization results.

NOTE: When using this feature with optreturn=True then your package of backtrader has to contain this change of mine:

Project details

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
backtrader_plotting-0.5.3-py3-none-any.whl (27.8 kB) Copy SHA256 hash SHA256 Wheel py3
backtrader_plotting-0.5.3.tar.gz (19.6 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page