We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8be5e18 commit 4312281Copy full SHA for 4312281
backtesting/lib.py
@@ -441,6 +441,13 @@ def set_trailing_sl(self, n_atr: float = 6):
441
442
def next(self):
443
super().next()
444
+ """
445
+ self.data in init() is different from self.data in next(). self.data in init() has all the data.
446
+ while the one in next() gets accumulated data over iterations. i.e. 5 iterations -> 5 data. n iteration -> n data.
447
+ so doing self.data.Close[-1] in next() gets you the last record.
448
+ but the same is not true for self.__atr, because self.__atr always has fully computed set from init(),
449
+ so we need to use absolute index while accessing atr value from self.__atr.
450
451
index = len(self.data)-1
452
for trade in self.trades:
453
if trade.is_long:
0 commit comments