question on determining trade information
example: print(self.trades.entry_price) print(self.trades.entry_bar)
I don't seem to be able to identify the correct way of using Strategy.trades for the available vars. I get a tuple error with no attribute? Can anyone throw me an example?
The docs say:
List of active trades
Tried printing self.trades? It's a list. (Indeed, it's actually a list-like tuple so it can't be modified.)
Hi Kernc. Thank you for replying. That makes sense now. But I am trying to access the information on individual trades. So that I can makes decisions during each next iteration.
an example would be to count bars from the most recent trade exit. I tried using class trade.exit_bar but it is not recognised as an attribute???
Please see: https://www.chiark.greenend.org.uk/~sgtatham/bugs.html
trade = self.trades[n] # get n-th sequential trade
trade.exit_bar # this *shouldn't* raise an error
https://github.com/kernc/backtesting.py/blob/8a7a932a352f2a4b4e16cff50daf587f2778e0e6/backtesting/backtesting.py#L556-L562
If the attribute is indeed not there, you need to update the library to the latest released version: pip install -U backtesting.