File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -806,9 +806,9 @@ def _process_orders(self):
806
806
continue
807
807
808
808
# stop_price, if set, was hit within this bar
809
- price = (min (open , order .limit , stop_price or np . inf )
809
+ price = (min (stop_price or open , order .limit )
810
810
if order .is_long else
811
- max (open , order .limit , stop_price or - np . inf ))
811
+ max (stop_price or open , order .limit ))
812
812
else :
813
813
# Market-if-touched / market order
814
814
price = prev_close if self ._trade_on_close else open
Original file line number Diff line number Diff line change @@ -479,6 +479,15 @@ def coroutine(self):
479
479
480
480
self ._Backtest (coroutine ).run ()
481
481
482
+ def test_stop_limit_order_price_is_stop_price (self ):
483
+ def coroutine (self ):
484
+ self .buy (stop = 112 , limit = 113 , size = 1 )
485
+ self .sell (stop = 107 , limit = 105 , size = 1 )
486
+ yield
487
+
488
+ stats = self ._Backtest (coroutine ).run ()
489
+ self .assertListEqual (stats ._trades .filter (like = 'Price' ).stack ().tolist (), [112 , 107 ])
490
+
482
491
483
492
class TestOptimize (TestCase ):
484
493
def test_optimize (self ):
You can’t perform that action at this time.
0 commit comments