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

How to create as sell order @ high price

  • I would like to create a sell order in backtrader which will sell @high price. How do i code the same? I have tried the following
    self.order=self.sell(exectype=bt.Order.Limit, price=self.high[0])

    But the same does not work. Self.high is defined as high price.

  • AFAIU the Backtrader engine tries to emulate the real time broker behavior. I doubt you could always sell at bar's high in real-life, right ? Because the high price happened in the past ( at the time the bar is reported)

    The only case where your order will be filled @current_bar_high is when the next bar high will be higher than the current one ( similarly to the real life ), or when you are issuing the limit order before the current bar (on previous bar) and somehow guess the next bar high price.


  • @raul4backtrader
    backtrader don't have self.high in strategy,unless you define it。maybe you should use



    data = self.getdatabyname( your data's name)
    self.order=self.sell(exectype=bt.Order.Limit, price=data.high[0])

    but you know,it is a limit order ,so your sell order maybe not fill or execute.

Log in to reply