-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
Expected behavior
The SLs should be displayed in the trade list (within the result stats) whenever they are set (according to the strategy).

Code sample
from backtesting import Backtest, Strategy
from backtesting.test import GOOG
from backtesting.lib import crossover
class Strat(Strategy):
def init(self):
pass
def next(self):
if self.position:
pass
else:
price = self.data.Close[-1]
self.buy(size = 1, sl = price - 10, tp = price + 20)
bt = Backtest(GOOG, Strat, cash=10_000)
output = bt.run()
display(output._trades.iloc[30:33])
bt.plot()Actual behavior
When I get the list of the trades, some of them are unprovided with the SL. This seems to happen only for the trades being closed BELOW the set SL.
This issue seems to be an unfixed part of the bug report #1288 by @xyffar.
Additional info, steps to reproduce, full crash traceback, screenshots
Software versions
backtesting.__version__: 0.6.5pandas.__version__: 2.3.3numpy.__version__: 1.26.2bokeh.__version__: 3.8.1- OS: Linux 6.14.0-36-generic x86_64
Metadata
Metadata
Assignees
Labels
No labels