@@ -49,7 +49,6 @@ class Strategy(metaclass=ABCMeta):
49
49
`backtesting.backtesting.Strategy.next` to define
50
50
your own strategy.
51
51
"""
52
-
53
52
def __init__ (self , broker , data , params ):
54
53
self ._indicators = []
55
54
self ._broker : _Broker = broker
@@ -292,7 +291,6 @@ class _Orders(tuple):
292
291
"""
293
292
TODO: remove this class. Only for deprecation.
294
293
"""
295
-
296
294
def cancel (self ):
297
295
"""Cancel all non-contingent (i.e. SL/TP) orders."""
298
296
for order in self :
@@ -320,7 +318,6 @@ class Position:
320
318
if self.position:
321
319
... # we have a position, either long or short
322
320
"""
323
-
324
321
def __init__ (self , broker : '_Broker' ):
325
322
self .__broker = broker
326
323
@@ -385,7 +382,6 @@ class Order:
385
382
[filled]: https://www.investopedia.com/terms/f/fill.asp
386
383
[Good 'Til Canceled]: https://www.investopedia.com/terms/g/gtc.asp
387
384
"""
388
-
389
385
def __init__ (self , broker : '_Broker' ,
390
386
size : float ,
391
387
limit_price : Optional [float ] = None ,
@@ -491,11 +487,10 @@ def parent_trade(self):
491
487
return self .__parent_trade
492
488
493
489
@property
494
- def tag (self ) -> Optional [ object ] :
490
+ def tag (self ):
495
491
"""
496
- An attribute which, if set, persists to enable tracking of this order
497
- by an external identifier if it becomes a trade in `Strategy.trades`
498
- and when closed in `Strategy.closed_trades`.
492
+ Arbitrary value (such as a string) which, if set, enables tracking
493
+ of this order and the associated `Trade` (see `Trade.tag`).
499
494
"""
500
495
return self .__tag
501
496
@@ -533,8 +528,7 @@ class Trade:
533
528
When an `Order` is filled, it results in an active `Trade`.
534
529
Find active trades in `Strategy.trades` and closed, settled trades in `Strategy.closed_trades`.
535
530
"""
536
-
537
- def __init__ (self , broker : '_Broker' , size : int , entry_price : float , entry_bar , tag : object ):
531
+ def __init__ (self , broker : '_Broker' , size : int , entry_price : float , entry_bar , tag ):
538
532
self .__broker = broker
539
533
self .__size = size
540
534
self .__entry_price = entry_price
@@ -596,11 +590,15 @@ def exit_bar(self) -> Optional[int]:
596
590
return self .__exit_bar
597
591
598
592
@property
599
- def tag (self ) -> Optional [ object ] :
593
+ def tag (self ):
600
594
"""
601
- A tag attribute optionally set when placing an order with
602
- `Strategy.buy()` or `Strategy.sell()`.
603
- See `Order.tag`.
595
+ A tag value inherited from the `Order` that opened
596
+ this trade.
597
+
598
+ This can be used to track trades and apply conditional
599
+ logic / subgroup analysis.
600
+
601
+ See also `Order.tag`.
604
602
"""
605
603
return self .__tag
606
604
@@ -1023,7 +1021,6 @@ class Backtest:
1023
1021
instance, or `backtesting.backtesting.Backtest.optimize` to
1024
1022
optimize it.
1025
1023
"""
1026
-
1027
1024
def __init__ (self ,
1028
1025
data : pd .DataFrame ,
1029
1026
strategy : Type [Strategy ],
0 commit comments