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/

    How to build on last order to further execute orders?

    General Code/Help
    3
    7
    191
    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.
    • Zoutain Ye
      Zoutain Ye last edited by

      basically I want to check the last buy order, if current close is larger than last execution, we buy another 50% in from the rest of cash. but no more than 3 times.
      The command wont execute, I know it could to be something like

      order.executed.price[0]
      

      but I couldn't find a right expression for it:

      def next(self):
              self.count = 0
              if not self.position:
                  if self.datahigh[0]>self.upper:
                      dif =self.short - self.long
                      if dif > 0:
                          self.order = self.order_target_percent(target=0.5)
      
              else:
                  if self.datalow[0] < self.lower:
                      dif = self.short - self.long
                      if dif < 0:
                          self.order = self.close()
      
                  elif self.data.close[0] < self.short*0.90:
                      self.order = self.close()
      
                  elif self.close[0] > order.executed.price[0]*1.5:
                      if self.count < 4:
                          self.order = self.order_target_percent(target=0.5)
                          self.count += 1
                          self.order = self.order_target_percent(target=0.5)
      

      please help

      1 Reply Last reply Reply Quote 0
      • Zoutain Ye
        Zoutain Ye last edited by

        got a redundant line in the end. please ignore

        1 Reply Last reply Reply Quote 0
        • Zoutain Ye
          Zoutain Ye last edited by

          Re: How to build on last order to further execute orders?

          tried

          elif self.close[0] > self.buyprice[0] * 1.5:
          or
          elif self.close[0] > self.buyprice * 1.5:
          

          doesn't really work
          and
          I can't modify my post? can't even delete it?

          1 Reply Last reply Reply Quote 0
          • run-out
            run-out last edited by

            Is your closing price really going to increase by 1.5 times? That's a pretty big move.

            RunBacktest.com

            1 Reply Last reply Reply Quote 0
            • Zoutain Ye
              Zoutain Ye last edited by

              just trying to figure out a way to execute this kind of request.

              run-out 1 Reply Last reply Reply Quote 0
              • run-out
                run-out @Zoutain Ye last edited by

                @Zoutain-Ye The point i'm making is your if/elif statment might not trigger if your price isn't increasing by 50% over the buyprice. That might be stopping execution.

                RunBacktest.com

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

                  First, set variable to count entries.

                  Then, from notify_order get execution price when counter is zero and set it to separate variable.

                  In the next() check if current close higher than execution price, then if counter is less than 4 issue the order and increase the counter (ideally this increase should be done in notify_order after the order is confirmed as completed, but in case of market orders and enough cash should be good here)

                  On my opinion it will be easier to use target value order with the value equal to half of the cash available + value of the position open.

                  Don't forget to set counter to zero when position is closing.

                  • 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
                  • 1 / 1
                  • First post
                    Last post
                  Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors