I am trying to implement a simple strategy from a book. I figured this would help me learn the QC framework. Here are the rules:
Ignore rule #7. I ran the backtest but there was no buying or selling. Can anyone help point out what I am doing wrong in how I am using the API.
Mia Alissi
From the provided code, it seems like there might be a logical error in the conditions for placing orders.
In the
OnData
method, the first condition checks if the open price is less than the 200-day SMA and the close price is greater than the 5-day SMA. If this condition is true, the function returns immediately, which means no orders are placed.However, based on the rules you provided, it seems like you would want to place an order when this condition is true, not return.
Also, in the condition for placing a MarketOnCloseOrder, you are checking if the close price is greater than the 5-day SMA. But according to the rules, you should sell if the close price is less than the 5-day SMA.
Please revise these conditions according to your strategy rules. If you still encounter issues, please provide more details about the expected vs. actual behavior.
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.
Gabriel Del Real
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!