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?



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


  • administrators

    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.


Log in to reply
 

});