| 425 | name='exit portion', plot=plot, overlay=False, scatter=True, color='black') |
| 426 | |
| 427 | def next(self): |
| 428 | super().next() |
| 429 | |
| 430 | exit_portion = self.__exit_signal[-1] |
| 431 | if exit_portion > 0: |
| 432 | for trade in self.trades: |
| 433 | if trade.is_long: |
| 434 | trade.close(exit_portion) |
| 435 | elif exit_portion < 0: |
| 436 | for trade in self.trades: |
| 437 | if trade.is_short: |
| 438 | trade.close(-exit_portion) |
| 439 | |
| 440 | entry_size = self.__entry_signal[-1] |
| 441 | if entry_size > 0: |
| 442 | self.buy(size=entry_size) |
| 443 | elif entry_size < 0: |
| 444 | self.sell(size=-entry_size) |
| 445 | |
| 446 | |
| 447 | class TrailingStrategy(Strategy): |