Backtrader Community

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

    How to create as sell order @ high price

    General Discussion
    4
    4
    412
    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.
    • R
      raul4backtrader last edited by

      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.

      tianjixuetu 1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • J T
          J T last edited by

          Self.data.high?

          1 Reply Last reply Reply Quote 0
          • tianjixuetu
            tianjixuetu @raul4backtrader last edited by

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

            self.datas[0].high[0]  
            

            or

            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.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors