Hello,
I was wondering how to close a position after precisely 1 hour. I have a similar strategy in the below algorithm, but for days. When I switch (self.Time - self.current).days to (self.Time - self.current).hours, its throws an error. How do if fix that?
Ive attached two algorithms in the thread. Thanks in advance for your help. Thanks :)
Varad Kabade
Hi Christian Olsen,
In the above algorithm, the resolution is Daily, so the OnData will be called once every 24 hrs, so it is not possible to liquidate after an hour. We recommend using a higher resolution (Hourly, Minutes) and using ScheduledEvents to check for signal and manually calculating the order quantity to save the order ticket, which we can use in OnData to check for liquidation. We have implemented an example algorithm for your reference. Refer to the attached backtest.
Best,
Varad Kabade
Christian Olsen
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!