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

Help with plotting issue

  • I have created a custom datafeed. The dataframe I use have the columns:
    datetime, open, high, low, close, volume

    When I run the script with a strategy to plot simple moving average with my custom data feed I will get a chart with ohlc bars but no sma is plotted.

    When I use the inbuilt pandas data feed I get ohlc bars and sma plotted.

    I guess I have missed something. Can anyone see why sma is not plotted when using my custom data feed?

    Here are som code.

    The strategy:

    class St(bt.Strategy):
        def __init__(self):
            self.sma = bt.indicators.SimpleMovingAverage(

    My custom data feed:

    class CustomDataLoader(btfeeds.PandasData):
        lines = ('datetime', 'open', 'high', 'low', 'close', 'volume',)
        params = (('datetime', None), ('open', 0), ('high', 1), ('low', 2), ('close', 3), ('volume', 4),)

    How I load the data:

    data = CustomDataLoader(dataname=df)		# Plots only ohlc bars but no sma
    #data = bt.feeds.PandasData(dataname=df)	# Plots both ohlc bars and sma

    How I plot the result:

    # Plot the result

    Any help would be appreciated.

  • administrators

    @eric said in Help with plotting issue:

    class CustomDataLoader(btfeeds.PandasData):
        lines = ('datetime', 'open', 'high', 'low', 'close', 'volume',)

    You are adding this lines to the existing lines in PandasData possible overriding them with the wrong order (I couldn't tell, it never occurred to me to repeat the same lines declaration overriding the existing lines)

    You only need to define the parameters to given them fixed known (to you) values and only new lines.

Log in to reply