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/

    limit close order syntax..

    General Code/Help
    3
    3
    27
    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.
    • P
      praxis last edited by

      Hello!

      This is the code I'm playing with:

      def next(self):
          if not self.position:  # not in the market
              if self.crossover > 0:  # if fast crosses slow to the upside
                  self.buy()  # enter long
          elif self.crossover < 0:  # in the market & cross to the downside
              self.close()  # close long position
      

      It enters a long position on SMA crossover and closes it out if we cross under.

      I'd like to modify so that once I enter a position, it automatically creates a limit close order at say, +25% of the fill price.

      So after self.buy() at a crossover at $100 a share, for example. I want immediately to submit a limit close for $125 to be executed if/when the price reaches that point.

      Any feedback would be appreciated, I'm awful at python but working hard at being less so, but the existing documentation isnt sinking in for me yet.

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

        Get entry order execution price from the notify_order(), use it to calculate your limit order price and issue the limit order right in the notify_order() or in the next().

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

          To add to @ab_trader great answer, you can get the order execution price in notifiy_order using:

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