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):
806806 continue
807807
808808 # 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 )
810810 if order .is_long else
811- max (open , order .limit , stop_price or - np . inf ))
811+ max (stop_price or open , order .limit ))
812812 else :
813813 # Market-if-touched / market order
814814 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):
479479
480480 self ._Backtest (coroutine ).run ()
481481
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+
482491
483492class TestOptimize (TestCase ):
484493 def test_optimize (self ):
You canβt perform that action at this time.
0 commit comments