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/

    I wonder What self.bar_executed means??

    General Code/Help
    4
    11
    1636
    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.
    • 황윤태
      황윤태 last edited by

          def notify_order(self, order):
               self.bar_executed = len(self)
         def next(self)
              if len(self) >= (self.bar_executed + 5):
      

      I am studying Backtrader Quickstart Guide in a and I wonder what each of the above functions means.

      From what I understand, the meaning of if len(self) >= (self.bar_executed + 5): was close price >= close price within 5 minutes.

      Could you tell me what the exact meaning is?

      Thank you in advance to all the people who answered.

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

        self.bar_executed records the length of the data feed at the moment when order related notification issued.

        @황윤태 said in I wonder What self.bar_executed means??:

        if len(self) >= (self.bar_executed + 5):

        this just compare if length of the data feed in current next() call is more than self.bar_executed + 5, no prices are involved, no minutes are involved.

        • 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 0
        • 황윤태
          황윤태 last edited by

          Thank you . your reply !
          if my data is follows:

          date                     close
          2020.04.05           100  
          2020.04.06           101         
          2020.04.07           102
          2020.04.08           101
          2020.04.09           105
          2020.04.10           120
          
          
          if len(self) >= (self.bar_executed + 5):
          

          Does the above code mean that you will use one of the prices from April 5, 2020 to April 9, 2020?

          1 Reply Last reply Reply Quote 0
          • 황윤태
            황윤태 @ab_trader last edited by

            @ab_trader Thank you . your reply !
            if my data is follows:

            date                     close
            2020.04.05           100  
            2020.04.06           101         
            2020.04.07           102
            2020.04.08           101
            2020.04.09           105
            2020.04.10           120
            
            if len(self) >= (self.bar_executed + 5):
            

            Does the above code mean that you will use one of the prices from April 5, 2020 to April 9, 2020?

            @ab_trader said in I wonder What self.bar_executed means??:

            self.bar_executed records the length of the data feed at the moment when order related notification issued.

            @황윤태 said in I wonder What self.bar_executed means??:

            if len(self) >= (self.bar_executed + 5):

            this just compare if length of the data feed in current next() call is more than self.bar_executed + 5, no prices are involved, no minutes are involved.

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

              The code shown in the post doesn't use prices. It counts length of the data feed itself.

              • 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 0
              • 황윤태
                황윤태 @ab_trader last edited by

                @ab_trader Thank you your response!!
                But I don't understand why you're using it.

                For example, if the length of the data is from April 1st to April 30th, 2004, does if len(self) >= (self.bar_executed + 5) mean that the transaction will be made on a 5th basis?

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

                  It is used to generate sell order on the fifth bar after position open.

                  • 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 0
                  • 황윤태
                    황윤태 @ab_trader last edited by

                    @ab_trader wow!!! I understand thank you !!!!!!!!! thank you!!

                    1 Reply Last reply Reply Quote 0
                    • J T
                      J T last edited by

                      I think it is just a tracker, to do something within 5 bars after u bought. So within that if statement, u can do something like if stochastics go up, add more or stochastics down, reduce position.

                      Likewise u can reverse that if statement, so u do nothing and calm down for 5 bars, then only take action after 5 bars.

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

                        Is there a way to track how long you have been out of position in a similar manner to this?

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

                          @B-U I believe that it is easier to count bars for which condition not self.position is True and reset the counter every time the position exists. Something like

                          def __init__(self):
                              outofposition = 0
                          
                          def next(self):
                              if not self.position:
                                  outofposition +=1
                              else:
                                  outofposition = 0
                          
                          • 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 0
                          • 1 / 1
                          • First post
                            Last post
                          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors