Back

Open market hours

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
Update Backtest






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.



Almost @Juan! The "SecurityExchange" is the default exchange which is open 24 hours, you might want to use EquityExchange instead which is 9.30-4pm

You can also access the exchange on each asset to get the market hours for each specific asset: Securities["IBM"].Exchange
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.


Thanks Jared!
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.


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.

1

@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

 

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.


I'm importing it as custom data.

0

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

0

Never Mind, I figured it out.

0

Please post what you learn back to help other community members! :)

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.


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.

0

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?

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