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

Question about bracket order sample file

  • Hi everyone !

    I'm a bit stuck since few days on this issue ...
    I don't understand some lines of the code in the bracket sample.

    in notify_order, we have a condition l.50 if the order status is completed:

    if order.status == order.Completed:
                self.holdstart = len(self)

    What does mean self.holdstart = len(self) ?
    And what is exactly len(self) ?

    • Does that mean we are holding some time for the next order ?

    Also in next l.121, we have a condition if we are not in position:

    else:  # in the market
                if (len(self) - self.holdstart) >= self.p.hold:
                    pass  # do nothing in this case

    What are we exactly doing with if (len(self) - self.holdstart) >= self.p.hold ?
    And why are we passing if the condition is True ?

    Thanks for your help !

    PS: I already checked that post, but it wasn't really helpful

  • Exactly what I was looking for ! Thanks @ab_trader !

  • Also @ab_trader I still don't understand why this piece of code is written in the sample, it sounds totally useless:

    else:  # in the market
                if (len(self) - self.holdstart) >= self.p.hold:
                    pass  # do nothing in this case

    If we are in the market and if the data feed length - holdstart >= position hold, then we do nothing ... ?
    If we remove this piece of code it's gonna work exactly the same way ...

    In the link you provided, at least there were logic behind it:

                # Already in the market ... we might sell
                if len(self) >= (self.bar_executed + 5):
                    # SELL, SELL, SELL!!! (with all possible default parameters)
                    self.log('SELL CREATE, %.2f' % self.dataclose[0])
                    # Keep track of the created order to avoid a 2nd order
                    self.order = self.sell()

  • Just take the fact that it does nothing because nothing should be done.

  • ok @ab_trader ! Thanks for your feedbacks !

Log in to reply