Hello,
I am new to both the platform and Python, so I appologise if my question is silly. I have been trying for days to put a code together that would put an orer at every time period based on current price and cancel this orders 2 hours later if unfilled. Enclosed is my epic failled attempt. While the code indeed run it is not canceling a given order after 2 hours if unfilled, instead it is keeping all of them live (and as a result they all filled up at 2013-10-08 11:00:00 (As you see from Log, Orders 1 to orders 28 get all filled but they should have been cancelled since they were more than 2 hours old!). My guess is that the orders should be stored in a table with their Expiry date and screening them at each iteration (e.g every hours) but I am at a loss as to how to do this.
In oanda for instance it is possible to set the expiry date on every order so it would be a great feature to have (along with some embeded take profit)
I would really appreciate the help and wisdom from this forum
Alexandre Catarino
In this particular case with only one security, we can control when new orders are placed with two variables: self.Portfolio.Invested and self.expiry:
if not self.Portfolio.Invested and self.expiry is None:
self.expiry is user defined and not None when there is an order waiting to be filled.
We need to set it to None when the order is cancelled or filled.
Sdoof
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!