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/

    Way to disable shorting

    General Discussion
    3
    5
    679
    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.
    • M
      mttax last edited by backtrader

      Re: how to disable shorting

      Sorry to reopen this question, but is there an easy way to restrict from shorting?

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

        No, but it should be fairly easy for the user not to sell.

        Unless you let us know why it should be difficult.

        1 Reply Last reply Reply Quote 0
        • M
          mttax last edited by

          In some markets, such as Chinese Stock, people cannot sell short, which means if I buy(size=1), then I cannot sell(size=2).

          But in Backtrader, both orders would be executed successfully. So I'm wondering if there is any way to disable user code from selling short? If there is, would you mind giving me a short example? Thank you.

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

            Use self.close() to close your long positions. Another way is to use correct sizes of existing positions in the self.sell().

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

              @mttax said in Way to disable shorting:

              In some markets, such as Chinese Stock, people cannot sell short

              In markets in general you cannot simply sell short. You first need to contact people who have the stocks, agree on the leasing conditions, sign the agreement, notify the proper authority (not always), and you can then sell the stocks.

              @mttax said in Way to disable shorting:

              if I buy(size=1), then I cannot sell(size=2)

              Don't do it. The platform isn't there to think for you.

              Do this (as proposed by @ab_trader)

              @ab_trader said in Way to disable shorting:

              Use self.close() to close your long positions. Another way is to use correct sizes of existing positions in the self.sell().

              You can always determine the current position by using self.getposition() where the returned position has the attribute size (you can use the @property shorthand position or even pass a data argument if you are using several data feeds). See Docs - Strategy

              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(); }); }