Back

How to issue a sell order a set amount of time after the security is purchased?

Hi there, I'm pretty new to coding so forgive me if this is a stupid question. I'm trying to issue a sell order a set amount of time after the security has been purchased but I can't seem to figure out how to make this happen. I tried the 'Scheduled Events' route but I don't think its what I'm looking for since my buy orders are set based on specific criteria which might not be periodic. And when I backtested my algo the holding periods weren't as expected, often considerably less than the timespan of the event schedule.

Any help would be greatly appreciated.

Thanks  in advance,

Dan

Update Backtest








When an order is submitted, we can save the time it happened and compare it against every timestep until our time condition is met. However, we better save the time the order was filled, since that is the event that marks the security was purchased.
To accomplish that, we can rely on the OnOrderEvent event handler. When the order is filled, we define the liquidation time, then we check whether Time object is equal of greater than it in the OnData event handler.

1

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.


Thanks for your help! That's exactly what I was looking for but had no clue how to do it. I like how clean your code is as well. As I mentioned above I'm new to coding, but I learned alot from your example!

Cheers,

Dan

0

Update Backtest





0

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.


Loading...

This discussion is closed