Backtrader Community

    • 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/

    Next() call not being delayed

    General Discussion
    4
    4
    1186
    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.
    • E
      etcetc last edited by etcetc

      I have an indicator with a period of 12 being initialized in my strategy.

      I am compressing 60 minutes into hour long bars.

      Based off of what I read on the wiki - the first next() call should not occur until 12 hours have passed in the data, correct? Yet my next() call is being triggered with only one item in self.data. Is there something I misunderstood with how compression works?

      edit: Just tried to remove compression and I still have the same issue. Here is my init function, using most of the boilerplate in oandatest.py

      I tried removing compression and this issue still occurs. Below is my strategy init function:

         def __init__(self):
          # To control operation entries
          self.orderid = list()
          self.order = None
      
          self.counttostop = 0
          self.datastatus = 0
      
          # Create SMA on 2nd data
          self.sma = bt.indicators.MovAv.SMA(self.data, period=self.p.smaperiod)
          self.atr = bt.indicators.ATR(self.data, period=20)
          self.highest = bt.indicators.MaxN(self.data, period=12)
          self.lowest = bt.indicators.MinN(self.data, period=12)
          self.margin = 0.0025
      
          print('--------------------------------------------------')
          print('Strategy Created')
          print('--------------------------------------------------')
      
      1 Reply Last reply Reply Quote 0
      • E
        etcetc last edited by etcetc

        Removed for edit

        1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators last edited by

          That code for sure is not enough to tell why next is called. But if you are using the oandatest sample, this sample calls next from prenext, because the point is seeing all received data and not waiting for the indicators.

          E 1 Reply Last reply Reply Quote 0
          • E
            etcetc @backtrader last edited by

            @backtrader Thank you, fixed.

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