Skip to content

Commit 18ecead

Browse files
authored
Merge pull request #3 from zlpatel/kernc#223
Trailing pct instead of ATR kernc#223
2 parents d81ae85 + a7732f2 commit 18ecead

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

Diff for: backtesting/lib.py

+3
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ def next(self):
451451
trade.sl = min(trade.sl or np.inf,
452452
self.data.Close[index] + self.__atr[index] * self.__n_atr)
453453

454+
454455
class PercentageTrailingStrategy(Strategy):
455456
"""
456457
A strategy with automatic trailing stop-loss, trailing the current
@@ -464,6 +465,7 @@ class PercentageTrailingStrategy(Strategy):
464465
overridden methods.
465466
"""
466467
_sl_percent = 5.
468+
467469
def init(self):
468470
super().init()
469471

@@ -486,6 +488,7 @@ def next(self):
486488
trade.sl = min(trade.sl or np.inf,
487489
self.data.Close[index]*(1+(self._sl_percent/100)))
488490

491+
489492
# Prevent pdoc3 documenting __init__ signature of Strategy subclasses
490493
for cls in list(globals().values()):
491494
if isinstance(cls, type) and issubclass(cls, Strategy):

Diff for: backtesting/test/_test.py

+1
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,7 @@ def next(self):
878878
stats = Backtest(GOOG, S).run()
879879
self.assertEqual(stats['# Trades'], 91)
880880

881+
881882
class TestUtil(TestCase):
882883
def test_as_str(self):
883884
def func():

0 commit comments

Comments
 (0)