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

Extending Data Feeds using PandasData to add custom calculated field

  • Re: How to Feed Backtrader Alternative Data

    I followed the guide at this link to add custom data fields using pandas
    but still getting attributes error -

    'Lines_LineSeries_DataSeries_OHLC_OHLCDateTime_Abst' object has no attribute 'RSI'

    def backtradercode ():
        #passing pandas dataframe to cerebro
        class PandasData(bt.feed.DataBase):
            params = (
                ('datetime', None ),
                ('Open', 1),
                ('High', 2),
                ('Low', 3),
                ('Close', 4),
                ('Volume', 5),
        #adding lines for calculated fields
        class CustomDataLoader(btfeeds.PandasData):
            lines = ('RSI', 'EMA8', 'VWAP', )
            params = (('RSI',6),
            datafields = btfeeds.PandasData.datafields + (['RSI', 'EMA8', 'VWAP'])
        dataframe = candleintra15mins_df
        data = bt.feeds.PandasData(dataname=dataframe)
        cerebro = bt.Cerebro(stdstats=False)
        class EMAMACDStrategy(bt.Strategy):
            #logging function for this strategy
            def log(self, txt, dt=None):
                dt = dt or self.datas[0].datetime.datetime(0)
                print('%s, %s' % (dt.isoformat(),txt))
            # declaring special variables
            def __init__(self):
                self.dataclose = self.datas[0].close
                self.RSI = self.datas[0].RSI
                self.EMA8 = self.datas[0].EMA8
                self.VWAP = self.datas[0].VWAP        

    Can someone please tell me why backtrader is still not recognizing the custom data fields as lines. Any help will be highly appreciated.

Log in to reply