Hi,
I am trying to test an algo strategy on QuantConnect, and when I run the following code, I notice that the stop-limit orders are getting sent, but they are never being filled. For example, the program correctly sent a buy order for SPY on 3/9/23 at the correct price, which is the high of the previous bar (3/8/23). On the SPY chart, the high of 3/8/23 was breached on 3/9/23 and thus, the buy order should have been executed. But when I look at the strategy equity graph, I see that none of the orders are getting filled and the equity remains the same throughout the entire backtest. Could someone please explain what is going wrong with my backtest?
Ps: I included the below line because I only want the order to be valid for one day. For example, if the program identifies the signal on 3/8/23, the order should be placed before the market opens on 3/9/23 and should be canceled if it is not filled after the market closes on 3/9/23.
self.DefaultOrderProperties.TimeInForce = TimeInForce.Day
Louis Szeto
Hi Rishab
A stop order should be linked to an order/position for a stop loss, but your condition is `if not self.Portfolio.Invested`. A standalone “naked" stop order will not be valid. Use a pair of order if you wish to enter a position while placing a stop loss
Best
Louis
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.
Rishab Maheshwari
Thanks for the answer. Would you mind sharing your thoughts on this post: Orders not getting filled. by Rishab Maheshwari - QuantConnect.com
Rishab Maheshwari
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!