Closed
Description
Expected Behavior
Number of trades shouldn't account for open trade at last candle.
._trades shouldnt return an ExitBar, ExitPrice, PnL, ReturnPct, ExitTime, and a Duration for open trade.
Actual Behavior
Number of trades accounts for open trade at last candle.
._trades returns an ExitBar, ExitPrice, PnL, ReturnPct, ExitTime, and a Duration for an open trade.
Steps to Reproduce
prediction (2).csv
prediction (1).csv
- Set prediction (1).csv as Data
- Run it through bt.run
- Last trade should be open since forecastedClose > Open
- Set prediction (2).csv as Data
- Run it through bt.run
- Last trade is closed as it should be since forecastedClose < Open
ALTERNATIVELY, use any strategy that should have an open trade at the last candle.
from backtesting import Strategy, Backtest
class MyStrategy(Strategy):
Data = prediction
def init(self):
super().init()
def next(self):
if self.data.forecastedClose>self.data.Open:
self.buy()
elif self.data.forecastedClose<self.data.Open:
self.position.close()
bt = Backtest(prediction, MyStrategy, cash=1000, trade_on_close=False)
stats=bt.run()
stats
stats._trades
Additional info
._trades output for prediction 1
._trades output for prediction 2
- Backtesting version: 0.3.2