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/

    Oanda and resampling

    General Code/Help
    2
    3
    77
    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.
    • leecallen
      leecallen last edited by

      Merry Christmas everyone.

      One of my wife's gifts to me is time to work on my forex project today. So I am tackling a problem that has mystified me for weeks. Here is a snippet of my code:

      def runstrategy( currpair ):
          cerebro = bt.Cerebro()
          broker = BrokerCls( token='my-token-here', account='my-account-here', practice=True )
          cerebro.setbroker(broker)
          DataFactory = DataCls
          data = DataFactory( dataname=currpair[0] + '_' + currpair[1], timeframe=bt.TimeFrame.Minutes, compression=5 )
          cerebro.resampledata(data , timeframe=bt.TimeFrame.Minutes, compression=60, rightedge=True)
          cerebro.resampledata(data , timeframe=bt.TimeFrame.Minutes, compression=240, rightedge=True)
          cerebro.addstrategy()
          cycles = cerebro.run()
      

      and then:

          def next( self ):
              for i, d in enumerate(self.datas):
                  print(i, d.datetime.datetime(0).strftime('%Y-%m-%dT%H:%M:%S.%f'))
      

      My problem: next() gets invoked for my two resampled timeframes - 60 & 240 minutes - but never for the raw M5 'ticks'. Every output looks like this:

      0 2020-12-24T11:00:00.000000
      1 2020-12-24T08:00:00.000000
      

      So self.datas[0] contains the first resample (M60) and self.datas[1] contains the second (M240). Where is my M5 data???

      I have been working around this by request M1 data and resampling to M5,M60,M240. That way data0,data1,data2 reflect those timeframes. But I need more backfill data on startup, and I think I would get more if I request M5 data instead of M1.

      I hope I am just misunderstanding something.

      Thanks to any fellow nerds who are active here today. And yes, I realize not everyone celebrates Christmas.

      1 Reply Last reply Reply Quote 0
      • R
        rajanprabu last edited by

        hi @leecallen You did not add the ticks to BT but only the resamples ones.

        cerebro.adddata(data) would also take ticks in to next ()

        1 Reply Last reply Reply Quote 0
        • leecallen
          leecallen last edited by

          @rajanprabu said in Oanda and resampling:

          cerebro.adddata(data)

          Omigod THANK YOU! So fast, so simple, and so right.

          It's a festivus miracle!

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors