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 data parameter in buy, sell and close work?

    General Code/Help
    2
    2
    297
    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.
    • B
      backtrader14 last edited by backtrader14

      I am trying to understand how data parameter in buy, sell and close work. According to the docs

      data (default: None)
      
      For which data the order has to be created. If None then the first data in the system, self.datas[0] or self.data0 (aka self.data) will be used
      

      I assumed that when we initiate self.buy() , self.sell() and self.close() bactrader uses the close price as the default point of entry. But when I did something like this

      self.buy(data=self.data.close[0])
      self.buy(data=self.data.open[0])

      it is throwing error. So how does data parameter in buy, sell and close work?

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        data is the target and NOT a price. The doc says that the argument price is where you put the price. Although for some orders, there is more than once price.

        You probably want to read about the execution types, to understand when you can and you cannot determine the price.

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