The algorithm keeps submitting multiple orders On Market Open. Is this a bug?
2019-01-18 16:00:00 : Time: 1/18/2019 9:00:00 PM OrderID: 25 Symbol: SPXL Status: Submitted
2019-01-18 16:00:00 : Time: 1/18/2019 9:00:00 PM OrderID: 26 Symbol: SPXS Status: Submitted
2019-01-18 16:00:00 : Time: 1/18/2019 9:00:00 PM OrderID: 27 Symbol: TMF Status: Submitted
2019-01-18 16:00:00 : Time: 1/18/2019 9:00:00 PM OrderID: 28 Symbol: SPXL Status: Submitted
2019-01-18 16:00:00 : Time: 1/18/2019 9:00:00 PM OrderID: 29 Symbol: SPXS Status: Submitted
2019-01-18 16:00:00 : Time: 1/18/2019 9:00:00 PM OrderID: 30 Symbol: TMF Status: Submitted
2019-01-18 16:00:00 : Time: 1/18/2019 9:00:00 PM OrderID: 31 Symbol: SPXL Status: Submitted
2019-01-18 16:00:00 : Time: 1/18/2019 9:00:00 PM OrderID: 32 Symbol: SPXS Status: Submitted
2019-01-18 16:00:00 : Time: 1/18/2019 9:00:00 PM OrderID: 33 Symbol: TMF Status: Submitted
2019-01-22 09:31:00 : Time: 1/22/2019 2:31:00 PM OrderID: 25 Symbol: SPXL Status: Filled Quantity: 12 FillPrice: 38.64 USD OrderFee: 1 USD
2019-01-22 09:31:00 : Time: 1/22/2019 2:31:00 PM OrderID: 26 Symbol: SPXS Status: Filled Quantity: -19 FillPrice: 25.65384 USD OrderFee: 1 USD
2019-01-22 09:31:00 : Time: 1/22/2019 2:31:00 PM OrderID: 27 Symbol: TMF Status: Filled Quantity: -54 FillPrice: 18.63476 USD OrderFee: 1 USD
2019-01-22 09:31:00 : Time: 1/22/2019 2:31:00 PM OrderID: 28 Symbol: SPXL Status: Filled Quantity: 12 FillPrice: 38.64 USD OrderFee: 1 USD
2019-01-22 09:31:00 : Time: 1/22/2019 2:31:00 PM OrderID: 29 Symbol: SPXS Status: Filled Quantity: -19 FillPrice: 25.65384 USD OrderFee: 1 USD
2019-01-22 09:31:00 : Time: 1/22/2019 2:31:00 PM OrderID: 30 Symbol: TMF Status: Filled Quantity: -54 FillPrice: 18.63476 USD OrderFee: 1 USD
2019-01-22 09:31:00 : Time: 1/22/2019 2:31:00 PM OrderID: 31 Symbol: SPXL Status: Filled Quantity: 12 FillPrice: 38.64 USD OrderFee: 1 USD
2019-01-22 09:31:00 : Time: 1/22/2019 2:31:00 PM OrderID: 32 Symbol: SPXS Status: Filled Quantity: -19 FillPrice: 25.65384 USD OrderFee: 1 USD
2019-01-22 09:31:00 : Time: 1/22/2019 2:31:00 PM OrderID: 33 Symbol: TMF Status: Filled Quantity: -54 FillPrice: 18.63476 USD OrderFee: 1 USD
Xin Wei
Dear Apollos,
The issue stems from how the consolidator is being used right now. The algorithm is using the same handler (twoforty()) to handle three (in the loop of Initialize function) different consolidated events. Therefore, it is triggered three times at the end of each hour. That's why you see three duplicated orders are submitted.
However, your code doesn't use the actual consolidated data that gets passed into it, and so you might consider not using a consolidator to begin with. If you are just interested in 60min (timedelta(minutes=60)) consolidated events, then you can use hourly data (Resolution.Hour) to skip the necessity of a consolidator. Please see my attached backtest for this solution.
If you want to stick with minute data, you may want to check out Scheduled Events (https://www.quantconnect.com/docs/algorithm-reference/scheduled-events) which allow you to trigger code to run at specific times of the day. For instance, you can use self.TimeRules.Every(timedelta(minutes=45)) for scheduled events at every 45 minutes.
Please let me know if you have further questions.
Apollos Hill
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!