In: https://www.backtrader.com/docu/trade.html?highlight=trade
It reads:
isopen (bool): records if any update has opened the trade
I'm wondering which of these options this refers:
- Trade was filled
- Trade was sent to broker
- Trade was accepted
Here's what I'm trying to achieve:
At the end of a backtest, I'm saving all the trades to a pickle file so that I can examine them
I would like to know, for each order (buy / sell / close): when the order was sent to the broker and when the order was filled.
Here's what I have so far, but I'm not sure what I'm getting from trade.dtopen
:
for index, data in enumerate(strategy.datas):
dataname = data._name
data_trades = strategy._trades[data][0]
trades = []
for trade in data_trades:
try:
trades.append({'ticker' : trade.data._name,
'bar_closed' : len(trade.data),
'trade_ref' : trade.ref,
'pnl' : round(trade.pnl, 2),
'bar_opened' : trade.baropen,
'date_opened' : trade.data.num2date(trade.dtopen),
'bar_closed' : trade.barclose,
'date_closed' : trade.data.num2date(trade.dtclose),
'n_bars_open_for' : trade.barlen,
'entry_trade' : trade.history[0]['event']['order'].info,
'exit_trade' : trade.history[1]['event']['order'].info,
'entry_price' : trade.history[0]['event']['price'],
'exit_price' : trade.history[1]['event']['price']
})
except Exception as e:
pass
Thanks for any assistance!