I have a weekly strategy where I want to trade from the first trading hour to the last trading hour of the week and not hold any positions over the weekend.
My point is... I don't want to hard code the regular schedule because it is fluid. The ultimate goal is to trade from the first hour to the last hour and not hold positions over the weekend.
How would you do it if you were using Minute resolution for a given Futures (e.g. ES, NQ, CL, etc.)
I have attached code that uses Scheduled Events. For WeekStart(), I noticed that the first day of the week is Monday or Tuesday. I was expecting Sunday. WeekEnd() looks correct.
Shile Wen
Dear Michael,
QuantConnect defines WeekStart to be Monday and WeekEnd to be Friday. This is to denote the Start and End days of the week for which trading occurs.
Inside the lambda function of Â
Schedule.On(DateRules.WeekEnd(myFuture.Symbol), TimeRules.BeforeMarketClose(myFuture.Symbol), () => {});
addÂ
Liquidate()
which will liquidate all holdings, so that aren't held over the weekend. Thus, your code should look like this:
Schedule.On(DateRules.WeekEnd(myFuture.Symbol), TimeRules.BeforeMarketClose(myFuture.Symbol), () => Â Â Â Â Â Â Â Â Â Â Â Â { Liquidate() Debug($"WeekEnd(myFuture.Symbol), TimeRules.BeforeMarketClose(myFuture.Symbol) fired at: {myFuture.Symbol} {Time}"); Â Â Â Â Â Â Â Â Â Â Â Â });
Best,
Shile Wen
Michael Bloomfield
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!