For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Confused - How to find out, "am I LONG or am I Short?"...only: "Yes you are!" ?

  • Hey guys,
    it is so basic but a solution is not researchable for me...
    May I ask: How to find out, if my actual position is LONG or Short within "next" of the strategy-class?

    Every Quickstart-example has this Checkout:

            # Check if we are in the market
            if not self.position:

    Perfect, also possible to check position.size, position.price, len(self.position).
    But not if it is SELL or BUY?

    "notify_order" has order-Methods:

    • isbuy(): returns bool indicating if the order buys
    • issell(): returns bool indicating if the order sells
    But how to use them within "next" of the strategy-class?

    Should look like this somehow

    # Check if we are in the market
            if not self.position:
                if buy_signal:
                    self.order =
                if self.sell_signial:
                    self.order = self.sell()
                if bt.And(we-are-long, self.sell_signial):
                    self.order = self.close()
                if bt.And(we-are-short, self.buy_signial):
                    self.order = self.close()

    But how to define "we-are-short", "we-are-long" ???
    I tried alot, but only error-messages.
    Any ideas?

  • check for position size:

    if self.position.size < 0:
        # you are short
    elif self.position.size > 0:
        # you are long
         # no open position

  • hey yes,
    Sorry to mention: I printed out position.size to see, if it is going negativ...but it was allways positive, Long and Short.

    But anyway...somehow it is not...maybe I was looking wrong, or formating-error.

    Now it works with no error.
    Thanks so much for quick reply!

Log in to reply