File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -459,8 +459,7 @@ def cancel(self):
459
459
elif self is trade ._tp_order :
460
460
trade ._replace (tp_order = None )
461
461
else :
462
- # XXX: https://github.com/kernc/backtesting.py/issues/251#issuecomment-835634984 ???
463
- assert False
462
+ pass # Order placed by Trade.close()
464
463
465
464
# Fields getters
466
465
Original file line number Diff line number Diff line change @@ -1040,6 +1040,19 @@ def test_stats_annualized(self):
1040
1040
self .assertFalse (np .isnan (stats ['Return (Ann.) [%]' ]))
1041
1041
self .assertEqual (round (stats ['Return (Ann.) [%]' ]), - 3 )
1042
1042
1043
+ def test_cancel_orders (self ):
1044
+ class S (Strategy ):
1045
+ def init (self ): pass
1046
+
1047
+ def next (self ):
1048
+ self .buy (sl = 1 , tp = 1e3 )
1049
+ if self .position :
1050
+ self .position .close ()
1051
+ for order in self .orders :
1052
+ order .cancel ()
1053
+
1054
+ Backtest (SHORT_DATA , S ).run ()
1055
+
1043
1056
1044
1057
if __name__ == '__main__' :
1045
1058
warnings .filterwarnings ('error' )
You can’t perform that action at this time.
0 commit comments