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/

    Suggestions on close order

    General Discussion
    3
    5
    660
    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.
    • Jingsi
      Jingsi last edited by

      currently, close an order will call buy/sell in strategy class. and I found my future broker allow me to hold long position and short position at the same time,
      if I send one buy cmd and one sell cmd, I have two open positions! the only way to close the position is send a close cmd

      so, my suggestion is not to convert the close call within strategy class, XXStore or XXBroker will be better place

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

        The idea of the close order is to provide the simplified method to close existing position. If you don't want to close existing position, than the close order should not be used. If you want to hold long and short positions at the same time, than use buy and sell orders to initiate the positions.

        • 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
        Jingsi 1 Reply Last reply Reply Quote 0
        • Jingsi
          Jingsi @ab_trader last edited by

          @ab_trader I do want to close the existing order, but there is no way to do that in this system, no close to override in BrokerBase. I am suggest move close from Strategy to BrokerBase, It makes code much more extensible without lose any convenient

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

            Following the existing concept, I think that close order can be implemented at the strategy level only, similar to the target orders, for example. The reason is that it uses position size as an argument and position size relates to strategy. At the broker level it can be several positions open by different strategies in the same data feed. Simple moving of the close order to broker level can easily break the legacy of the bt scripts, since the call of the close order will be closing all positions in all strategies.

            If you desperately needs this, than sub-class the bbroker and write your own implementation. But honestly, the strategy can be written without using of the close order at all, therefore I think that this mod will bring more hassle than worth.

            • 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
            • ?
              A Former User last edited by

              what @ab_trader said is what you should follow to prevent later issues. You could overwrite the close method of the strategy and check for your broker. If it is your broker, use a different way to close the order, if not, just call super(self).close(order)

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