Set the future trailing stop-loss as some percent (`0 < pct < 1`) below the current price (default 5% below). .. note:: Stop-loss set by `pct` is inexact Stop-loss set by `set_trailing_pct` is converted to units of ATR with `mean(Close * pct / atr)`
(self, pct: float = .05)
| 481 | self.__n_atr = n_atr |
| 482 | |
| 483 | def set_trailing_pct(self, pct: float = .05): |
| 484 | """ |
| 485 | Set the future trailing stop-loss as some percent (`0 < pct < 1`) |
| 486 | below the current price (default 5% below). |
| 487 | |
| 488 | .. note:: Stop-loss set by `pct` is inexact |
| 489 | Stop-loss set by `set_trailing_pct` is converted to units of ATR |
| 490 | with `mean(Close * pct / atr)` and set with `set_trailing_sl`. |
| 491 | """ |
| 492 | assert 0 < pct < 1, 'Need pct= as rate, i.e. 5% == 0.05' |
| 493 | pct_in_atr = np.mean(self.data.Close * pct / self.__atr) # type: ignore |
| 494 | self.set_trailing_sl(pct_in_atr) |
| 495 | |
| 496 | def next(self): |
| 497 | super().next() |