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/

    Bug in bbroker._try_exec_limit()

    General Code/Help
    1
    1
    97
    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
      Batman last edited by

      In the method:

      def _try_exec_limit(self, order, popen, phigh, plow, plimit):
              if order.isbuy():
                  if plimit >= popen:
                      # open smaller/equal than requested - buy cheaper
                      pmax = min(phigh, plimit)
                      p = self._slip_up(pmax, popen, doslip=self.p.slip_open,
                                        lim=True)
                      self._execute(order, ago=0, price=p)
                  elif plimit >= plow:
                      # day low below req price ... match limit price
                      self._execute(order, ago=0, price=plimit)
      
              else:  # Sell
                  if plimit <= popen:
                      # open greater/equal than requested - sell more expensive
                      pmin = max(plow, plimit)
                      p = self._slip_down(plimit, popen, doslip=self.p.slip_open,
                                          lim=True)
                      self._execute(order, ago=0, price=p)
                  elif plimit <= phigh:
                      # day high above req price ... match limit price
                      self._execute(order, ago=0, price=plimit)
      

      The line:

      p = self._slip_down(plimit, popen, doslip=self.p.slip_open,
                                          lim=True)
      

      Should use "pmin" instead of "plimit" (as it uses "pmax" in the buy case):

      p = self._slip_down(pmin, popen, doslip=self.p.slip_open,
                                          lim=True)
      

      It is not adjusting the limit price before calling _slip_down().

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