diff --git a/backtesting/lib.py b/backtesting/lib.py index e1c5b3a4..f7715e20 100644 --- a/backtesting/lib.py +++ b/backtesting/lib.py @@ -451,6 +451,7 @@ def next(self): trade.sl = min(trade.sl or np.inf, self.data.Close[index] + self.__atr[index] * self.__n_atr) + class PercentageTrailingStrategy(Strategy): """ A strategy with automatic trailing stop-loss, trailing the current @@ -464,6 +465,7 @@ class PercentageTrailingStrategy(Strategy): overridden methods. """ _sl_percent = 5. + def init(self): super().init() @@ -486,6 +488,7 @@ def next(self): trade.sl = min(trade.sl or np.inf, self.data.Close[index]*(1+(self._sl_percent/100))) + # Prevent pdoc3 documenting __init__ signature of Strategy subclasses for cls in list(globals().values()): if isinstance(cls, type) and issubclass(cls, Strategy): diff --git a/backtesting/test/_test.py b/backtesting/test/_test.py index 3cbcc372..e4cc8d05 100644 --- a/backtesting/test/_test.py +++ b/backtesting/test/_test.py @@ -878,6 +878,7 @@ def next(self): stats = Backtest(GOOG, S).run() self.assertEqual(stats['# Trades'], 91) + class TestUtil(TestCase): def test_as_str(self): def func():