Skip to content

Commit cf51b35

Browse files
committed
Revert unrelated black changes
1 parent 9215132 commit cf51b35

1 file changed

Lines changed: 11 additions & 37 deletions

File tree

backtesting/backtesting.py

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -889,9 +889,7 @@ def _process_orders(self):
889889
# Check if stop condition was hit
890890
stop_price = order.stop
891891
if stop_price:
892-
is_stop_hit = (
893-
high >= stop_price if order.is_long else low <= stop_price
894-
)
892+
is_stop_hit = ((high >= stop_price) if order.is_long else (low <= stop_price))
895893
if not is_stop_hit:
896894
continue
897895

@@ -902,9 +900,7 @@ def _process_orders(self):
902900
# Determine purchase price.
903901
# Check if limit order can be filled.
904902
if order.limit:
905-
is_limit_hit = (
906-
low <= order.limit if order.is_long else high >= order.limit
907-
)
903+
is_limit_hit = low <= order.limit if order.is_long else high >= order.limit
908904
# When stop and limit are hit within the same bar, we pessimistically
909905
# assume limit was hit before the stop (i.e. "before it counts")
910906
is_limit_hit_before_stop = (is_limit_hit and
@@ -915,20 +911,14 @@ def _process_orders(self):
915911
continue
916912

917913
# stop_price, if set, was hit within this bar
918-
price = (
919-
min(stop_price or open, order.limit)
920-
if order.is_long
921-
else max(stop_price or open, order.limit)
922-
)
914+
price = (min(stop_price or open, order.limit)
915+
if order.is_long else
916+
max(stop_price or open, order.limit))
923917
else:
924918
# Market-if-touched / market order
925919
# Contingent orders always on next open
926920
prev_close = data.Close[-2]
927-
price = (
928-
prev_close
929-
if self._trade_on_close and not order.is_contingent
930-
else open
931-
)
921+
price = prev_close if self._trade_on_close and not order.is_contingent else open
932922
if stop_price:
933923
price = max(price, stop_price) if order.is_long else min(price, stop_price)
934924

@@ -1039,28 +1029,12 @@ def _process_orders(self):
10391029
reprocess_orders = True
10401030
# Order.stop and TP hit within the same bar, but SL wasn't. This case
10411031
# is not ambiguous, because stop and TP go in the same price direction.
1042-
elif (
1043-
stop_price
1044-
and not order.limit
1045-
and order.tp
1046-
and (
1047-
(
1048-
order.is_long
1049-
and order.tp <= high
1050-
and (order.sl or -np.inf) < low
1051-
)
1052-
or (
1053-
order.is_short
1054-
and order.tp >= low
1055-
and (order.sl or np.inf) > high
1056-
)
1057-
)
1058-
):
1032+
elif stop_price and not order.limit and order.tp and (
1033+
(order.is_long and order.tp <= high and (order.sl or -np.inf) < low) or
1034+
(order.is_short and order.tp >= low and (order.sl or np.inf) > high)):
10591035
reprocess_orders = True
1060-
elif (
1061-
low <= (order.sl or -np.inf) <= high
1062-
or low <= (order.tp or -np.inf) <= high
1063-
):
1036+
elif (low <= (order.sl or -np.inf) <= high or
1037+
low <= (order.tp or -np.inf) <= high):
10641038
warnings.warn(
10651039
f"({data.index[-1]}) A contingent SL/TP order would execute in the "
10661040
"same bar its parent stop/limit order was turned into a trade. "

0 commit comments

Comments
 (0)