Skip to content

Commit 4312281

Browse files
authored
Add code comment for change kernc#316
1 parent 8be5e18 commit 4312281

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

backtesting/lib.py

+7
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,13 @@ def set_trailing_sl(self, n_atr: float = 6):
441441

442442
def next(self):
443443
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+
"""
444451
index = len(self.data)-1
445452
for trade in self.trades:
446453
if trade.is_long:

0 commit comments

Comments
 (0)