-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Open a limit order in certain time frame #502
Comments
time = self.data.index[-1].time()
if start <= time <= end:
self.buy(...)
...
for order in self.orders:
if time >= time(15, 10):
order.cancel() |
Thanks this seems to work. I've got a another question though. If I place 2 limit orders a long and a short and I want to cancel the opposite order when one of them is filled, how can I do it in backtesting? Say my long order is filled, I then want to cancel my short order. |
You can test the order via You can also just loop over |
This also cancels the stoploss on the current trade though. Is there a way to disguinish between the stoploss which is attached to the current trade and the order for a limit short (in case the current trade is a long). I only want to cancel the short order, not the stoploss attached to the current active long trade
|
Orders have |
@kernc How can I make cancel a order when it exceed certain time ? |
Whatever is not provided by the library, you can code yourself. Something like: order = self.buy(...)
self.order_times[order] = self.data.index[-1]
for order in self.orders:
if self.data.index[-1] - self.order_times[order] > pd.Timedelta('3 days'):
order.cancel() If you think |
Hello,
I am trying to open a long limit order when the time is between 2:55pm and 3pm and only in that timeframe.
In raw python it would look like this, where x is my index column in my dataframe.
I am however unsure how I would make it in the backtesting library? How do I open a long limit order when the time is between 2:55pm and 3pm and then close it say 10 minutes later if it hasn't been filled?
The text was updated successfully, but these errors were encountered: