TimeSpan openTime = TimeSpan.Parse("09:30:00");
//Skip to the next day if we're beyond our open time but outside our play time
if (Time.TimeOfDay >= openTime)
{
var nextDay = Time.Date.AddDays(1) + openTime;
Debug(string.Format("EOD on {0}. Skipping to {1}", (Time.Date.Date + Time.TimeOfDay).ToString("MM/dd/yyyy HH:mm:ss"), nextDay.ToString("MM/dd/yyyy HH:mm:ss")));
SetDateTime(nextDay);
}
else //Skip to start of day if before our open time
{
Debug(string.Format("Start of day on {0}. Skipping to {1}", Time.Date.ToString("MM/dd/yyyy"), (Time.Date + openTime).ToString("MM/dd/yyyy HH:mm:ss")));
SetDateTime(Time.Date + openTime);
}
In regards to the function SetDateTime() I assumed while back testing it would allow me to move forward in time. Essentially while playing /ES there is a lot of downtime between the timeframes I actually play and to make backtesting faster (so it's not sending data for each second outside of my playtime (09:30 - 10:30)) for no reason.
Anyone have an idea about this or a means for me to bypass the time outside my playtime for quick backtesting (I'm already funneling out the data so there is no plays, but it still takes time to go through second by second data across the whole day after)?
Broc R. White
Answer: Use
security.Exchange.SetMarketHours();
Â
Broc R. White
I submitted that answer before I finished my entire message and I couldn't delete/edit it. Although this handles setting the market hours I'm still getting data from seconds outside my hours. HOw am I supposed to do this?
Link Liang
Hi Broc,
SetDateTime() and SetMarketHours() will not skip data, as long as you are subscribing it. So the only way to "skip" the data out of your playtime is to subscribe to it before you play, and unsubscribe (remove) it after you are done.
To make the scheduled event happen every trading day, we subscribe to "SPY" and track all its trading day. Moreover, in order to let the scheduled event happen before 9:30, we enable extendedMarketHours when subscribing to "SPY". Now you only subscribe to "ES" from 9:30 to 10:30 everyday!
Broc R. White
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!