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



  • Re: how to disable shorting

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


  • administrators

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

    Unless you let us know why it should be difficult.



  • 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.



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


  • administrators

    @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


Log in to reply
 

});