Skip to content

Commit 4099372

Browse files
committed
Revert name changes
1 parent 3485f0c commit 4099372

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

backtesting/backtesting.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -900,9 +900,7 @@ def next(self):
900900

901901
def _process_orders(self):
902902
data = self._data
903-
open_price = data._current_value("Open")
904-
high_price = data._current_value("High")
905-
low_price = data._current_value("Low")
903+
open, high, low = data._current_value("Open"), data._current_value("High"), data._current_value("Low")
906904
reprocess_orders = False
907905

908906
# Process orders
@@ -916,7 +914,7 @@ def _process_orders(self):
916914
stop_price = order.stop
917915
if stop_price:
918916
is_stop_hit = (
919-
high_price >= stop_price if order.is_long else low_price <= stop_price
917+
high >= stop_price if order.is_long else low <= stop_price
920918
)
921919
if not is_stop_hit:
922920
continue
@@ -929,7 +927,7 @@ def _process_orders(self):
929927
# Check if limit order can be filled.
930928
if order.limit:
931929
is_limit_hit = (
932-
low_price <= order.limit if order.is_long else high_price >= order.limit
930+
low <= order.limit if order.is_long else high >= order.limit
933931
)
934932
# When stop and limit are hit within the same bar, we pessimistically
935933
# assume limit was hit before the stop (i.e. "before it counts")
@@ -942,9 +940,9 @@ def _process_orders(self):
942940

943941
# stop_price, if set, was hit within this bar
944942
price = (
945-
min(stop_price or open_price, order.limit)
943+
min(stop_price or open, order.limit)
946944
if order.is_long
947-
else max(stop_price or open_price, order.limit)
945+
else max(stop_price or open, order.limit)
948946
)
949947
else:
950948
# Market-if-touched / market order
@@ -953,7 +951,7 @@ def _process_orders(self):
953951
price = (
954952
prev_close
955953
if self._trade_on_close and not order.is_contingent
956-
else open_price
954+
else open
957955
)
958956
if stop_price:
959957
price = max(price, stop_price) if order.is_long else min(price, stop_price)
@@ -1067,20 +1065,20 @@ def _process_orders(self):
10671065
and (
10681066
(
10691067
order.is_long
1070-
and order.tp <= high_price
1071-
and (order.sl or -np.inf) < low_price
1068+
and order.tp <= high
1069+
and (order.sl or -np.inf) < low
10721070
)
10731071
or (
10741072
order.is_short
1075-
and order.tp >= low_price
1076-
and (order.sl or np.inf) > high_price
1073+
and order.tp >= low
1074+
and (order.sl or np.inf) > high
10771075
)
10781076
)
10791077
):
10801078
reprocess_orders = True
10811079
elif (
1082-
low_price <= (order.sl or -np.inf) <= high_price
1083-
or low_price <= (order.tp or -np.inf) <= high_price
1080+
low <= (order.sl or -np.inf) <= high
1081+
or low <= (order.tp or -np.inf) <= high
10841082
):
10851083
warnings.warn(
10861084
f"({data.index[-1]}) A contingent SL/TP order would execute in the "

0 commit comments

Comments
 (0)