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

Backtest vs live bars "off-by-1" discrepancy?



  • @Squirrel-Singing as I remember, as soon, as live data comes in, it will not right align, but I am not really sure anymore. I stopped using backtrader for live trading. I just maintain the btoandav20 store since then. This bug was somehow a dealbreaker for me.



  • @Squirrel-Singing but I remember, there was a release later, which addressed some intraday data alignment issues.





  • @Squirrel-Singing but for a possible solution you could create your own data feed, subtract the time difference and set the new time manually when new data gets available (checking if the feed is live).



  • Thanks Dasch for your comprehensive reply.

    The issue that I am seeing is an incorrect final delayed bar, where it is formed before the time period is over.

    Using the below screenshot as an example, GBPUSD closing price of 1.28984 at 8:05:00 is incorrect as it shows GBPUSD's closing price at the time of connection instead of at 08:05:00

    ccf9c381-d1b6-41fe-b409-ef644e575bb2-image.png

    Is it just me facing this problem or this data point got overlooked by others?

    Creating my own data filter/feed could be an option but I just find it incredible how users could live/paper trade with this incorrect data point.

    Code is attached below for reference.

    import backtrader as bt
    import datetime as dt
    import pytz as pytz
    
    class Test_Strategy (bt.Strategy):    
        def next (self):
            self.log (self.data.close[0])
        
        def notify_data(self, data, status):
            print('*' * 5, 'DATA NOTIF:', data._getstatusname(status))
        
        def log (self, text):
            print (self.data.datetime.datetime(0),": ", text)
    
    if __name__ == '__main__':
        ibstore = bt.stores.IBStore (host = '127.0.0.1', clientId = 110, port = 7497)
        data = ibstore.getdata (dataname = 'GBP.USD-CASH-IDEALPRO',       #GBP.USD-CASH-IDEALPRO, BARC-STK-LSE-GBP
                                rtbar = False,
                                tz=pytz.timezone('US/Eastern'),
                                )
        cerebro = bt.Cerebro()
        cerebro.broker = ibstore.getbroker()                                                          ###
        cerebro.resampledata (data, timeframe = bt.TimeFrame.Minutes, compression = 5, rightedge = True, boundoff = 0)
        cerebro.addstrategy (Test_Strategy)
        cerebro.run()
    


  • @Squirrel-Singing that was the reason why I stopped using it that much. The issue was not acknowledged and I didn't want to write too many workarounds since every time I changed something, new issues occurred.

    You could ask @backtrader about this issue.

    I don't have a too complicated strategy but I use current time and time periods to do some decisions, so the timestamps were an important part. I now just stream data from oanda, use ta-lib for some indicators, so no need for backtrader in this. For tests and experiments I still use backtrader.



  • @dasch , thanks for your reply.

    @backtrader , can I ask for your thoughts on the issue I mentioned 25 minutes earlier?



  • Realize that there's no reply, so just want to follow up and ask if anyone has any insights on this query that I raised?


Log in to reply
 

});