File tree 1 file changed +17
-1
lines changed
1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -452,11 +452,27 @@ def next(self):
452
452
self .data .Close [index ] + self .__atr [index ] * self .__n_atr )
453
453
454
454
class PercentageTrailingStrategy (Strategy ):
455
- _sl_percent = 5
455
+ """
456
+ A strategy with automatic trailing stop-loss, trailing the current
457
+ price at distance of some percentage. Call
458
+ `PercentageTrailingStrategy.set_trailing_sl()` to set said percentage
459
+ (`5` by default). See [tutorials] for usage examples.
460
+
461
+ [tutorials]: index.html#tutorials
462
+
463
+ Remember to call `super().init()` and `super().next()` in your
464
+ overridden methods.
465
+ """
466
+ _sl_percent = 5.
456
467
def init (self ):
457
468
super ().init ()
458
469
459
470
def set_trailing_sl (self , percentage : float = 5 ):
471
+ assert percentage > 0 , "percentage must be greater than 0"
472
+ """
473
+ Sets the future trailing stop-loss as some (`percentage`)
474
+ percentage away from the current price.
475
+ """
460
476
self ._sl_percent = percentage
461
477
462
478
def next (self ):
You can’t perform that action at this time.
0 commit comments