Help with plotting issue
eric last edited by
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.
class St(bt.Strategy): def __init__(self): self.sma = bt.indicators.SimpleMovingAverage(self.data)
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 cerebro.plot(style='candlestick')
Any help would be appreciated.
class CustomDataLoader(btfeeds.PandasData): lines = ('datetime', 'open', 'high', 'low', 'close', 'volume',)
You are adding this lines to the existing lines in
PandasDatapossible 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.