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/

    Question about bracket order sample file

    Indicators/Strategies/Analyzers
    brackets samples
    2
    6
    205
    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.
    • B
      balibou last edited by

      Hi everyone !

      I'm a bit stuck since few days on this issue ...
      I don't understand some lines of the code in the bracket sample.

      in notify_order, we have a condition l.50 if the order status is completed:

      if order.status == order.Completed:
                  self.holdstart = len(self)
      

      What does mean self.holdstart = len(self) ?
      And what is exactly len(self) ?

      • Does that mean we are holding some time for the next order ?

      Also in next l.121, we have a condition if we are not in position:

      else:  # in the market
                  if (len(self) - self.holdstart) >= self.p.hold:
                      pass  # do nothing in this case
      

      What are we exactly doing with if (len(self) - self.holdstart) >= self.p.hold ?
      And why are we passing if the condition is True ?

      Thanks for your help !

      PS: I already checked that post, but it wasn't really helpful

      1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by

        https://community.backtrader.com/topic/2422/i-wonder-what-self-bar_executed-means

        • If my answer helped, hit reputation up arrow at lower right corner of the post.
        • Python Debugging With Pdb
        • New to python and bt - check this out
        B 1 Reply Last reply Reply Quote 1
        • B
          balibou @ab_trader last edited by

          Exactly what I was looking for ! Thanks @ab_trader !

          1 Reply Last reply Reply Quote 0
          • B
            balibou last edited by

            Also @ab_trader I still don't understand why this piece of code is written in the sample, it sounds totally useless:

            else:  # in the market
                        #  COMPARE IF LENGTH OF THE DATA FEED - HOLDSTART IS >= POSITION HOLD
                        if (len(self) - self.holdstart) >= self.p.hold:
                            pass  # do nothing in this case
            

            If we are in the market and if the data feed length - holdstart >= position hold, then we do nothing ... ?
            If we remove this piece of code it's gonna work exactly the same way ...

            In the link you provided, at least there were logic behind it:

            else:
            
                        # Already in the market ... we might sell
                        if len(self) >= (self.bar_executed + 5):
                            # SELL, SELL, SELL!!! (with all possible default parameters)
                            self.log('SELL CREATE, %.2f' % self.dataclose[0])
            
                            # Keep track of the created order to avoid a 2nd order
                            self.order = self.sell()
            
            1 Reply Last reply Reply Quote 0
            • A
              ab_trader last edited by

              Just take the fact that it does nothing because nothing should be done.

              • If my answer helped, hit reputation up arrow at lower right corner of the post.
              • Python Debugging With Pdb
              • New to python and bt - check this out
              1 Reply Last reply Reply Quote 1
              • B
                balibou last edited by

                ok @ab_trader ! Thanks for your feedbacks !

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