Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    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?

    General Discussion
    7
    29
    3094
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      dasch @Squirrel Singing last edited by

      @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.

      1 Reply Last reply Reply Quote 0
      • D
        dasch @Squirrel Singing last edited by

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

        D 1 Reply Last reply Reply Quote 0
        • D
          dasch @dasch last edited by

          https://community.backtrader.com/topic/1397/resampling-fixes-for-1-9-67-122/2

          1 Reply Last reply Reply Quote 0
          • D
            dasch @Squirrel Singing last edited by

            @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).

            1 Reply Last reply Reply Quote 1
            • Squirrel Singing
              Squirrel Singing last edited by

              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()
              
              D stevetree 2 Replies Last reply Reply Quote 1
              • D
                dasch @Squirrel Singing last edited by

                @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.

                1 Reply Last reply Reply Quote 0
                • Squirrel Singing
                  Squirrel Singing last edited by

                  @dasch , thanks for your reply.

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

                  1 Reply Last reply Reply Quote 0
                  • Squirrel Singing
                    Squirrel Singing last edited by

                    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?

                    1 Reply Last reply Reply Quote 0
                    • stevetree
                      stevetree @Squirrel Singing last edited by

                      @Squirrel-Singing I can confirm that. Unfortunately, I have the same problem.

                      1 Reply Last reply Reply Quote 0
                      • 1
                      • 2
                      • 2 / 2
                      • First post
                        Last post
                      Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
                      $(document).ready(function () { app.coldLoad(); }); }