@@ -875,7 +875,7 @@ def _process_orders(self):
875
875
# Check if stop condition was hit
876
876
stop_price = order .stop
877
877
if stop_price :
878
- is_stop_hit = ((high > stop_price ) if order .is_long else (low < stop_price ))
878
+ is_stop_hit = ((high >= stop_price ) if order .is_long else (low <= stop_price ))
879
879
if not is_stop_hit :
880
880
continue
881
881
@@ -886,13 +886,13 @@ def _process_orders(self):
886
886
# Determine purchase price.
887
887
# Check if limit order can be filled.
888
888
if order .limit :
889
- is_limit_hit = low < order .limit if order .is_long else high > order .limit
889
+ is_limit_hit = low <= order .limit if order .is_long else high >= order .limit
890
890
# When stop and limit are hit within the same bar, we pessimistically
891
891
# assume limit was hit before the stop (i.e. "before it counts")
892
892
is_limit_hit_before_stop = (is_limit_hit and
893
- (order .limit < (stop_price or - np .inf )
893
+ (order .limit <= (stop_price or - np .inf )
894
894
if order .is_long
895
- else order .limit > (stop_price or np .inf )))
895
+ else order .limit >= (stop_price or np .inf )))
896
896
if not is_limit_hit or is_limit_hit_before_stop :
897
897
continue
898
898
@@ -905,9 +905,8 @@ def _process_orders(self):
905
905
# Contingent orders always on next open
906
906
prev_close = data .Close [- 2 ]
907
907
price = prev_close if self ._trade_on_close and not order .is_contingent else open
908
- price = (max (price , stop_price or - np .inf )
909
- if order .is_long else
910
- min (price , stop_price or np .inf ))
908
+ if stop_price :
909
+ price = max (price , stop_price ) if order .is_long else min (price , stop_price )
911
910
912
911
# Determine entry/exit bar index
913
912
is_market_order = not order .limit and not stop_price
0 commit comments