Skip to content

Commit

Permalink
updated variable name as per code review comment kernc#223
Browse files Browse the repository at this point in the history
  • Loading branch information
zlpatel committed Jun 15, 2021
1 parent a7732f2 commit f954742
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions backtesting/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class PercentageTrailingStrategy(Strategy):
Remember to call `super().init()` and `super().next()` in your
overridden methods.
"""
_sl_percent = 5.
_sl_pct = 5.

def init(self):
super().init()
Expand All @@ -475,18 +475,18 @@ def set_trailing_sl(self, percentage: float = 5):
Sets the future trailing stop-loss as some (`percentage`)
percentage away from the current price.
"""
self._sl_percent = percentage
self._sl_pct = percentage/100

def next(self):
super().next()
index = len(self.data)-1
for trade in self.trades:
if trade.is_long:
trade.sl = max(trade.sl or -np.inf,
self.data.Close[index]*(1-(self._sl_percent/100)))
self.data.Close[index]*(1-self._sl_pct))
else:
trade.sl = min(trade.sl or np.inf,
self.data.Close[index]*(1+(self._sl_percent/100)))
self.data.Close[index]*(1+self._sl_pct))


# Prevent pdoc3 documenting __init__ signature of Strategy subclasses
Expand Down

0 comments on commit f954742

Please sign in to comment.