Hi there folks, I need some help with the market hours.
I want to send orders only when the market is open, the way I'm trying to do it is as follow:
// Class fields
bool is MarketOpen
SecurityExchange Market = new SecurityExchange();
public void OnData(TradeBars data)
{
isMarketOpen = Market.DateTimeIsOpen(Time) && Market.DateTimeIsOpen(Time.AddMinutes(10));
if (isMarketOpen)
{
// Loss all your money, but efficiently
}
}
But when I run the backtest, some days, some orders are sent at 16:00 hs.
// Log output
2015-01-02 16:00:00 Converted OrderID: 238 into a MarketOnOpen order.
2015-01-05 16:00:00 Converted OrderID: 338 into a MarketOnOpen order.
2015-01-13 16:00:00 Converted OrderID: 1071 into a MarketOnOpen order.
2015-01-13 16:00:00 Converted OrderID: 1072 into a MarketOnOpen order.
2015-01-14 16:00:00 Converted OrderID: 1190 into a MarketOnOpen order.
2015-01-16 16:00:00 Converted OrderID: 1433 into a MarketOnOpen order.
2015-01-20 16:00:00 Converted OrderID: 1548 into a MarketOnOpen order.
2015-01-30 16:00:00 Converted OrderID: 2419 into a MarketOnOpen order.
Am I missing something?
Thanks in advance, JJ
Jared Broad
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.
JayJayD
Sid Bhadauria
Hello, I have a problem where I'm importing data from Yahoo to use in my algorithm to execute on. The problem is that the exchange for the security is listed as SecurityExchange by default, but I need it to be EquityExchange so that the algorithm will execute at the correct market close. I tried:
Securities["SPY"].Exchange=new EquityExchange();
But it didn't work.
Jared Broad
@Sid - Are you importing Yahoo as custom data or storing it in your hard drive with the toolbox projects?
You probably need to create your own security initializer which sets the default security exchange to equity for your case. You can see an example of this on Github.
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.
Sid Bhadauria
I'm importing it as custom data.
Sid Bhadauria
Also, after I import it, does the algorithm automatically use it for the order function? Like If I use MarketOnCloseOrder will it automatically execute on the close from Yahoo and not the close for the default data? Or do I have to do something else?
Thanks
Sid Bhadauria
Never Mind, I figured it out.
Jared Broad
Please post what you learn back to help other community members! :)
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.
Sid Bhadauria
It was a pretty dumb mistake, I had imported the data and called it "SPY" but had also added the security using the AddSecurity function at the same time and that was also called "SPY" so when I bought or sold "SPY" it was buying the Quantconnect data SPY and not the imported data. But it's working fine now.
Sid Bhadauria
I have one last question:
How do I make it so the algorithm reinvests the profit made? Instead of storing it in a different account?
JayJayD
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!