The price has not touch the stop price and StopMarketOrder be filled at 00:00:00
20230724 14:41:40.336 TRACE:: Log: OnOrderEvent 2023-07-13 09:45:00: 0: FillPrice:376.7095
20230724 14:41:40.386 TRACE:: Log: OnOrderEvent 2023-07-14 00:00:00: 2: StopPrice:375.46
20230724 14:41:40.386 TRACE:: Log: ------ OnDailyData 2023-07-14 00:00:00 - 2023-07-13 00:00:00 - Open: 376.05 - High: 379.99 - Low: 375.46 - Close: 379.15 = sma5:370.548

Is this a bug? How to avoid it?
Mia Alissi
Based on the information provided in the extracts, it seems like you're experiencing an issue where a StopMarketOrder is being filled at a time when the stop price has not been reached. This could be due to the fill model used in your algorithm.
In QuantConnect, the fill model is responsible for determining how orders are filled. Different models have different rules for filling orders. For example, the Immediate Fill Model fills orders as soon as the stop condition is met, while the Equity Fill Model only fills stop market orders during regular trading hours.
If you're using a fill model that fills orders as soon as the stop condition is met, it's possible that the order is being filled at the start of the next trading day (00:00:00) because that's when the model checks if the stop condition has been met.
To avoid this, you could consider using a different fill model that better suits your needs. For example, the Equity Fill Model only fills stop market orders during regular trading hours, which might prevent the order from being filled at 00:00:00.
Here are the links to the documentation for the different fill models supported by QuantConnect:
Please note that these are just possible explanations and solutions based on the information provided in the extracts. For a more accurate diagnosis and solution, you might want to provide more details about your algorithm or consider reaching out to the QuantConnect community or support team.
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.
Shuai Liu
The default fill model is Equity Fill Model. It should not fills stop market orders at 00:00:00.
Here is my code
Mia Alissi
Based on the provided code and the information from the extracts, it seems like you're using the Equity Fill Model, which only fills stop market orders during regular trading hours. However, you've also set
extendedMarketHours=True
when adding the equity, which means the algorithm is considering data outside of the regular trading hours.The Equity Fill Model won't fill stop market orders with stale data or data with the order timestamp to avoid look-ahead bias. This could be the reason why the stop market order is being filled at 00:00:00, as the model might be considering the extended market hours data as stale.
One possible solution could be to set
extendedMarketHours=False
when adding the equity. This way, the algorithm will only consider data during regular trading hours, which is consistent with the behavior of the Equity Fill Model.Here's how you can modify the code:
Please note that this is just a possible solution based on the information provided in the extracts. For a more accurate solution, you might want to provide more details about your algorithm or consider reaching out to the QuantConnect community or support team.
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.
Shuai Liu
set extendedMarketHours=False can't avoid this issue.
Shuai Liu
I found this bug will happen when I add the same equity with both minute and daily resolution.
at 00:00:00 in OnData() will receive a daily tradebar and at the same time stop market order will be filled.
Mia Alissi
Based on the information provided in the extracts and your code, it seems like you're adding the same equity ("QQQ") twice with different resolutions (Minute and Daily). This could potentially cause some unexpected behavior in your algorithm.
In QuantConnect, when you add an equity, it creates a security object for that equity with the specified resolution. If you add the same equity twice with different resolutions, it might cause some confusion in the algorithm, especially when it comes to filling orders.
In your case, it seems like the stop market order is being filled at 00:00:00 because that's when the daily bar is being generated. The Equity Fill Model, which you're using, only fills orders during regular market hours. However, since you're also using minute data, the model might be checking the stop condition at every minute, including at 00:00:00 when the daily bar is generated.
One possible solution could be to only add the equity once with the resolution that you need for your algorithm. If you need both minute and daily data, you could consider using the
Consolidate
method to consolidate the minute data into daily data. Here's an example:In this example,
OnDailyData
is a method that you would define to handle the consolidated daily data.Please note that this is just a possible solution based on the information provided in the extracts. For a more accurate solution, you might want to provide more details about your algorithm or consider reaching out to the QuantConnect community or support team.
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.
Shuai Liu
In this way, the daily bar you consolidated is not correct and it reflects extended market hours which it should not.
Mia Alissi
I see your point. The consolidated daily bar in the previous example would indeed reflect extended market hours because it's based on minute data that includes extended market hours.
If you want the daily bar to only reflect regular market hours, you might need to implement a custom consolidator that only consolidates data during regular market hours. However, creating a custom consolidator might be complex and beyond the scope of the information provided in the extracts.
Another possible solution could be to use the
Schedule.On
method to schedule a function to run at a specific time (e.g., at market close) to update your indicators or perform other tasks. This way, you can ensure that these tasks are only performed based on data from regular market hours.Here's an example:
In this example,
OnMarketClose
is a method that you would define to handle tasks at market close.Please note that these are just possible solutions based on the information provided in the extracts. For a more accurate solution, you might want to provide more details about your algorithm or consider reaching out to the QuantConnect community or support team.
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.
Shuai Liu
Is there any support team? need some help.
Shuai Liu
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!