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/

    Simulating Limit Orders Clarifications

    General Discussion
    2
    3
    840
    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.
    • dimitar-petrov
      dimitar-petrov last edited by

      Hello All,

      I am wondering what is a correct sumulation when there is a gap between 2 consecutive bars.

         datetime    open    high     low   close 
       2016-12-12  785.04  791.25  784.35  789.27 
       2016-12-13   793.9  804.38  793.34   796.1 
      

      Let's execute a long limit order on 2016-12-12 with price equal to the high of current bar (791.25)

      ipdb> pprint(vars(order.created))
      {'comm': 0.0,
       'dt': 736310.9999999999,
       'exbits': deque([]),
       'margin': None,
       'p1': 0,
       'p2': 0,
       'pclose': 789.27,
       'pnl': 0.0,
       'pprice': 0,
       'price': 791.25,
       'pricelimit': 791.25,
       'psize': 0,
       'remsize': 0,
       'size': 6,
       'trailamount': None,
       'trailpercent': None,
       'value': 0.0}
      

      BT will skip that order execution due to the following logic in ./backtrader/brokers/bbroker.py(717)_try_exec_limit()

          718             if plimit >= popen:
          719                 # open smaller/equal than requested - buy cheaper
          720                 pmax = min(phigh, plimit)
          721                 p = self._slip_up(pmax, popen, doslip=self.p.slip_open,
          722                                   lim=True)
          723                 self._execute(order, ago=0, price=p)
          724             elif plimit >= plow:
          725                 # day low below req price ... match limit price
          726                 self._execute(order, ago=0, price=plimit)
      

      Technically our limit order price is between high of previous bar and low of current bar, so during live trading that order will be executed I think.

      I am wondering what are your thoughs on this scenario.

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

        If you issue an order on 2016-12-12 (the timeframe seems daily) it won't be considered for execution until 2016-12-13.

        The bar on 2016-12-12 is already closed when you see it.

        dimitar-petrov 1 Reply Last reply Reply Quote 0
        • dimitar-petrov
          dimitar-petrov @backtrader last edited by

          Thanks for clarification.

          I had missunderstanding of Stop vs Limit Order.

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
          $(document).ready(function () { app.coldLoad(); }); }