-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Stop-loss order executed at a higher price than the market price #521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Not sure if there is active maintenance of the library, but this class _Broker:
...
def _process_orders(self):
data = self._data
open, high, low = data.Open[-1], data.High[-1], data.Low[-1]
prev_close = data.Close[-2]
...
else:
# Market-if-touched / market order
price = prev_close if self._trade_on_close else open
price = (max(price, stop_price or -np.inf)
if order.is_long else
min(price, stop_price or np.inf))
########################### [fix] use Open price ###############################
if order.parent_trade and self._trade_on_close and stop_price:
if order.parent_trade.is_long and order.is_short:
if open < stop_price:
price = open
if order.parent_trade.is_short and order.is_long:
if open > stop_price:
price = open |
Expected Behavior
Consider a stop-loss order placed at a stop-loss price
p
. When the opening price is way below the stop-loss pricep
, I would expect the stop-loss order to be executed at the opening price.Actual Behavior
The stop-loss order is executed at the stop-loss price
p
, which is way higher than the opening price.Steps to Reproduce
Additional info
trade_on_close
option isFalse
, the code works as expected.The text was updated successfully, but these errors were encountered: